Skip to content

Commit 599d64c

Browse files
author
Akash Satheesan
committed
chore(ci): migrate from hub to gh
1 parent f21884c commit 599d64c

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

ci/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Any file or directory in this subdirectory should be documented here.
2424
- It will upload them to the draft release.
2525
6. Run some basic sanity tests on one of the released packages.
2626
- Especially make sure the terminal works fine.
27-
7. Make sure the github release tag is the commit with the artifacts. This is a bug in
28-
`hub` where uploading assets in step 5 will break the tag.
27+
7. Make sure the github release tag is the commit with the artifacts.
2928
8. Publish the release and merge the PR.
3029
1. CI will automatically grab the artifacts and then:
3130
1. Publish the NPM package from `npm-package`.
@@ -106,10 +105,10 @@ You can disable minification by setting `MINIFY=`.
106105
- [./ci/build/code-server.service](./build/code-server.service)
107106
- systemd user service packaged into the `.deb` and `.rpm`.
108107
- [./ci/build/release-github-draft.sh](./build/release-github-draft.sh) (`yarn release:github-draft`)
109-
- Uses [hub](https://github.com/github/hub) to create a draft release with a template description.
108+
- Uses [gh](https://github.com/cli/cli) to create a draft release with a template description.
110109
- [./ci/build/release-github-assets.sh](./build/release-github-assets.sh) (`yarn release:github-assets`)
111110
- Downloads the release-package artifacts for the current commit from CI.
112-
- Uses [hub](https://github.com/github/hub) to upload the artifacts to the release
111+
- Uses [gh](https://github.com/cli/cli) to upload the artifacts to the release
113112
specified in `package.json`.
114113
- [./ci/build/npm-postinstall.sh](./build/npm-postinstall.sh)
115114
- Post install script for the npm package.

ci/build/release-github-assets.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main() {
1515
for i in "${!assets[@]}"; do
1616
assets[$i]="--attach=${assets[$i]}"
1717
done
18-
EDITOR=true hub release edit --draft "${assets[@]}" "v$VERSION"
18+
EDITOR=true gh release upload "v$VERSION" "${assets[@]}"
1919
}
2020

2121
main "$@"

ci/build/release-github-draft.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ main() {
77
cd "$(dirname "$0")/../.."
88
source ./ci/lib.sh
99

10-
hub release create \
11-
--file - \
12-
-t "$(git rev-parse HEAD)" \
13-
--draft "v$VERSION" <<EOF
10+
gh release create "v$VERSION" \
11+
--notes-file - \
12+
--target "$(git rev-parse HEAD)" \
13+
--draft <<EOF
1414
v$VERSION
1515
1616
VS Code v$(vscode_version)

ci/build/release-prep.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# Description: This is a script to make the release process easier
33
# Run it with `yarn release:prep` and it will do the following:
4-
# 1. Check that you have a $GITHUB_TOKEN set and hub installed
4+
# 1. Check that you have gh installed and that you're signed in
55
# 2. Update the version of code-server (package.json, docs, etc.)
66
# 3. Update the code coverage badge in the README
77
# 4. Open a draft PR using the release_template.md and view in browser
@@ -19,19 +19,11 @@ main() {
1919

2020
cd "$(dirname "$0")/../.."
2121

22-
# Check that $GITHUB_TOKEN is set
23-
if [[ -z ${GITHUB_TOKEN-} ]]; then
24-
echo "We couldn't find an environment variable under GITHUB_TOKEN."
25-
echo "This is needed for our scripts that use hub."
26-
echo -e "See docs regarding GITHUB_TOKEN here under 'GitHub OAuth authentication': https://hub.github.com/hub.1.html"
27-
exit
28-
fi
29-
30-
# Check that hub is installed
31-
if ! command -v hub &>/dev/null; then
32-
echo "hub could not be found."
22+
# Check that gh is installed
23+
if ! command -v gh &>/dev/null; then
24+
echo "gh could not be found."
3325
echo "We use this with the release-github-draft.sh and release-github-assets.sh scripts."
34-
echo -e "See docs here: https://github.com/github/hub#installation"
26+
echo -e "See docs here: https://github.com/cli/cli#installation"
3527
exit
3628
fi
3729

@@ -68,6 +60,14 @@ main() {
6860
exit
6961
fi
7062

63+
# Check that gh is authenticated
64+
if ! gh auth status -h github.com &>/dev/null; then
65+
echo "gh isn't authenticated to github.com."
66+
echo "This is needed for our scripts that use gh."
67+
echo -e "See docs regarding authentication: https://cli.github.com/manual/gh_auth_login"
68+
exit
69+
fi
70+
7171
# Note: we need to set upstream as well or the gh pr create step will fail
7272
# See: https://github.com/cli/cli/issues/575
7373
CURRENT_BRANCH=$(git branch | grep '\*' | cut -d' ' -f2-)

ci/lib.sh

+5-9
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,20 @@ arch() {
4949
esac
5050
}
5151

52-
curl() {
53-
command curl -H "Authorization: token $GITHUB_TOKEN" "$@"
54-
}
55-
5652
# Grabs the most recent ci.yaml github workflow run that was successful and triggered from the same commit being pushd.
5753
# This will contain the artifacts we want.
5854
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
5955
get_artifacts_url() {
6056
local artifacts_url
61-
local workflow_runs_url="https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=pull_request"
57+
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?status=success&event=pull_request"
6258
# For releases, we look for run based on the branch name v$code_server_version
6359
# example: v3.9.3
6460
local version_branch="v$VERSION"
65-
artifacts_url=$(curl -fsSL "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
61+
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
6662
if [[ -z "$artifacts_url" ]]; then
6763
echo >&2 "ERROR: artifacts_url came back empty"
6864
echo >&2 "We looked for a successful run triggered by a pull_request with for code-server version: $code_server_version and a branch named $version_branch"
69-
echo >&2 "URL used for curl call: $workflow_runs_url"
65+
echo >&2 "URL used for gh API call: $workflow_runs_url"
7066
exit 1
7167
fi
7268

@@ -77,7 +73,7 @@ get_artifacts_url() {
7773
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
7874
get_artifact_url() {
7975
local artifact_name="$1"
80-
curl -fsSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
76+
gh api "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
8177
}
8278

8379
# Uses the above two functions to download a artifact into a directory.
@@ -88,7 +84,7 @@ download_artifact() {
8884
local tmp_file
8985
tmp_file="$(mktemp)"
9086

91-
curl -fsSL "$(get_artifact_url "$artifact_name")" >"$tmp_file"
87+
gh api "$(get_artifact_url "$artifact_name")" >"$tmp_file"
9288
unzip -q -o "$tmp_file" -d "$dst"
9389
rm "$tmp_file"
9490
}

0 commit comments

Comments
 (0)