-
Notifications
You must be signed in to change notification settings - Fork 2
121 lines (101 loc) · 4.04 KB
/
Copy pathgo.yml
File metadata and controls
121 lines (101 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# This workflow builds and tests a golang project for every commit in a PR
#
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
# This job identifies all commits that need to be tested
# For push events: only tests the latest commit
# For PR events: tests every commit in the PR
commit_list:
name: Get Commits to Test
runs-on: ubuntu-latest
steps:
# Checkout with full history to enable commit listing
- uses: actions/checkout@v6
with:
fetch-depth: 0
# For push events: only test the latest commit (GITHUB_SHA)
- name: Get commit list (push)
id: get_commit_list_push
if: ${{ github.event_name == 'push' }}
run: |
# Create a single output variable with the latest commit
echo "id0=$GITHUB_SHA" > $GITHUB_OUTPUT
# Add commit URL to the workflow summary for visibility
echo "List of tested commits:" > $GITHUB_STEP_SUMMARY
echo "- https://github.com/${{ github.repository }}/commit/$GITHUB_SHA" >> $GITHUB_STEP_SUMMARY
# For PR events: get all commits in the PR
- name: Get commit list (PR)
id: get_commit_list_pr
if: ${{ github.event_name == 'pull_request' }}
run: |
# Get all commits between base branch and PR head, in oldest to newest order
git rev-list --reverse refs/remotes/origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} |
awk '{ print "id" NR "=" $1 }' > $GITHUB_OUTPUT
# If the merge commit differs from the PR head, also test the merge commit
git diff --quiet ${{ github.event.pull_request.head.sha }} ${{ github.sha }} ||
echo "id0=$GITHUB_SHA" >> $GITHUB_OUTPUT
# Create a summary with links to all commits
echo "List of tested commits:" > $GITHUB_STEP_SUMMARY
sed -n 's,^id[0-9]\+=\(.*\),- https://github.com/${{ github.repository }}/commit/\1,p' -- $GITHUB_OUTPUT >> $GITHUB_STEP_SUMMARY
# Make the list of commits available to downstream jobs
outputs:
commits: ${{ toJSON(steps.*.outputs.*) }}
# Lint job - runs once per workflow execution, not per commit
golangci-lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- run: go version
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.6.1
# Build and test each commit for both architectures
# Uses a matrix strategy to create separate job runs for each combination of commit and architecture
per_commit_build_test:
name: Build & Test ${{ matrix.arch }}
runs-on: ubuntu-latest
needs: commit_list
strategy:
# Don't stop all tests if one commit/arch fails
fail-fast: false
matrix:
# Create matrix entries for each combination of commit and architecture
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
arch: [amd64, arm64]
steps:
# Checkout the specific commit to test
- uses: actions/checkout@v6
with:
ref: ${{ matrix.commit }}
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- run: go version
- name: Build ${{ matrix.commit }} for ${{ matrix.arch }}
run: GOARCH=${{ matrix.arch }} go build -v ./...
- name: Unit test ${{ matrix.commit }} for ${{ matrix.arch }}
run: go test -v ./...
# License check runs once per workflow execution
check-license-lines:
name: Check License Lines
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: kt3k/license_checker@v1.0.6