Skip to content

Commit

Permalink
Try with node
Browse files Browse the repository at this point in the history
  • Loading branch information
alsi-lawr committed Aug 31, 2024
1 parent 0cadbab commit babac68
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/bin/**
**/obj/**
**/*.cobertura*
node_modules
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

13 changes: 3 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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();
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit babac68

Please sign in to comment.