Skip to content

Commit 9a04d57

Browse files
Mat001claude
andauthored
[FSSDK-12919] Replace deprecated hub CLI with gh in release workflow (#467)
* [FSSDK-12919] Replace deprecated hub CLI with gh in release workflow Agent GitHub releases were shipping with no binary assets because the release workflow attached generate_secret via the deprecated `hub` CLI, which is not installed on GitHub-hosted runners (hub: command not found). Replace `hub` with `gh` (preinstalled on all runners): - ci_attach_generate_secret.sh: `hub release edit -a` -> `gh release upload --clobber` - new ci_create_github_release.sh: gh-based, idempotent replacement for travisci-tools/release_github_v2.sh (same CHANGELOG parsing) - workflow: drop install_hub.sh steps + unused travisci-tools checkouts; `hub release download -i` -> `gh release download -p` https://optimizely-ext.atlassian.net/browse/FSSDK-12919 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [FSSDK-12919] Address review: harden release script, drop unused HOME - ci_create_github_release.sh: set -eo pipefail; guard missing CHANGELOG.md; quote CHANGELOG; write notes to a temp file and use --notes-file so backticks/$ in the changelog body aren't shell-parsed - agent.yml: remove now-unused HOME='home/runner' override Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dd1e69c commit 9a04d57

3 files changed

Lines changed: 82 additions & 41 deletions

File tree

‎.github/workflows/agent.yml‎

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ jobs:
170170
with:
171171
go-version: '1.24.0'
172172
check-latest: true
173-
- uses: actions/checkout@v2
174-
with:
175-
# You should create a personal access token and store it in your repository
176-
token: ${{ secrets.CI_USER_TOKEN }}
177-
repository: 'optimizely/travisci-tools'
178-
path: 'home/runner/travisci-tools'
179-
ref: 'master'
180-
persist-credentials: false
181173
- name: Get the version
182174
id: get_version
183175
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
@@ -190,31 +182,22 @@ jobs:
190182
echo "APP_VERSION=${TAG#v}" >> $GITHUB_ENV
191183
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV
192184
echo "TRAVIS_BUILD_DIR=${{ steps.get_workspace.outputs.WORKSPACE }}" >> $GITHUB_ENV
193-
- name: Upload and publish draft
194-
env:
195-
HOME: 'home/runner'
196-
run: |
197-
# installs hub to ~/bin
198-
$HOME/travisci-tools/release_github/install_hub.sh
199-
echo "$HOME/bin:$HOME/travisci-tools/release_github" >> $GITHUB_PATH
200185
- name: run make
201186
env:
202187
TRAVIS_OS_NAME: 'linux'
203188
run: |
204189
make -e setup build
205190
- name: create and upload packages
206-
env:
207-
HOME: 'home/runner'
191+
env:
208192
GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }}
209193
TRAVIS_OS_NAME: 'linux'
210194
DOCKERHUB_PASS: ${{ secrets.DOCKERHUB_PASS }}
211195
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
212196
run: |
213197
# now we're going to create packages & upload packages
214198
./scripts/ci_create_packages.sh && ./scripts/ci_upload_packages.sh
215-
# create the github release (draft)
216-
cp $HOME/travisci-tools/release_github/release_github_v2.sh .
217-
./release_github_v2.sh "$APP_VERSION"
199+
# create the github release (draft) if it doesn't already exist
200+
./scripts/ci_create_github_release.sh "$RELEASE_TAG"
218201
# attach generate_secret to the github release
219202
./scripts/ci_build_generate_secret.sh && ./scripts/ci_attach_generate_secret.sh
220203
@@ -244,29 +227,13 @@ jobs:
244227
with:
245228
go-version: '1.24.0'
246229
check-latest: true
247-
- uses: actions/checkout@v2
248-
with:
249-
# You should create a personal access token and store it in your repository
250-
token: ${{ secrets.CI_USER_TOKEN }}
251-
repository: 'optimizely/travisci-tools'
252-
path: 'home/runner/travisci-tools'
253-
ref: 'master'
254-
persist-credentials: false
255230
- name: Get the version
256231
id: get_version
257232
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
258233
- name: set the env
259234
run: |
260235
TAG=${{ steps.get_version.outputs.VERSION }}
261236
echo "APP_VERSION=${TAG#v}" >> $GITHUB_ENV
262-
- name: Upload and publish draft
263-
shell: bash
264-
env:
265-
HOME: 'home/runner'
266-
run: |
267-
# installs hub to ~/bin
268-
$HOME/travisci-tools/release_github/install_hub.sh
269-
# echo "$HOME/bin:$HOME/travisci-tools/slack" >> $GITHUB_PATH
270237
- name: run script
271238
env:
272239
GITHUB_TOKEN: ${{ secrets.CI_USER_TOKEN }}
@@ -276,7 +243,8 @@ jobs:
276243
id: script
277244
shell: bash
278245
run: |
279-
hub release download $(git describe --abbrev=0 --tags) -i '*-${{ matrix.TARGET }}-*'
246+
# gh is preinstalled on GitHub-hosted runners; replaces the deprecated hub CLI
247+
gh release download $(git describe --abbrev=0 --tags) -p '*-${{ matrix.TARGET }}-*'
280248
tar xvfz generate_secret-${{ matrix.TARGET }}-${APP_VERSION}.tar.gz -C /tmp
281249
/tmp/generate_secret
282250
# TODO: add step to publish outcome on teams.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
hub release edit "$RELEASE_TAG" -m "" \
5-
-a "/tmp/output_packages/generate_secret-linux-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Linux 64-bit" \
6-
-a "/tmp/output_packages/generate_secret-darwin-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for MacOS 64-bit" \
7-
-a "/tmp/output_packages/generate_secret-windows-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Windows 64-bit"
4+
# Attaches the generate_secret binaries to the GitHub release for $RELEASE_TAG.
5+
# Uses `gh` (preinstalled on GitHub-hosted runners) instead of the deprecated `hub` CLI.
6+
# `gh release upload` supports per-asset display labels via the "path#label" syntax.
7+
gh release upload "$RELEASE_TAG" --clobber \
8+
"/tmp/output_packages/generate_secret-linux-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Linux 64-bit" \
9+
"/tmp/output_packages/generate_secret-darwin-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for MacOS 64-bit" \
10+
"/tmp/output_packages/generate_secret-windows-amd64-$APP_VERSION.tar.gz#generate_secret $APP_VERSION for Windows 64-bit"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
# Creates a draft GitHub release for the given tag, using the latest
5+
# CHANGELOG.md entry as the release description.
6+
#
7+
# This is a `gh`-based replacement for travisci-tools/release_github/release_github_v2.sh,
8+
# which relied on the deprecated `hub` CLI. `gh` is preinstalled on GitHub-hosted runners.
9+
#
10+
# Run this in the same directory where CHANGELOG.md lives.
11+
# grep -P below is GNU grep specific, so this is meant to run on Linux.
12+
13+
CHANGELOG="CHANGELOG.md"
14+
15+
# set to true for debugging
16+
debug=false
17+
18+
if [ $# -ne 1 ]; then
19+
echo "example: $0 v3.1.1"
20+
exit 1
21+
fi
22+
23+
# the tag being released, e.g. v4.6.0
24+
GIT_TAG="$1"
25+
26+
# VERSION is the git tag with the "v" prefix removed
27+
VERSION=${GIT_TAG#v}
28+
29+
# The release is often already created (the tag push that triggers CI usually
30+
# comes from a GitHub release created in the UI). In that case there is nothing
31+
# to create -- just let the caller move on to uploading assets.
32+
if gh release view "${GIT_TAG}" >/dev/null 2>&1; then
33+
echo "Release ${GIT_TAG} already exists; skipping creation."
34+
exit 0
35+
fi
36+
37+
if [[ ! -f "${CHANGELOG}" ]]; then
38+
echo "ERROR: ${CHANGELOG} not found in $(pwd)."
39+
exit 1
40+
fi
41+
42+
# check that CHANGELOG.md has been updated
43+
# (first version entry in the changelog should match our VERSION argument)
44+
NEW_VERSION_CHECK=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | cut -d[ -f2 | cut -d] -f1 | awk 'NR==1')
45+
46+
$debug && echo "NEW_VERSION_CHECK $NEW_VERSION_CHECK"
47+
$debug && echo "VERSION $VERSION"
48+
49+
if [[ "${NEW_VERSION_CHECK}" != "${VERSION}" ]]; then
50+
echo "ERROR: ${CHANGELOG} has not been updated yet."
51+
exit 1
52+
fi
53+
54+
NEW_VERSION=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | awk 'NR==1' | sed -e 's/\[/\\\[/' | sed -e 's/\]/\\\]/')
55+
LAST_VERSION=$(grep -P '^## \[\d+\.\d+\.\d+\]' "${CHANGELOG}" | awk 'NR==2' | sed -e 's/\[/\\\[/' | sed -e 's/\]/\\\]/')
56+
57+
DESCRIPTION=$(awk "/^${NEW_VERSION}$/,/^${LAST_VERSION:-nothingmatched}$/" "${CHANGELOG}" | grep -v "^${LAST_VERSION:-nothingmatched}$")
58+
59+
$debug && echo "NEW_VERSION $NEW_VERSION"
60+
$debug && echo "LAST_VERSION $LAST_VERSION"
61+
$debug && echo "DESCRIPTION $DESCRIPTION"
62+
63+
# Write the notes to a temp file and pass via --notes-file. This avoids the shell
64+
# re-parsing backticks / $ that can appear in changelog bodies (which --notes would).
65+
NOTES_FILE=$(mktemp)
66+
trap 'rm -f "${NOTES_FILE}"' EXIT
67+
printf '%s\n' "${DESCRIPTION}" > "${NOTES_FILE}"
68+
69+
# --draft creates a draft release; the tag already exists (release is triggered by the tag push)
70+
gh release create "${GIT_TAG}" --draft --title "Release ${VERSION}" --notes-file "${NOTES_FILE}"

0 commit comments

Comments
 (0)