Repository navigation
189 lines (168 loc) · 7.32 KB
/
Copy pathrelease.yml
File metadata and controls
189 lines (168 loc) · 7.32 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Release: tag main's HEAD with the next version and publish a GitHub release.
#
# It runs on its own twice a week (Monday and Thursday, 14:00 UTC) as a patch release,
# and only when something was merged since the last tag; otherwise it does nothing.
# A maintainer can also run it by hand any time (Actions -> Release -> Run workflow ->
# pick the bump), e.g. for an urgent fix or a minor release. It never runs on push or on a PR.
#
# patch v0.4.1 -> v0.4.2 fixes, new providers or sources on an existing kind
# minor v0.4.1 -> v0.5.0 new kinds, new or moved exported API, anything a user should read about
# (no tag yet -> v0.1.0)
#
# v1.0.0 and later majors are not an option here: they are a deliberate decision a
# maintainer makes by hand, not a button.
#
# Fail closed: the leak guard, gitleaks, build, vet, gofmt and the tests run on the exact
# commit being tagged, and any failure stops the run before a tag exists.
#
# NEVER delete or move a pushed tag. Go's module proxy (proxy.golang.org) and checksum
# database remember every version forever, so a moved tag breaks everyone who already
# fetched it. If a release is wrong, fix it on main and release a new patch version.
name: Release
on:
schedule:
- cron: "0 14 * * 1,4" # Mon + Thu 14:00 UTC; scheduled runs are always a patch release
workflow_dispatch:
inputs:
bump:
description: "Which part of the version to bump (patch: fixes and providers; minor: new kinds or API)"
type: choice
options:
- patch
- minor
default: patch
permissions:
contents: write
# One release at a time; a second run waits instead of cancelling the first.
concurrency:
group: release
cancel-in-progress: false
env:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
jobs:
release:
name: tag and release main
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: only from main
if: github.ref != 'refs/heads/main'
env:
REF: ${{ github.ref }}
run: |
echo "::error::Run the Release workflow from main, not $REF."
exit 1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
fetch-tags: true
- name: next version
id: version
env:
BUMP: ${{ inputs.bump || 'patch' }}
EVENT: ${{ github.event_name }}
run: |
head=$(git rev-parse HEAD)
existing=$(git tag --points-at "$head")
if [ -n "$existing" ]; then
if [ "$EVENT" = "schedule" ]; then
echo "Nothing merged since $existing: no release this time."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "::error::main's HEAD ($head) is already tagged: $existing. Nothing new to release."
exit 1
fi
latest=$(git tag -l 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1 || true)
if [ -z "$latest" ]; then
next=v0.1.0
else
IFS=. read -r major minor patch <<< "${latest#v}"
case "$BUMP" in
patch) next="v${major}.${minor}.$((patch + 1))" ;;
minor) next="v${major}.$((minor + 1)).0" ;;
*) echo "::error::unknown bump '$BUMP'"; exit 1 ;;
esac
fi
if git rev-parse -q --verify "refs/tags/$next" >/dev/null; then
echo "::error::$next already exists."
exit 1
fi
# A new kind (a new kinds/<kind>/ directory) deserves a minor, not a
# patch. A scheduled run can't decide that, so it skips and a maintainer releases by hand.
if [ "$EVENT" = "schedule" ] && [ -n "$latest" ]; then
new_formats=$(comm -13 <(git ls-tree -d --name-only "$latest" kinds/ | sort) <(git ls-tree -d --name-only HEAD kinds/ | sort))
if [ -n "$new_formats" ]; then
echo "::warning::New kind(s) since $latest: $new_formats. That's a minor release: run Release by hand with bump=minor."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
echo "latest=${latest:-none}, bump=$BUMP -> $next at $head"
echo "tag=$next" >> "$GITHUB_OUTPUT"
echo "sha=$head" >> "$GITHUB_OUTPUT"
- name: internal names (hashed), whole tree
if: steps.version.outputs.skip != 'true'
run: python3 scripts/leak_guard.py --all
- name: install gitleaks ${{ env.GITLEAKS_VERSION }}
if: steps.version.outputs.skip != 'true'
run: |
tarball="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -fsSL -o "$RUNNER_TEMP/$tarball" "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${tarball}"
echo "${GITLEAKS_SHA256} $RUNNER_TEMP/$tarball" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/$tarball" -C "$RUNNER_TEMP" gitleaks
- name: gitleaks, whole history
if: steps.version.outputs.skip != 'true'
run: '"$RUNNER_TEMP/gitleaks" git --no-banner --redact --verbose .'
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
if: steps.version.outputs.skip != 'true'
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: go build
if: steps.version.outputs.skip != 'true'
run: go build ./...
- name: go vet
if: steps.version.outputs.skip != 'true'
run: go vet ./...
- name: gofmt
if: steps.version.outputs.skip != 'true'
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "::error::not gofmt-formatted:"; echo "$unformatted"; exit 1
fi
- name: go test
if: steps.version.outputs.skip != 'true'
run: go test -race -count=1 ./...
# Only reached when every check above passed.
- name: create and push the annotated tag
if: steps.version.outputs.skip != 'true'
env:
TAG: ${{ steps.version.outputs.tag }}
SHA: ${{ steps.version.outputs.sha }}
ACTOR: ${{ github.actor }}
EVENT_NAME: ${{ github.event_name }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
by="scheduled"
[ "$EVENT_NAME" = "workflow_dispatch" ] && by="run by @$ACTOR"
git tag -a "$TAG" "$SHA" -m "$TAG" -m "Released by the Release workflow ($by)."
git push origin "refs/tags/$TAG"
# The list of providers and sources, from the registry at the tag: the
# release's plugins.json asset. Never committed; the docs site reads the
# latest release's copy.
- name: list the providers and sources
if: steps.version.outputs.skip != 'true'
env:
TAG: ${{ steps.version.outputs.tag }}
run: go run ./cmd/list-plugins -ref "$TAG" -o "$RUNNER_TEMP/plugins.json"
- name: publish the GitHub release
if: steps.version.outputs.skip != 'true'
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: gh release create "$TAG" --verify-tag --generate-notes --title "$TAG" "$RUNNER_TEMP/plugins.json"