Skip to content

ci: added sample packages to exercice CI pipelines #14

ci: added sample packages to exercice CI pipelines

ci: added sample packages to exercice CI pipelines #14

Workflow file for this run

name: go test

Check failure on line 1 in .github/workflows/go-test.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/go-test.yml

Invalid workflow file

(Line: 91, Col: 12): Unrecognized function: 'success'. Located at position 1 within expression: success()
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 "> ℹ️ INFO: 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:
# NOTE(fredbi): as of Aug. 2025, there is no way to have github actions declare outputs dynamically
all: "${{ toJSON(steps.goreport.outputs) }}"
test_result_oldstable_ubuntu_latest: "${{ steps.goreport.outputs.test_result_oldstable_ubuntu_latest }}"
test_result_oldstable_macos: "${{ steps.goreport.outputs.test_result_oldstable_macos }}"
test_result_oldstable_windows: "${{ steps.goreport.outputs.test_result_oldstable_windows }}"
test_result_stable_ubuntu_latest: "${{ steps.goreport.outputs.test_result_stable_ubuntu_latest }}"
test_result_stable_macos: "${{ steps.goreport.outputs.test_result_stable_macos }}"
test_result_stable_windows: "${{ steps.goreport.outputs.test_result_stable_windows }}"
strategy:
matrix:
#os: [ ubuntu-latest, macos-latest, windows-latest ]
os: [ ubuntu-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
# description: |
# runs unit tests with test coverage assuming that this repository contains only one module,
# with a go.mod located at the root.
id: gotest
shell: bash
run: |
go test -v \
-race \
-coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" \
-covermode=atomic \
-coverpkg=$(go list ./... |paste -sd ",") \
./...
- name: Report test
if: success() || failure()
id: goreport
shell: bash
run: |
icon="✅"
if [[ "${{ success() }}" != "true" ]] ; then
icon="🚫"
fi
echo "test_result_${{ matrix.go_version }}_$(echo "${{ matrix.os }}"|tr '-' '_')='| ${{ matrix.go_version }} | ${{ matrix.os }} | ${icon} ${{ 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: false
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: '${{ toJSON(needs.unit_tests.outputs) }}' # <- this is a JSON map
x_result: '${{ join(needs.unit_tests.outputs.*) }}'
x_all: '${{ needs.unit_tests.outputs.all }}'
runs-on: ubuntu-latest
steps:
- name: Tests complete
run: |
echo "DEBUG: ${{ env.test_result }}"
echo "DEBUG: ${{ env.x_result }}"
echo "DEBUG: ${{ env.x_all }}"
echo "DEBUG: ${{ toJSON(needs.unit_tests.outputs) }}"
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
for line in "${{ env.x_result }}";do echo "${line}" ; done >> $GITHUB_STEP_SUMMARY
some_failed_tests:
name: Some tests have failed
# description: |
# This job is only here to report a summary of failed tests in the github actions UI
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 failed
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