Skip to content

Commit aa4e7a4

Browse files
authored
chore: Added Actions-based release workflow (#331)
* chore: Added Actions-based release workflow * Set GOPATH * Fixed working directory for tests * Decrypting credentials into the testdata directory * Added preflight and post check scripts
1 parent 43c7e77 commit aa4e7a4

File tree

8 files changed

+445
-1
lines changed

8 files changed

+445
-1
lines changed
1.69 KB
Binary file not shown.

.github/scripts/generate_changelog.sh

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

.github/scripts/publish_post_check.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
#!/bin/bash
3+
4+
# Copyright 2020 Google Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
19+
###################################### Outputs #####################################
20+
21+
# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3).
22+
# 2. changelog: Formatted changelog text for this release.
23+
24+
####################################################################################
25+
26+
set -e
27+
set -u
28+
29+
function echo_info() {
30+
local MESSAGE=$1
31+
echo "[INFO] ${MESSAGE}"
32+
}
33+
34+
function echo_warn() {
35+
local MESSAGE=$1
36+
echo "[WARN] ${MESSAGE}"
37+
}
38+
39+
function terminate() {
40+
echo ""
41+
echo_warn "--------------------------------------------"
42+
echo_warn "POST CHECK FAILED"
43+
echo_warn "--------------------------------------------"
44+
exit 1
45+
}
46+
47+
48+
echo_info "Starting publish post check..."
49+
echo_info "Git revision : ${GITHUB_SHA}"
50+
echo_info "Git ref : ${GITHUB_REF}"
51+
echo_info "Workflow triggered by : ${GITHUB_ACTOR}"
52+
echo_info "GitHub event : ${GITHUB_EVENT_NAME}"
53+
54+
55+
echo_info ""
56+
echo_info "--------------------------------------------"
57+
echo_info "Extracting release version"
58+
echo_info "--------------------------------------------"
59+
echo_info ""
60+
61+
echo_info "Loading version from: firebase.go"
62+
63+
readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true
64+
if [[ -z "${RELEASE_VERSION}" ]]; then
65+
echo_warn "Failed to extract release version from: firebase.go"
66+
terminate
67+
fi
68+
69+
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
70+
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting."
71+
terminate
72+
fi
73+
74+
echo_info "Extracted release version: ${RELEASE_VERSION}"
75+
echo "::set-output name=version::v${RELEASE_VERSION}"
76+
77+
78+
echo_info ""
79+
echo_info "--------------------------------------------"
80+
echo_info "Generating changelog"
81+
echo_info "--------------------------------------------"
82+
echo_info ""
83+
84+
echo_info "---< git fetch origin master --prune --unshallow >---"
85+
git fetch origin master --prune --unshallow
86+
echo ""
87+
88+
echo_info "Generating changelog from history..."
89+
readonly CURRENT_DIR=$(dirname "$0")
90+
readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh`
91+
echo "$CHANGELOG"
92+
93+
# Parse and preformat the text to handle multi-line output.
94+
# See https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870
95+
FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"`
96+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}"
97+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}"
98+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}"
99+
echo "::set-output name=changelog::${FILTERED_CHANGELOG}"
100+
101+
102+
echo ""
103+
echo_info "--------------------------------------------"
104+
echo_info "POST CHECK SUCCESSFUL"
105+
echo_info "--------------------------------------------"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
18+
set -e
19+
set -u
20+
21+
function echo_info() {
22+
local MESSAGE=$1
23+
echo "[INFO] ${MESSAGE}"
24+
}
25+
26+
function echo_warn() {
27+
local MESSAGE=$1
28+
echo "[WARN] ${MESSAGE}"
29+
}
30+
31+
function terminate() {
32+
echo ""
33+
echo_warn "--------------------------------------------"
34+
echo_warn "PREFLIGHT FAILED"
35+
echo_warn "--------------------------------------------"
36+
exit 1
37+
}
38+
39+
40+
echo_info "Starting publish preflight check..."
41+
echo_info "Git revision : ${GITHUB_SHA}"
42+
echo_info "Git ref : ${GITHUB_REF}"
43+
echo_info "Workflow triggered by : ${GITHUB_ACTOR}"
44+
echo_info "GitHub event : ${GITHUB_EVENT_NAME}"
45+
46+
47+
echo_info ""
48+
echo_info "--------------------------------------------"
49+
echo_info "Extracting release version"
50+
echo_info "--------------------------------------------"
51+
echo_info ""
52+
53+
echo_info "Loading version from: firebase.go"
54+
55+
readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true
56+
if [[ -z "${RELEASE_VERSION}" ]]; then
57+
echo_warn "Failed to extract release version from: firebase.go"
58+
terminate
59+
fi
60+
61+
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
62+
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting."
63+
terminate
64+
fi
65+
66+
echo_info "Extracted release version: ${RELEASE_VERSION}"
67+
68+
69+
echo_info ""
70+
echo_info "--------------------------------------------"
71+
echo_info "Checking release tag"
72+
echo_info "--------------------------------------------"
73+
echo_info ""
74+
75+
echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---"
76+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
77+
echo ""
78+
79+
readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true
80+
if [[ -n "${EXISTING_TAG}" ]]; then
81+
echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting."
82+
echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again."
83+
echo_warn " $ git tag -d v${RELEASE_VERSION}"
84+
echo_warn " $ git push --delete origin v${RELEASE_VERSION}"
85+
86+
readonly RELEASE_URL="https://github.com/firebase/firebase-admin-go/releases/tag/v${RELEASE_VERSION}"
87+
echo_warn "Delete any corresponding releases at ${RELEASE_URL}."
88+
terminate
89+
fi
90+
91+
echo_info "Tag v${RELEASE_VERSION} does not exist."
92+
93+
94+
echo ""
95+
echo_info "--------------------------------------------"
96+
echo_info "PREFLIGHT SUCCESSFUL"
97+
echo_info "--------------------------------------------"

