github.1485827954.workers.dev/nektos/act@v0.2.63/.github/actions/run-tests/action.yml (about)

     1  name: 'run-tests'
     2  description: 'Runs go test and upload a step summary'
     3  inputs:
     4    filter:
     5      description: 'The go test pattern for the tests to run'
     6      required: false
     7      default: ''
     8    upload-logs-name:
     9      description: 'Choose the name of the log artifact'
    10      required: false
    11      default: logs-${{ github.job }}-${{ strategy.job-index }}
    12    upload-logs:
    13      description: 'If true uploads logs of each tests as an artifact'
    14      required: false
    15      default: 'true'
    16  runs:
    17    using: composite
    18    steps:
    19      - uses: actions/github-script@v6
    20        with:
    21          github-token: none # No reason to grant access to the GITHUB_TOKEN
    22          script: |
    23            let myOutput = '';
    24            var fs = require('fs');
    25            var uploadLogs = process.env.UPLOAD_LOGS === 'true';
    26            if(uploadLogs) {
    27              await io.mkdirP('logs');
    28            }
    29            var filename = null;
    30            const options = {};
    31            options.ignoreReturnCode = true;
    32            options.env = Object.assign({}, process.env);
    33            delete options.env.ACTIONS_RUNTIME_URL;
    34            delete options.env.ACTIONS_RUNTIME_TOKEN;
    35            delete options.env.ACTIONS_CACHE_URL;
    36            options.listeners = {
    37              stdout: (data) => {
    38                for(line of data.toString().split('\n')) {
    39                  if(/^\s*(===\s[^\s]+\s|---\s[^\s]+:\s)/.test(line)) {
    40                    if(uploadLogs) {
    41                      var runprefix = "=== RUN   ";
    42                      if(line.startsWith(runprefix)) {
    43                        filename = "logs/" + line.substring(runprefix.length).replace(/[^A-Za-z0-9]/g, '-') + ".txt";
    44                        fs.writeFileSync(filename, line + "\n");
    45                      } else if(filename) {
    46                        fs.appendFileSync(filename, line + "\n");
    47                        filename = null;
    48                      }
    49                    }
    50                    myOutput += line + "\n";
    51                  } else if(filename) {
    52                    fs.appendFileSync(filename, line + "\n");
    53                  }
    54                }
    55              }
    56            };
    57            var args = ['test', '-v', '-cover', '-coverpkg=./...', '-coverprofile=coverage.txt', '-covermode=atomic', '-timeout', '20m'];
    58            var filter = process.env.FILTER;
    59            if(filter) {
    60              args.push('-run');
    61              args.push(filter);
    62            }
    63            args.push('./...');
    64            var exitcode = await exec.exec('go', args, options);
    65            if(process.env.GITHUB_STEP_SUMMARY) {
    66              core.summary.addCodeBlock(myOutput);
    67              await core.summary.write();
    68            }
    69            process.exit(exitcode);
    70        env:
    71          FILTER: ${{ inputs.filter }}
    72          UPLOAD_LOGS: ${{ inputs.upload-logs }}
    73      - uses: actions/upload-artifact@v3
    74        if: always() && inputs.upload-logs == 'true' && !env.ACT
    75        with:
    76          name: ${{ inputs.upload-logs-name }}
    77          path: logs