|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md |
| 2 | +name: Test Go |
| 3 | + |
| 4 | +env: |
| 5 | + # See: https://github.com/actions/setup-go/tree/v2#readme |
| 6 | + GO_VERSION: "1.16" |
| 7 | + |
| 8 | +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows |
| 9 | +on: |
| 10 | + create: |
| 11 | + push: |
| 12 | + paths: |
| 13 | + - ".github/workflows/test-go-task.ya?ml" |
| 14 | + - "codecov.ya?ml" |
| 15 | + - "**/go.mod" |
| 16 | + - "**/go.sum" |
| 17 | + - "Taskfile.ya?ml" |
| 18 | + - "**.go" |
| 19 | + - "**/testdata/**" |
| 20 | + pull_request: |
| 21 | + paths: |
| 22 | + - ".github/workflows/test-go-task.ya?ml" |
| 23 | + - "codecov.ya?ml" |
| 24 | + - "**/go.mod" |
| 25 | + - "**/go.sum" |
| 26 | + - "Taskfile.ya?ml" |
| 27 | + - "**.go" |
| 28 | + - "**/testdata/**" |
| 29 | + workflow_dispatch: |
| 30 | + repository_dispatch: |
| 31 | + |
| 32 | +jobs: |
| 33 | + run-determination: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + result: ${{ steps.determination.outputs.result }} |
| 37 | + steps: |
| 38 | + - name: Determine if the rest of the workflow should run |
| 39 | + id: determination |
| 40 | + run: | |
| 41 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 42 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 43 | + if [[ \ |
| 44 | + "${{ github.event_name }}" != "create" || \ |
| 45 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \ |
| 46 | + ]]; then |
| 47 | + # Run the other jobs. |
| 48 | + RESULT="true" |
| 49 | + else |
| 50 | + # There is no need to run the other jobs. |
| 51 | + RESULT="false" |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "::set-output name=result::$RESULT" |
| 55 | +
|
| 56 | + test: |
| 57 | + name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }}) |
| 58 | + needs: run-determination |
| 59 | + if: needs.run-determination.outputs.result == 'true' |
| 60 | + |
| 61 | + strategy: |
| 62 | + fail-fast: false |
| 63 | + |
| 64 | + matrix: |
| 65 | + operating-system: |
| 66 | + - ubuntu-latest |
| 67 | + - windows-latest |
| 68 | + - macos-latest |
| 69 | + module: |
| 70 | + # TODO: add paths of all Go modules here |
| 71 | + - path: ./ |
| 72 | + codecov-flags: unit |
| 73 | + |
| 74 | + runs-on: ${{ matrix.operating-system }} |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Checkout repository |
| 78 | + uses: actions/checkout@v2 |
| 79 | + |
| 80 | + - name: Install Go |
| 81 | + uses: actions/setup-go@v2 |
| 82 | + with: |
| 83 | + go-version: ${{ env.GO_VERSION }} |
| 84 | + |
| 85 | + - name: Install Task |
| 86 | + uses: arduino/setup-task@v1 |
| 87 | + with: |
| 88 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + version: 3.x |
| 90 | + |
| 91 | + - name: Run tests |
| 92 | + env: |
| 93 | + GO_MODULE_PATH: ${{ matrix.module.path }} |
| 94 | + run: task go:test |
| 95 | + |
| 96 | + # - name: Send unit tests coverage to Codecov |
| 97 | + # if: runner.os == 'Linux' |
| 98 | + # uses: codecov/codecov-action@v2 |
| 99 | + # with: |
| 100 | + # file: ${{ matrix.module.path }}coverage_unit.txt |
| 101 | + # flags: ${{ matrix.module.codecov-flags }} |
| 102 | + # fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cloud-cli' }} |
0 commit comments