.github/scripts/run_all_tests.sh

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 testdata/integration_cert.json .github/resources/integ-service-account.json.gpg
22+
23+
echo "${FIREBASE_API_KEY}" > testdata/integration_apikey.txt
24+
25+
go test -v -race firebase.google.com/go/...

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Continuous Integration
2-
on: [push, pull_request]
2+
on: push
33
jobs:
44

55
build:

.github/workflows/publish.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2020 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Publish Release
16+
17+
on:
18+
# Only run the workflow when a PR is merged to the master branch.
19+
pull_request:
20+
branches: master
21+
types: closed
22+
23+
jobs:
24+
publish_release:
25+
if: github.event.pull_request.merged
26+
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout source
31+
uses: actions/checkout@v2
32+
33+
- name: Publish post check
34+
id: postcheck
35+
run: ./.github/scripts/publish_post_check.sh
36+
37+
# We pull this action from a custom fork of a contributor until
38+
# https://github.com/actions/create-release/pull/32 is merged. Also note that v1 of
39+
# this action does not support the "body" parameter.
40+
- name: Create release tag
41+
uses: fleskesvor/create-release@1a72e235c178bf2ae6c51a8ae36febc24568c5fe
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
with:
45+
tag_name: ${{ steps.postcheck.outputs.version }}
46+
release_name: Firebase Admin Go SDK ${{ steps.postcheck.outputs.version }}
47+
body: ${{ steps.postcheck.outputs.changelog }}
48+
draft: false
49+
prerelease: false
50+
51+
# Post to Twitter if explicitly opted-in by adding the label 'release:tweet'.
52+
- name: Post to Twitter
53+
if: success() &&
54+
contains(github.event.pull_request.labels.*.name, 'release:tweet')
55+
uses: firebase/firebase-admin-node/.github/actions/send-tweet@master
56+
with:
57+
status: >
58+
${{ steps.postcheck.outputs.version }} of @Firebase Admin Go SDK is avaialble.
59+
https://github.com/firebase/firebase-admin-go/releases/tag/${{ steps.postcheck.outputs.version }}
60+
consumer-key: ${{ secrets.FIREBASE_TWITTER_CONSUMER_KEY }}
61+
consumer-secret: ${{ secrets.FIREBASE_TWITTER_CONSUMER_SECRET }}
62+
access-token: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN }}
63+
access-token-secret: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN_SECRET }}
64+
continue-on-error: true

0 commit comments

Comments
 (0)