Skip to content

Commit 0de3dcc

Browse files
committed
feat: enhance watch-upstream workflow to sync multiple package versions and update README accordingly
1 parent 0c404a8 commit 0de3dcc

2 files changed

Lines changed: 158 additions & 99 deletions

File tree

.github/workflows/watch-upstream.yaml

Lines changed: 157 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,143 +14,205 @@ concurrency:
1414
cancel-in-progress: false
1515

1616
jobs:
17-
update:
18-
name: Update Watched Versions
17+
sync-upstream:
18+
name: Sync Watched Upstream Versions
1919
runs-on: ubuntu-latest
20+
env:
21+
WATCH_MATRIX: |
22+
[
23+
{
24+
"package_name": "nitro-cli",
25+
"repo": "library/amazonlinux",
26+
"filter": "^(2023[.][0-9]+[.][0-9]+[.][0-9]+)$",
27+
"second_filter": "",
28+
"version_file": "packages/nitro-cli/.current-version",
29+
"publish_input": "deploy-nitro-cli"
30+
},
31+
{
32+
"package_name": "walrus-upload-relay",
33+
"repo": "mysten/walrus-upload-relay",
34+
"filter": "^main-v([0-9]+[.][0-9]+[.][0-9]+)$",
35+
"second_filter": "^main-arm64-v{{version}}$",
36+
"version_file": "packages/walrus-upload-relay/.current-version",
37+
"publish_input": "deploy-walrus-upload-relay"
38+
}
39+
]
2040
steps:
2141
- name: Checkout main
2242
uses: actions/checkout@v6
2343
with:
2444
ref: main
2545

