Skip to content

Commit c482816

Browse files
authored
implement the november batch of unified github workflows improvements (ipdxco#100)
* chore(ipdxco#69): do not install go twice when not needed * feat(ipdxco#91): simplify disabling CGO for the Go tests * fix(ipdxco#89): do not release -dev/-rc versions as latest * chore(ipdxco#86): mark go updating PRs as breaking changes * chore(ipdxco#70): remove usage of search api from releaser workflow * fix: the second go setup conditional in go-test * fix: the second go setup conditional in go-check * fix: the second go setup conditional in go-test * fix: the cgo enabled config key retrieval * fix: finding merge pr in releaser * fix: finding merge pr in releaser
1 parent 8a83207 commit c482816

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

.github/workflows/go-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
submodules: recursive
2525
- name: Check out the latest stable version of Go
26+
id: stable
2627
uses: actions/setup-go@v5
2728
with:
2829
go-version: stable
@@ -35,6 +36,7 @@ jobs:
3536
uses: ipdxco/unified-github-workflows/.github/actions/read-go-mod@main
3637
- name: Set up the Go version read from the go.mod file
3738
id: go
39+
if: (inputs.go-version || fromJSON(steps.go-mod.outputs.json).Go) != steps.stable.outputs.go-version || inputs.go-cache != 'false'
3840
uses: actions/setup-go@v5
3941
with:
4042
go-version: ${{ inputs.go-version || fromJSON(steps.go-mod.outputs.json).Go }}

.github/workflows/go-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
with:
4545
submodules: recursive
4646
- name: Check out the latest stable version of Go
47+
id: stable
4748
uses: actions/setup-go@v5
4849
with:
4950
go-version: stable
@@ -94,6 +95,7 @@ jobs:
9495
echo "GORACEFLAGS=-v $GORACEFLAGS" >> $GITHUB_ENV
9596
- name: Set up the Go version read from the go.mod file
9697
uses: actions/setup-go@v5
98+
if: steps.go.outputs.version != steps.stable.outputs.go-version || inputs.go-cache != 'false'
9799
with:
98100
go-version: ${{ steps.go.outputs.version }}
99101
cache: ${{ inputs.go-cache }}
@@ -109,6 +111,7 @@ jobs:
109111
uses: protocol/[email protected]
110112
env:
111113
GOFLAGS: ${{ format('{0} {1}', env.GOTESTFLAGS, env.GOFLAGS) }}
114+
CGO_ENABLED: ${{ toJSON(fromJSON(steps.config.outputs.json).cgo) != 'false' }}
112115
with:
113116
run: go test ./...
114117
- name: Run tests (32 bit)
@@ -120,6 +123,7 @@ jobs:
120123
env:
121124
GOARCH: 386
122125
GOFLAGS: ${{ format('{0} {1}', env.GO386FLAGS, env.GOFLAGS) }}
126+
CGO_ENABLED: ${{ toJSON(fromJSON(steps.config.outputs.json).cgo) != 'false' }}
123127
with:
124128
run: |
125129
export "PATH=$PATH_386:$PATH"
@@ -132,6 +136,7 @@ jobs:
132136
uses: protocol/[email protected]
133137
env:
134138
GOFLAGS: ${{ format('{0} {1}', env.GORACEFLAGS, env.GOFLAGS) }}
139+
CGO_ENABLED: ${{ toJSON(fromJSON(steps.config.outputs.json).cgo) != 'false' }}
135140
with:
136141
run: go test -race ./...
137142
- name: Collect coverage files

.github/workflows/releaser.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
done
6262
echo "version=$version" | tee -a $GITHUB_OUTPUT
6363
echo "tag=${prefix}${version}" | tee -a $GITHUB_OUTPUT
64+
echo "suffix=${version#*[-+]}" | tee -a $GITHUB_OUTPUT
6465
- id: latest
6566
if: steps.version.outputs.version != ''
6667
name: Determine latest version
@@ -94,30 +95,29 @@ jobs:
9495
env:
9596
GITHUB_TOKEN: ${{ github.token }}
9697
REPOSITORY: ${{ github.repository }}
97-
QUERY: repository:${{ github.repository }} is:pr is:merged ${{ github.sha }}
98+
REF: ${{ github.ref }}
9899
SHA: ${{ github.sha }}
99100
uses: actions/github-script@v7
100101
with:
101102
script: |
102103
const [owner, repo] = process.env.REPOSITORY.split('/');
103-
const items = await github.paginate(github.rest.search.issuesAndPullRequests, {
104-
q: process.env.QUERY,
104+
const ref = process.env.REF.replace(/^refs\/heads\//, '');
105+
const candidates = await github.paginate(github.rest.pulls.list, {
106+
owner,
107+
repo,
108+
state: 'closed',
109+
base: ref,
105110
});
106111
let pr;
107-
for (const item of items) {
108-
const candidate = await github.rest.pulls.get({
109-
owner,
110-
repo,
111-
pull_number: item.number,
112-
});
113-
if (candidate.data.merge_commit_sha === process.env.SHA) {
112+
for (const candidate of candidates) {
113+
if (candidate.merge_commit_sha === process.env.SHA) {
114114
pr = candidate;
115115
break;
116116
}
117117
}
118118
if (pr !== undefined) {
119-
console.log(`Found PR: ${pr.data.html_url}`);
120-
const labels = pr.data.labels.map(l => l.name);
119+
console.log(`Found PR: ${pr.html_url}`);
120+
const labels = pr.labels.map(l => l.name);
121121
const release = labels.includes('release');
122122
console.log(`This is a release PR: ${release}`);
123123
core.setOutput('release', release);
@@ -148,7 +148,7 @@ jobs:
148148
tag_name: ${{ steps.version.outputs.tag }}
149149
generate_release_notes: true
150150
target_commitish: ${{ github.sha }}
151-
make_latest: ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.tag == steps.latest.outputs.latest }}
151+
make_latest: ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.suffix == '' && steps.version.outputs.tag == steps.latest.outputs.latest }}
152152
token: ${{ secrets.UCI_GITHUB_TOKEN || github.token }}
153153
- name: Create release.json
154154
if: steps.release.outputs.id != ''
@@ -163,7 +163,7 @@ jobs:
163163
"id": "${{ steps.release.outputs.id }}",
164164
"upload_url": "${{ steps.release.outputs.upload_url }}",
165165
"assets": ${{ steps.release.outputs.assets }},
166-
"make_latest": ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.tag == steps.latest.outputs.latest }},
166+
"make_latest": ${{ steps.version.outputs.prefix == 'v' && steps.version.outputs.suffix == '' && steps.version.outputs.tag == steps.latest.outputs.latest }},
167167
"source": "${{ matrix.source }}"
168168
}
169169
run: |

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8+
### Added
9+
- a `cgo` job specific configuration variable which disables cgo in the go-test workflow
10+
11+
### Changed
12+
- do not install the same version of Go twice in the go-test and go-check workflows
13+
- mark the Go update commits as breaking changes in the style of conventional commits
14+
- removed usage of search API from the releaser workflow
15+
16+
### Fixed
17+
- do not mark prereleases or versions with build strings as latest in the releaser workflow
818

919
## [1.0.15] - 2024-11-28
1020
### Changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ If you want to disable verbose logging or test shuffling, you can do so by setti
113113
}
114114
```
115115

116+
If you want to disable cgo, you can do so by setting `cgo` to `false` in `.github/workflows/go-test-config.json`:
117+
```json
118+
{
119+
"cgo": false
120+
}
121+
```
122+
116123
### Workflow Modification
117124

118125
You can modify the workflows distributed by Unified CI as you wish. Unified CI will only ever try to update the versions of reusables after the initial distribution. Similarly to how dependabot operates.

scripts/update-go.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ while read file; do
5555
git add .
5656

5757
if ! git diff-index --quiet HEAD; then
58-
git commit -m "chore: bump go.mod to Go $expected and run go fix"
58+
git commit -m "chore!: bump go.mod to Go $expected and run go fix" -m "BREAKING CHANGE: Updating the Go version to $expected"
5959
fi
6060

6161
if [[ -f go.work ]]; then
@@ -64,7 +64,7 @@ while read file; do
6464
go work use
6565
git add .
6666
if ! git diff-index --quiet HEAD; then
67-
git commit -m "chore: bump go.work to Go $expected"
67+
git commit -m "chore!: bump go.work to Go $expected" -m "BREAKING CHANGE: Updating the Go version to $expected"
6868
fi
6969
fi
7070

0 commit comments

Comments
 (0)