ci: added sample packages to exercice CI pipelines #10
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: go test | ||
|
Check failure on line 1 in .github/workflows/go-test.yml
|
||
| on: | ||
| workflow_call: | ||
| jobs: | ||
| lint: | ||
| name: Lint | ||
| # description: | | ||
| # Lint uses golangci-lint github action and lints only changes from master. | ||
| # | ||
| # It will run on the latest go version. | ||
| # | ||
| # We rely on golangci-lint to automatically disable linters that do not apply to the minimum required go version | ||
| # currently defined in go.mod. | ||
| # | ||
| # At this moment, .golangci.yml configuration files are not shared: each repository must have its configuration. | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: stable | ||
| check-latest: true | ||
| cache: true | ||
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v8 | ||
| with: | ||
| version: latest | ||
| only-new-issues: true | ||
| skip-cache: true | ||
| - name: Linting complete | ||
| run: | | ||
| echo "### Your changes to the go code look good. 👍" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "> We use [golangci-lint action](https://github.com/golangci/golangci-lint-action)" >> $GITHUB_STEP_SUMMARY | ||
| echo "> to lint any change to go code from master" >> $GITHUB_STEP_SUMMARY | ||
| unit_tests: | ||
| name: Unit tests | ||
| # description: | | ||
| # Run go unit tests run 6x: linux, mac & windows on the 2 latest go versions. | ||
| # | ||
| # Run tests with the -race flag. | ||
| # | ||
| # Captures test coverage and uploads it to codecov.com. | ||
| runs-on: ${{ matrix.os }} | ||
| outputs: | ||
| test_result: ${{ toJSON(steps.gotest.outputs) }} | ||
| strategy: | ||
| matrix: | ||
| os: [ ubuntu-latest, macos-latest, windows-latest ] | ||
| go_version: ['oldstable', 'stable' ] | ||
| steps: | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '${{ matrix.go_version }}' | ||
| check-latest: true | ||
| cache: true | ||
| - uses: actions/checkout@v5 | ||
| - name: Run unit tests | ||
| id: gotest | ||
| shell: bash | ||
| run: | | ||
| go test -v \ | ||
| -race \ | ||
| -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" \ | ||
| -covermode=atomic -coverpkg=$(go list)/... \ | ||
| ./... | ||
| - name: Report failed test | ||
| if: failure() | ||
| shell: bash | ||
| run: | | ||
| echo "test_result_${{ matrix.go_version }}_${{ matrix.os }}=\"| ${{ matrix.go_version }} | ${{ matrix.os }} | 🚫 ${{ steps.gotest.outcome }} |\"" >> $GITHUB_OUTPUT | ||
| - name: Report successful test | ||
| shell: bash | ||
| run: | | ||
| echo "test_result_${{ matrix.go_version }}_${{ matrix.os }}=\"| ${{ matrix.go_version }} | ${{ matrix.os }} | ✅ ${{ steps.gotest.outcome }} |\"" >> $GITHUB_OUTPUT | ||
| - name: Upload coverage to codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out' | ||
| flags: '${{ matrix.go_version }}-${{ matrix.os }}' | ||
| fail_ci_if_error: false | ||
| verbose: true | ||
| all_tests: | ||
| name: All tests | ||
| # description: | | ||
| # This job regroups all tests launched as a matrix, so we may define a branch protection rule | ||
| # just on that job rather than each matrix job independently. | ||
| needs: [ unit_tests ] # requires all unit_tests jobs to be successful. | ||
| env: | ||
| test_result: '${{ needs.unit_tests.outputs.test_result }}' # <- this is a JSON map | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Tests complete | ||
| run: | | ||
| #ALL_RESULTS=${{ | ||
| echo "All tests completed. 👍" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "| go version | OS | Result |" >> $GITHUB_STEP_SUMMARY | ||
| echo "|------------|----|--------|" >> $GITHUB_STEP_SUMMARY | ||
| echo "${{ env.test_result }}" >> $GITHUB_STEP_SUMMARY | ||
| some_failed_tests: | ||
| name: Some tests have failed | ||
| needs: [ unit_tests ] # requires all unit_tests jobs to be completed, but not necessarily successfully. | ||
| if: ${{ needs.unit_tests.result == 'failure' }} | ||
| env: | ||
| test_result: '${{ needs.unit_tests.outputs.test_result }}' # <- this is a JSON map | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Tests complete | ||
| run: | | ||
| echo "Some tests have failed. 🚫" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "| go version | OS | Result |" >> $GITHUB_STEP_SUMMARY | ||
| echo "|------------|----|--------|" >> $GITHUB_STEP_SUMMARY | ||
| echo "${{ env.test_result }}" >> $GITHUB_STEP_SUMMARY | ||