26-
- name: Fetch upstream version tag
27-
id: walrus-version
28-
uses: nerd-coder/fetch-dockerhub-tags@v1
29-
with:
30-
repo: mysten/walrus-upload-relay
31-
filter: ^main-v([0-9]+[.][0-9]+[.][0-9]+)$
32-
max_pages: 3
33-
34-
- name: Require upstream arm64 tag
35-
uses: nerd-coder/fetch-dockerhub-tags@v1
36-
with:
37-
repo: mysten/walrus-upload-relay
38-
filter: ^main-arm64-v${{ fromJSON(steps.walrus-version.outputs['matched-groups'])[0] }}$
39-
max_pages: 3
40-
41-
- name: Fetch Amazon Linux 2023 version tag
42-
id: amazonlinux-version
43-
uses: nerd-coder/fetch-dockerhub-tags@v1
44-
with:
45-
repo: library/amazonlinux
46-
filter: ^(2023[.][0-9]+[.][0-9]+[.][0-9]+)$
47-
max_pages: 3
48-
49-
- name: Detect upstream updates
50-
id: detect
51-
env:
52-
WALRUS_LATEST_VERSION: ${{ fromJSON(steps.walrus-version.outputs['matched-groups'])[0] }}
53-
WALRUS_VERSION_FILE: packages/walrus-upload-relay/.current-version
54-
AMAZONLINUX_LATEST_VERSION: ${{ fromJSON(steps.amazonlinux-version.outputs['matched-groups'])[0] }}
55-
NITRO_VERSION_FILE: packages/nitro-cli/.current-version
56-
NITRO_DOCKERFILE: packages/nitro-cli/Dockerfile
46+
- name: Fetch latest upstream tags
47+
id: watch
5748
shell: bash
5849
run: |
5950
set -euo pipefail
6051
61-
updated=false
62-
deploy_nitro_cli=false
63-
deploy_walrus_upload_relay=false
64-
summary_file="$(mktemp)"
65-
66-
update_readme_version() {
67-
local current_version="$1"
68-
local latest_version="$2"
69-
70-
sed -i "s/\`${current_version}\` 👁️/\`${latest_version}\` 👁️/" README.md
52+
fetch_latest_tag() {
53+
local repo="$1"
54+
local filter="$2"
55+
local max_pages="$3"
56+
57+
local page=1
58+
while (( page <= max_pages )); do
59+
response="$(
60+
curl -fsSL "https://hub.docker.com/v2/repositories/${repo}/tags?page=${page}&page_size=100"
61+
)"
62+
63+
tag="$(
64+
jq -r --arg filter "${filter}" '
65+
.results[]?.name
66+
| match($filter)?
67+
| select(. != null)
68+
| (.captures[0].string // .string)
69+
' <<< "${response}" | head -n1
70+
)"
71+
72+
if [[ -n "${tag}" ]]; then
73+
printf '%s\n' "${tag}"
74+
return 0
75+
fi
76+
77+
page=$((page + 1))
78+
done
79+
80+
echo "No tag matched ${filter} in ${repo}" >&2
81+
return 1
7182
}
7283
73-
walrus_current_version="$(tr -d '[:space:]' < "${WALRUS_VERSION_FILE}")"
74-
if [[ -z "${walrus_current_version}" ]]; then
75-
echo "No version found in ${WALRUS_VERSION_FILE}" >&2
76-
exit 1
77-
fi
84+
packages="$(jq -cn '{}')"
7885
79-
if [[ "${walrus_current_version}" != "${WALRUS_LATEST_VERSION}" ]]; then
80-
printf '%s\n' "${WALRUS_LATEST_VERSION}" > "${WALRUS_VERSION_FILE}"
81-
update_readme_version "${walrus_current_version}" "${WALRUS_LATEST_VERSION}"
86+
while read -r package; do
87+
package_name="$(jq -r '.package_name' <<< "${package}")"
88+
repo="$(jq -r '.repo' <<< "${package}")"
89+
filter="$(jq -r '.filter' <<< "${package}")"
90+
second_filter="$(jq -r '.second_filter' <<< "${package}")"
8291
83-
updated=true
84-
deploy_walrus_upload_relay=true
85-
printf '%s\n' "- walrus-upload-relay: ${walrus_current_version} -> ${WALRUS_LATEST_VERSION}" >> "${summary_file}"
86-
else
87-
echo "walrus-upload-relay is already at ${WALRUS_LATEST_VERSION}"
88-
fi
89-
90-
nitro_current_version="$(tr -d '[:space:]' < "${NITRO_VERSION_FILE}")"
91-
if [[ -z "${nitro_current_version}" ]]; then
92-
echo "No version found in ${NITRO_VERSION_FILE}" >&2
93-
exit 1
94-
fi
92+
latest_version="$(fetch_latest_tag "${repo}" "${filter}" 3)"
9593
96-
if [[ "${nitro_current_version}" != "${AMAZONLINUX_LATEST_VERSION}" ]]; then
97-
printf '%s\n' "${AMAZONLINUX_LATEST_VERSION}" > "${NITRO_VERSION_FILE}"
98-
update_readme_version "${nitro_current_version}" "${AMAZONLINUX_LATEST_VERSION}"
99-
sed -i "s/^ARG VERSION=${nitro_current_version}$/ARG VERSION=${AMAZONLINUX_LATEST_VERSION}/" "${NITRO_DOCKERFILE}"
94+
if [[ -n "${second_filter}" ]]; then
95+
resolved_second_filter="${second_filter//\{\{version\}\}/${latest_version}}"
96+
fetch_latest_tag "${repo}" "${resolved_second_filter}" 3 > /dev/null
97+
fi
10098
101-
updated=true
102-
deploy_nitro_cli=true
103-
printf '%s\n' "- nitro-cli: ${nitro_current_version} -> ${AMAZONLINUX_LATEST_VERSION}" >> "${summary_file}"
104-
else
105-
echo "nitro-cli is already at ${AMAZONLINUX_LATEST_VERSION}"
106-
fi
99+
packages="$(
100+
jq -c \
101+
--arg package_name "${package_name}" \
102+
--arg latest_version "${latest_version}" \
103+
--argjson package "${package}" \
104+
'. + {($package_name): ($package + {latest_version: $latest_version})}' \
105+
<<< "${packages}"
106+
)"
107+
done < <(jq -c '.[]' <<< "${WATCH_MATRIX}")
107108
108109
{
109-
echo "updated=${updated}"
110-
echo "deploy-nitro-cli=${deploy_nitro_cli}"
111-
echo "deploy-walrus-upload-relay=${deploy_walrus_upload_relay}"
112-
echo "summary<<EOF"
113-
cat "${summary_file}"
110+
echo "packages<<EOF"
111+
jq -c . <<< "${packages}"
114112
echo "EOF"
115113
} >> "${GITHUB_OUTPUT}"
116114
117-
- name: Commit updates
118-
if: steps.detect.outputs.updated == 'true'
115+
- name: Patch and commit latest versions
116+
id: sync
119117
env:
120-
SUMMARY: ${{ steps.detect.outputs.summary }}
118+
WATCHED_PACKAGES: ${{ steps.watch.outputs.packages }}
121119
shell: bash
122120
run: |
123121
set -euo pipefail
124122
123+
update_readme_version() {
124+
local package_name="$1"
125+
local current_version="$2"
126+
local latest_version="$3"
127+
128+
sed -i "/\[\`cmdoss\/${package_name}\`\]/s/\`${current_version}\` 👁️/\`${latest_version}\` 👁️/" README.md
129+
130+
if ! grep -F "[\`cmdoss/${package_name}\`]" README.md | grep -Fq "\`${latest_version}\` 👁️"; then
131+
echo "Failed to update ${package_name} version in README.md" >&2
132+
exit 1
133+
fi
134+
}
135+
136+
updated=false
137+
deploy_inputs="$(
138+
jq -c '
139+
map({(.publish_input): "false"})
140+
| add
141+
| . + {"deploy-auth-proxy": "false"}
142+
' <<< "${WATCH_MATRIX}"
143+
)"
144+
summary_file="$(mktemp)"
145+
146+
while read -r package; do
147+
package_name="$(jq -r '.package_name' <<< "${package}")"
148+
version_file="$(jq -r '.version_file' <<< "${package}")"
149+
publish_input="$(jq -r '.publish_input' <<< "${package}")"
150+
latest_version="$(jq -r '.latest_version' <<< "${package}")"
151+
152+
current_version="$(tr -d '[:space:]' < "${version_file}")"
153+
if [[ -z "${current_version}" ]]; then
154+
echo "No version found in ${version_file}" >&2
155+
exit 1
156+
fi
157+
158+
if [[ "${current_version}" == "${latest_version}" ]]; then
159+
echo "${package_name} is already at ${latest_version}"
160+
continue
161+
fi
162+
163+
printf '%s\n' "${latest_version}" > "${version_file}"
164+
update_readme_version "${package_name}" "${current_version}" "${latest_version}"
165+
166+
deploy_inputs="$(jq -c --arg publish_input "${publish_input}" '.[$publish_input] = "true"' <<< "${deploy_inputs}")"
167+
updated=true
168+
printf '%s\n' "- ${package_name}: ${current_version} -> ${latest_version}" >> "${summary_file}"
169+
done < <(jq -c '.[]' <<< "${WATCHED_PACKAGES}")
170+
171+
if [[ "${updated}" != "true" ]]; then
172+
{
173+
echo "updated=false"
174+
echo "deploy-inputs<<EOF"
175+
jq -c . <<< "${deploy_inputs}"
176+
echo "EOF"
177+
} >> "${GITHUB_OUTPUT}"
178+
179+
echo "No watched upstream image updates found."
180+
exit 0
181+
fi
182+
125183
git config user.name "github-actions[bot]"
126184
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
127185
128-
git add -- packages/nitro-cli/.current-version packages/nitro-cli/Dockerfile packages/walrus-upload-relay/.current-version README.md
129-
git commit -m "chore: update watched upstream image versions" -m "${SUMMARY}"
186+
mapfile -d '' changed_paths < <(git diff --name-only -z)
187+
git add -- "${changed_paths[@]}"
188+
189+
summary="$(cat "${summary_file}")"
190+
git commit -m "chore: update watched upstream image versions" -m "${summary}"
130191
git push origin HEAD:main
131192
193+
{
194+
echo "updated=true"
195+
echo "deploy-inputs<<EOF"
196+
jq -c . <<< "${deploy_inputs}"
197+
echo "EOF"
198+
} >> "${GITHUB_OUTPUT}"
199+
132200
- name: Dispatch publish
133-
if: steps.detect.outputs.updated == 'true'
201+
if: steps.sync.outputs.updated == 'true'
134202
env:
135203
GH_TOKEN: ${{ github.token }}
136-
DEPLOY_NITRO_CLI: ${{ steps.detect.outputs['deploy-nitro-cli'] }}
137-
DEPLOY_WALRUS_UPLOAD_RELAY: ${{ steps.detect.outputs['deploy-walrus-upload-relay'] }}
204+
DEPLOY_INPUTS: ${{ steps.sync.outputs['deploy-inputs'] }}
138205
shell: bash
139206
run: |
140207
set -euo pipefail
141208
142209
payload="$(
143210
jq -cn \
144-
--arg deploy_nitro_cli "${DEPLOY_NITRO_CLI}" \
145-
--arg deploy_walrus_upload_relay "${DEPLOY_WALRUS_UPLOAD_RELAY}" \
211+
--argjson inputs "${DEPLOY_INPUTS}" \
146212
'{
147-
ref: "main",
148-
inputs: {
149-
"deploy-nitro-cli": $deploy_nitro_cli,
150-
"deploy-auth-proxy": "false",
151-
"deploy-walrus-upload-relay": $deploy_walrus_upload_relay
152-
}
153-
}'
213+
ref: "main",
214+
inputs: $inputs
215+
}'
154216
)"
155217
156218
curl -fsSL \
@@ -160,7 +222,3 @@ jobs:
160222
-H "X-GitHub-Api-Version: 2022-11-28" \
161223
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/workflows/publish.yaml/dispatches" \
162224
-d "${payload}"
163-
164-
- name: Report no updates
165-
if: steps.detect.outputs.updated != 'true'
166-
run: echo "No watched upstream image updates found."

packages/nitro-cli/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Default for local builds. Release builds pass VERSION from .current-version.
12
ARG VERSION=2023
23

34
FROM amazonlinux:${VERSION}

0 commit comments

Comments
 (0)