Skip to content

Commit 5abaab6

Browse files
authored
chore: Experimental release flow based on Actions (#780)
* chore: Experimental release flow based on Actions * Added tarball verification step; Simplified CI trigger * Splitting staging and publish phases into separate jobs * Fleshed out the full workflow * Trigger RC build
1 parent e57c262 commit 5abaab6

7 files changed

+438
-3
lines changed
1.69 KB
Binary file not shown.

.github/scripts/generate_changelog.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -u
5+
6+
function printChangelog() {
7+
local TITLE=$1
8+
shift
9+
# Skip the sentinel value.
10+
local ENTRIES=("${@:2}")
11+
if [ ${#ENTRIES[@]} -ne 0 ]; then
12+
echo "### ${TITLE}"
13+
echo ""
14+
for ((i = 0; i < ${#ENTRIES[@]}; i++))
15+
do
16+
echo "* ${ENTRIES[$i]}"
17+
done
18+
echo ""
19+
fi
20+
}
21+
22+
if [[ -z "${GITHUB_SHA}" ]]; then
23+
GITHUB_SHA="HEAD"
24+
fi
25+
26+
LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1) 2> /dev/null` || true
27+
if [[ -z "${LAST_TAG}" ]]; then
28+
echo "[INFO] No tags found. Including all commits up to ${GITHUB_SHA}."
29+
VERSION_RANGE="${GITHUB_SHA}"
30+
else
31+
echo "[INFO] Last release tag: ${LAST_TAG}."
32+
COMMIT_SHA=`git show-ref -s ${LAST_TAG}`
33+
echo "[INFO] Last release commit: ${COMMIT_SHA}."
34+
VERSION_RANGE="${COMMIT_SHA}..${GITHUB_SHA}"
35+
echo "[INFO] Including all commits in the range ${VERSION_RANGE}."
36+
fi
37+
38+
echo ""
39+
40+
# Older versions of Bash (< 4.4) treat empty arrays as unbound variables, which triggers
41+
# errors when referencing them. Therefore we initialize each of these arrays with an empty
42+
# sentinel value, and later skip them.
43+
CHANGES=("")
44+
FIXES=("")
45+
FEATS=("")
46+
MISC=("")
47+
48+
while read -r line
49+
do
50+
COMMIT_MSG=`echo ${line} | cut -d ' ' -f 2-`
51+
if [[ $COMMIT_MSG =~ ^change(\(.*\))?: ]]; then
52+
CHANGES+=("$COMMIT_MSG")
53+
elif [[ $COMMIT_MSG =~ ^fix(\(.*\))?: ]]; then
54+
FIXES+=("$COMMIT_MSG")
55+
elif [[ $COMMIT_MSG =~ ^feat(\(.*\))?: ]]; then
56+
FEATS+=("$COMMIT_MSG")
57+
else
58+
MISC+=("${COMMIT_MSG}")
59+
fi
60+
done < <(git log ${VERSION_RANGE} --oneline)
61+
62+
printChangelog "Breaking Changes" "${CHANGES[@]}"
63+
printChangelog "New Features" "${FEATS[@]}"
64+
printChangelog "Bug Fixes" "${FIXES[@]}"
65+
printChangelog "Miscellaneous" "${MISC[@]}"

.github/scripts/publish_package.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
set -u
19+
20+
echo "//wombat-dressing-room.appspot.com/:_authToken=${NPM_AUTH_TOKEN}" >> ~/.npmrc
21+
22+
readonly UNPREFIXED_VERSION=`echo ${VERSION} | cut -c 2-`
23+
npm publish dist/firebase-admin-${UNPREFIXED_VERSION}.tgz --registry https://wombat-dressing-room.appspot.com
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
###################################### Outputs #####################################
18+
19+
# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3).
20+
# 2. changelog: Formatted changelog text for this release.
21+
22+
####################################################################################
23+
24+
set -e
25+
set -u
26+
27+
function echo_info() {
28+
local MESSAGE=$1
29+
echo "[INFO] ${MESSAGE}"
30+
}
31+
32+
function echo_warn() {
33+
local MESSAGE=$1
34+
echo "[WARN] ${MESSAGE}"
35+
}
36+
37+
function terminate() {
38+
echo ""
39+
echo_warn "--------------------------------------------"
40+
echo_warn "PREFLIGHT FAILED"
41+
echo_warn "--------------------------------------------"
42+
exit 1
43+
}
44+
45+
46+
echo_info "Starting publish preflight check..."
47+
echo_info "Git revision : ${GITHUB_SHA}"
48+
echo_info "Workflow triggered by : ${GITHUB_ACTOR}"
49+
echo_info "GitHub event : ${GITHUB_EVENT_NAME}"
50+
51+
52+
echo_info ""
53+
echo_info "--------------------------------------------"
54+
echo_info "Extracting release version"
55+
echo_info "--------------------------------------------"
56+
echo_info ""
57+
58+
echo_info "Loading version from: package.json"
59+
60+
readonly VERSION_SCRIPT="const pkg = require('./package.json'); console.log(pkg.version);"
61+
readonly RELEASE_VERSION=`node -e "${VERSION_SCRIPT}"` || true
62+
if [[ -z "${RELEASE_VERSION}" ]]; then
63+
echo_warn "Failed to extract release version from: package.json"
64+
terminate
65+
fi
66+
67+
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
68+
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting."
69+
terminate
70+
fi
71+
72+
echo_info "Extracted release version: ${RELEASE_VERSION}"
73+
echo "::set-output name=version::v${RELEASE_VERSION}"
74+
75+
76+
echo_info ""
77+
echo_info "--------------------------------------------"
78+
echo_info "Check release artifacts"
79+
echo_info "--------------------------------------------"
80+
echo_info ""
81+
82+
if [[ ! -d dist ]]; then
83+
echo_warn "dist directory does not exist."
84+
terminate
85+
fi
86+
87+
readonly RELEASE_ARTIFACT="dist/firebase-admin-${RELEASE_VERSION}.tgz"
88+
if [[ -f "${RELEASE_ARTIFACT}" ]]; then
89+
echo_info "Found release artifact: ${RELEASE_ARTIFACT}"
90+
else
91+
echo_warn "Release artifact ${RELEASE_ARTIFACT} not found."
92+
terminate
93+
fi
94+
95+
readonly ARTIFACT_COUNT=`ls dist/ | wc -l`
96+
if [[ $ARTIFACT_COUNT -ne 1 ]]; then
97+
echo_warn "Unexpected artifacts in the distribution directory."
98+
ls -l dist
99+
terminate
100+
fi
101+
102+
103+
echo_info ""
104+
echo_info "--------------------------------------------"
105+
echo_info "Checking previous releases"
106+
echo_info "--------------------------------------------"
107+
echo_info ""
108+
109+
readonly NPM_DIST_TARBALL=`npm show firebase-admin@${RELEASE_VERSION} dist.tarball`
110+
if [[ -n "${NPM_DIST_TARBALL}" ]]; then
111+
echo_warn "Release version ${RELEASE_VERSION} already present in NPM."
112+
terminate
113+
else
114+
echo_info "Release version ${RELEASE_VERSION} not found in NPM."
115+
fi
116+
117+
118+
echo_info ""
119+
echo_info "--------------------------------------------"
120+
echo_info "Checking release tag"
121+
echo_info "--------------------------------------------"
122+
echo_info ""
123+
124+
echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---"
125+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
126+
echo ""
127+
128+
readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true
129+
if [[ -n "${EXISTING_TAG}" ]]; then
130+
echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting."
131+
echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again."
132+
echo_warn " $ git tag -d v${RELEASE_VERSION}"
133+
echo_warn " $ git push --delete origin v${RELEASE_VERSION}"
134+
135+
readonly RELEASE_URL="https://github.com/firebase/firebase-admin-node/releases/tag/v${RELEASE_VERSION}"
136+
echo_warn "Delete any corresponding releases at ${RELEASE_URL}."
137+
terminate
138+
fi
139+
140+
echo_info "Tag v${RELEASE_VERSION} does not exist."
141+
142+
143+
echo_info ""
144+
echo_info "--------------------------------------------"
145+
echo_info "Generating changelog"
146+
echo_info "--------------------------------------------"
147+
echo_info ""
148+
149+
echo_info "---< git fetch origin master --prune --unshallow >---"
150+
git fetch origin master --prune --unshallow
151+
echo ""
152+
153+
echo_info "Generating changelog from history..."
154+
readonly CURRENT_DIR=$(dirname "$0")
155+
readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh`
156+
echo "$CHANGELOG"
157+
158+
# Parse and preformat the text to handle multi-line output.
159+
# See https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870
160+
FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"` || true
161+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}"
162+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}"
163+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}"
164+
echo "::set-output name=changelog::${FILTERED_CHANGELOG}"
165+
166+
167+
echo ""
168+
echo_info "--------------------------------------------"
169+
echo_info "PREFLIGHT SUCCESSFUL"
170+
echo_info "--------------------------------------------"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
set -u
19+
20+
gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}" \
21+
--output test/resources/key.json .github/resources/integ-service-account.json.gpg
22+
23+
echo "${FIREBASE_API_KEY}" > test/resources/apikey.txt
24+
25+
npm run test:integration -- --updateRules --testMultiTenancy

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Continuous Integration
22

3-
on: [push, pull_request]
3+
on: push
44

55
jobs:
66
build:
@@ -22,5 +22,3 @@ jobs:
2222
npm ci
2323
npm run build
2424
npm test
25-
env:
26-
CI: true

0 commit comments

Comments
 (0)