@@ -49,17 +49,50 @@ arch() {
49
49
esac
50
50
}
51
51
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:
52
56
# Grabs the most recent ci.yaml github workflow run that was triggered from the
53
57
# pull request of the release branch for this version (regardless of whether
54
58
# that run succeeded or failed). The release branch name must be in semver
55
59
# format with a v prepended.
56
60
# This will contain the artifacts we want.
57
61
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
58
62
get_artifacts_url () {
63
+ local environment=" $1 "
59
64
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
+
61
93
local workflow_runs_url=" repos/:owner/:repo/actions/workflows/ci.yaml/runs?event=pull_request&branch=$version_branch "
62
94
artifacts_url=$( gh api " $workflow_runs_url " | jq -r " .workflow_runs[] | select(.head_branch == \" $version_branch \" ) | .artifacts_url" | head -n 1)
95
+
63
96
if [[ -z " $artifacts_url " ]]; then
64
97
echo >&2 " ERROR: artifacts_url came back empty"
65
98
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() {
70
103
echo " $artifacts_url "
71
104
}
72
105
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
75
111
get_artifact_url () {
76
112
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
78
115
}
79
116
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
81
122
download_artifact () {
82
123
local artifact_name=" $1 "
83
124
local dst=" $2 "
125
+ local environment=" $3 "
84
126
85
127
local tmp_file
86
128
tmp_file=" $( mktemp) "
87
129
88
- gh api " $( get_artifact_url " $artifact_name " ) " > " $tmp_file "
130
+ gh api " $( get_artifact_url " $artifact_name " " $environment " ) " > " $tmp_file "
89
131
unzip -q -o " $tmp_file " -d " $dst "
90
132
rm " $tmp_file "
91
133
}
0 commit comments