Skip to content

Commit 8e9e67a

Browse files
committed
wip
1 parent 30a39fa commit 8e9e67a

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

ci/lib.sh

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,50 @@ arch() {
4949
esac
5050
}
5151

52+
# A helper function to get the artifacts url
53+
# Takes 1 argument:
54+
# $1 = environment {string} "staging" | "development" | "production" - which environment this is called in
55+
# Notes:
5256
# Grabs the most recent ci.yaml github workflow run that was triggered from the
5357
# pull request of the release branch for this version (regardless of whether
5458
# that run succeeded or failed). The release branch name must be in semver
5559
# format with a v prepended.
5660
# This will contain the artifacts we want.
5761
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
5862
get_artifacts_url() {
63+
local environment="$1"
5964
local artifacts_url
60-
local version_branch="v$VERSION"
65+
66+
case $environment in
67+
production)
68+
# This assumes you're releasing code-server using a branch named `v$VERSION` i.e. `v4.0.1`
69+
# If you don't, this will fail.
70+
local branch="v$VERSION"
71+
local event="pull_request"
72+
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=$event&branch=$branch"
73+
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$branch\") | .artifacts_url" | head -n 1)
74+
;;
75+
staging)
76+
local branch="main"
77+
local event="push"
78+
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=$event&branch=$branch"
79+
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$branch\") | .artifacts_url" | head -n 1)
80+
;;
81+
development)
82+
# TODO@jsjoeio how do we get the branch name here? probably need to pass in from caller
83+
local branch="????"
84+
local event="pull_request"
85+
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=$event&branch=$branch"
86+
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
87+
;;
88+
*)
89+
echo -n "unknown"
90+
;;
91+
esac
92+
6193
local workflow_runs_url="repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=pull_request&branch=$version_branch"
6294
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
95+
6396
if [[ -z "$artifacts_url" ]]; then
6497
echo >&2 "ERROR: artifacts_url came back empty"
6598
echo >&2 "We looked for a successful run triggered by a pull_request with for code-server version: $VERSION and a branch named $version_branch"
@@ -70,22 +103,31 @@ get_artifacts_url() {
70103
echo "$artifacts_url"
71104
}
72105

73-
# Grabs the artifact's download url.
74-
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
106+
# A helper function to grab the artifact's download url
107+
# Takes 2 arguments:
108+
# $1 = artifact_name {string} - the name of the artifact to download (i.e. "npm-package")
109+
# $2 = environment {string} "staging" | "development" | "production" - which environment this is called in
110+
# See: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
75111
get_artifact_url() {
76112
local artifact_name="$1"
77-
gh api "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
113+
local environment="$2"
114+
gh api "$(get_artifacts_url "$environment")" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
78115
}
79116

80-
# Uses the above two functions to download a artifact into a directory.
117+
# A helper function to download the an artifact into a directory
118+
# Takes 3 arguments:
119+
# $1 = artifact_name {string} - the name of the artifact to download (i.e. "npm-package")
120+
# $2 = destination {string} - where to download the artifact
121+
# $3 = environment {string} "staging" | "development" | "production" - which environment this is called in
81122
download_artifact() {
82123
local artifact_name="$1"
83124
local dst="$2"
125+
local environment="$3"
84126

85127
local tmp_file
86128
tmp_file="$(mktemp)"
87129

88-
gh api "$(get_artifact_url "$artifact_name")" > "$tmp_file"
130+
gh api "$(get_artifact_url "$artifact_name" "$environment")" > "$tmp_file"
89131
unzip -q -o "$tmp_file" -d "$dst"
90132
rm "$tmp_file"
91133
}

0 commit comments

Comments
 (0)