From babac68ad9c9a88f5de3e0d23abc4d7d0575b138 Mon Sep 17 00:00:00 2001 From: alsi-lawr Date: Sat, 31 Aug 2024 22:24:22 +0100 Subject: [PATCH] Try with node --- .gitignore | 1 + Dockerfile | 18 ---------- action.yml | 13 ++----- index.js | 39 ++++++++++++++++++++ package-lock.json | 91 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 19 ++++++++++ 6 files changed, 153 insertions(+), 28 deletions(-) delete mode 100644 Dockerfile create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore index dcb553f..5ddfe64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/bin/** **/obj/** **/*.cobertura* +node_modules diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 5b838b7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# Use an ARG to allow the .NET version to be specified at build time -ARG DOTNET_VERSION=6.0 - -# Use the specified .NET SDK version as the base image -FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} - -# Set the working directory inside the container -WORKDIR /workspace - -# Copy the entire workspace into the container's workspace directory -COPY . . - -# Make sure the script is executable -RUN chmod +x /workspace/src/test.sh - -# Set the entrypoint to the script -ENTRYPOINT ["/bin/bash", "/workspace/src/test.sh"] - diff --git a/action.yml b/action.yml index fec7a3e..44091b6 100644 --- a/action.yml +++ b/action.yml @@ -35,15 +35,8 @@ outputs: description: 'Path to the generated code coverage report directory' runs: - using: 'docker' - image: 'Dockerfile' - build-args: | - DOTNET_VERSION=${{ inputs.dotnet-version }} + using: 'node20' + main: 'index.js' env: - UNIT_TEST_PROJECT: ${{ inputs.project }} - UNIT_TEST_EXCLUDE_FILES: ${{ inputs.exclude-files }} - UNIT_TEST_EXCLUDE_MODULES: ${{ inputs.exclude-modules }} - UNIT_TEST_COVERAGE_THRESHOLD: ${{ inputs.threshold }} - args: - - ${{ inputs.project }} + GITHUB_WORKSPACE: ${{ github.workspace }} diff --git a/index.js b/index.js new file mode 100644 index 0000000..4643cf7 --- /dev/null +++ b/index.js @@ -0,0 +1,39 @@ +const core = require("@actions/core"); +const exec = require("@actions/exec"); + +async function run() { + try { + // Get inputs + const project = core.getInput("project"); + const excludeFiles = core.getInput("exclude-files"); + const excludeModules = core.getInput("exclude-modules"); + const threshold = core.getInput("threshold"); + const dotnetVersion = core.getInput("dotnet-version"); + const workspace = process.env.GITHUB_WORKSPACE; + + // Define Docker image name + const imageName = `mcr.microsoft.com/dotnet/sdk:${dotnetVersion}`; + + // Run the Docker container with the environment variables passed in + // prettier-ignore + await exec.exec('docker', [ + 'run', + '--rm', + '-v ', `${workspace}:/workspace`, + '-e', `UNIT_TEST_PROJECT=${project}`, + '-e', `UNIT_TEST_EXCLUDE_FILES=${excludeFiles}`, + '-e', `UNIT_TEST_EXCLUDE_MODULES=${excludeModules}`, + '-e', `UNIT_TEST_COVERAGE_THRESHOLD=${threshold}`, + '-w', '/workspace', + imageName, + 'bash -c', './src/test.sh', project + ]); + + // Optionally, set an output for the action (e.g., path to coverage report) + core.setOutput("coverage-report-path", `/workspace/${project}/report`); + } catch (error) { + core.setFailed(`Action failed with error: ${error.message}`); + } +} + +run(); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fa647c2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,91 @@ +{ + "name": "dotnet-test-coverlet", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "dotnet-test-coverlet", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.10.1", + "@actions/exec": "^1.1.1" + } + }, + "node_modules/@actions/core": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", + "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", + "license": "MIT", + "dependencies": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "node_modules/@actions/exec": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", + "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", + "license": "MIT", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", + "integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, + "node_modules/@actions/io": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", + "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", + "license": "MIT" + }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/undici": { + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "license": "MIT", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b984122 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "dotnet-test-coverlet", + "version": "1.0.0", + "description": "This reusable action runs unit tests on a .NET project and generates a code coverage report. It supports configuration for custom test project paths, exclusion of files and modules from coverage, and setting a coverage threshold.", + "main": "index.js", + "directories": { + "doc": "docs", + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.10.1", + "@actions/exec": "^1.1.1" + } +}