Initial code + basic workflows #4
Workflow file for this run
This file contains 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: Unit Tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
pull-requests: write | |
concurrency: | |
group: ci-${{ github.ref }}-tests | |
cancel-in-progress: true | |
jobs: | |
tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: 1.21 | |
- uses: technote-space/[email protected] | |
with: | |
PATTERNS: | | |
**/**.go | |
go.mod | |
go.sum | |
- name: Get data from Go build cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/go/pkg/mod | |
~/.cache/golangci-lint | |
~/.cache/go-build | |
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | |
- name: Run unit tests | |
run: go test -mod=readonly -race -timeout 5m ./... | |
unit-test-check: | |
name: Unit Test Check | |
runs-on: ubuntu-latest | |
needs: tests | |
if: always() | |
steps: | |
- name: Get workflow conclusion | |
id: workflow_conclusion | |
uses: nick-fields/retry@v2 | |
with: | |
max_attempts: 2 | |
retry_on: error | |
timeout_seconds: 30 | |
command: | | |
jobs=$(curl https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs) | |
job_statuses=$(echo "$jobs" | jq -r '.jobs[] | .conclusion') | |
for status in $job_statuses | |
do | |
echo "Status: $status" | |
if [[ "$status" == "failure" ]]; then | |
echo "Some or all tests have failed!" | |
exit 1 | |
fi | |
done | |
echo "All tests have passed!" |