Repository navigation
164 lines (153 loc) · 7.21 KB
/
Copy pathbump.yml
File metadata and controls
164 lines (153 loc) · 7.21 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
name: Bump versions
# Weekly: check the upstream release feeds for newer releases than what's
# pinned here -- nginx-stable/angie in ci-deep.yml's build-flavors matrix,
# the harness jobs' static mainline pin (HARNESS_NGINX_VERSION in ci-deep.yml
# and harness-fault-arms.yml), the Windows build's sources in
# ci/tools/windows-pins.sh, and the Arch package's exact nginx pin in
# packaging/arch/PKGBUILD (from Arch's own package database, which lags
# nginx.org by its packaging time). The matrix's own mainline entry is resolved
# dynamically at CI run time (build-test.yml's `resolve` job / ci-deep.yml's
# per-job resolve steps, through ci/tools/nginx-releases.sh) and has no
# static pin; ci/tools/bump-versions.sh's header lists exactly what is and
# is not bumped.
#
# ci/tools/bump-versions.sh does the actual work (also runnable locally with
# --dry-run to preview). Opens a PR rather than pushing straight to master --
# master carries a required-pull-request ruleset with no bypass actor, so a
# direct push is always rejected (audit sha e289021 F4); the bot instead
# pushes a branch and opens a PR via BUMP_PR_TOKEN (a classic PAT -- the
# default GITHUB_TOKEN cannot create PRs on myguard-labs repos). Normal
# review/required-checks still gate the merge.
#
# BUMP_PR_TOKEN authenticates BOTH halves: gh (via GH_TOKEN) for the PR, and
# git (via GIT_ASKPASS) for the branch push. persist-credentials is false, so
# the push has no ambient credential of its own -- without the askpass helper
# it dies on "could not read Username for 'https://github.com'".
#
# Action pins (keep in sync with build-test.yml):
# actions/checkout@v5.1.0 -> fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
on:
schedule:
# Weekly, Monday 04:00 UTC.
- cron: "0 4 * * 1"
workflow_dispatch: {}
concurrency:
group: bump-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
bump:
name: Bump version pins
runs-on: ${{ fromJSON(vars.POOL || '["ubuntu-latest"]') }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
persist-credentials: false
fetch-depth: 0
# Secrets do not travel with a fork, so a fork's scheduled run has no
# BUMP_PR_TOKEN. Without this step such a run stays green for as long
# as nothing needs bumping and then dies at the branch push, mailing
# the fork's owner a failure about a repository they do not bump. In a
# fork the missing token ends the run green with a notice; anywhere
# else it is a broken bumper and fails HERE, by name, rather than
# downstream as a git authentication error. Whether this is a fork is
# asked of the API with the run's own read-only token, and a failed
# lookup counts as "not a fork" -- the strict side. The step comes
# before the full apt install so a skipping fork pays nothing past
# the checkout; it needs only gh, which the hosted runner image
# ships. A POOL runner without gh would otherwise turn the lookup
# into "unknown" and fail a fork by name, so gh alone is installed
# when it is missing.
- name: Ensure gh is available
run: |
if ! command -v gh >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y gh
fi
- name: Require BUMP_PR_TOKEN (a fork without one skips, green)
id: token
env:
BUMP_PR_TOKEN: ${{ secrets.BUMP_PR_TOKEN }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if [ -n "$BUMP_PR_TOKEN" ]; then
echo "present=true" >>"$GITHUB_OUTPUT"
exit 0
fi
echo "present=false" >>"$GITHUB_OUTPUT"
fork="$(gh api "repos/$GITHUB_REPOSITORY" --jq .fork 2>/dev/null || echo unknown)"
if [ "$fork" = "true" ]; then
echo "::notice::BUMP_PR_TOKEN is not set in this fork; skipping the version bump. Set the secret to run it here."
exit 0
fi
echo "::error::BUMP_PR_TOKEN is not set (fork=$fork); the bump cannot push its branch or open its PR."
exit 1
# This scheduled workflow also falls back to ubuntu-latest for forks.
- name: Install dependencies
if: steps.token.outputs.present == 'true'
run: |
sudo apt-get update
sudo apt-get install -y curl gh git gnupg python3
- name: Run bump script
id: bump
if: steps.token.outputs.present == 'true'
env:
# The angie release lookup hits api.github.com; unauthenticated the
# shared runner IP is rate-limited to 403s.
GH_TOKEN: ${{ secrets.BUMP_PR_TOKEN }}
run: bash ci/tools/bump-versions.sh
- name: Open PR if anything changed
if: steps.token.outputs.present == 'true'
env:
GH_TOKEN: ${{ secrets.BUMP_PR_TOKEN }}
BUMP_PR_TOKEN: ${{ secrets.BUMP_PR_TOKEN }}
run: |
set -euo pipefail
if [ -z "$(git status --porcelain)" ]; then
echo "nothing changed, skipping PR"
exit 0
fi
branch="bump/versions-$(date -u +%Y%m%d)"
git config user.name "myguard-bump-bot"
git config user.email "actions@users.noreply.github.com"
git checkout -b "$branch"
git add -A
git commit -m "chore: bump version pins
Automated weekly version check (ci/tools/bump-versions.sh)."
# persist-credentials is false, so the checkout leaves no git
# credential behind and a plain `git push` prompts for a username
# (fatal: could not read Username, run 29722422889). GH_TOKEN
# authenticates gh but not git, so hand git its own credential via
# the askpass helper -- keeps the token out of argv and out of
# .git/config, unlike an inline x-access-token@ push URL.
git config credential.helper ''
askpass="$(mktemp)"
cat > "$askpass" <<'ASKPASS'
#!/bin/sh
case "$1" in
Username*) echo x-access-token ;;
*) printf '%s' "$BUMP_PR_TOKEN" ;;
esac
ASKPASS
chmod 700 "$askpass"
# Force-push: the branch name is date-based, so a same-day re-run
# (a manual dispatch, or a retry after a failure) collides with the
# branch the earlier run created and is otherwise rejected
# non-fast-forward. The branch is bot-owned and disposable.
GIT_ASKPASS="$askpass" git push --force-with-lease origin "$branch"
rm -f "$askpass"
# An open PR for this branch may already exist from that earlier
# run; the push above has refreshed it, so there is nothing to do.
if [ -n "$(gh pr list --head "$branch" --state open --json number -q '.[0].number')" ]; then
echo "PR for $branch already open, refreshed by the push"
exit 0
fi
gh pr create \
--title "chore: bump version pins ($(date -u +%Y-%m-%d))" \
--body "Automated weekly version check (ci/tools/bump-versions.sh). Review the diff and let required CI checks gate the merge." \
--base master \
--head "$branch"