Skip to content

Commit c40a69d

Browse files
authored
chore: Implementing GitHub Actions release workflow (#363)
* Adding release workflow preliminaries * Fixed a syntax error * Uploading only the jar artifacts * Enabling integration tests * Using Maven lifecycle more effectively * Fixing indentation * Maven deployment configuration * Point the send tweet action to master * Setting all publish config as env variables * Fixed typo in tweet
1 parent c9648cf commit c40a69d

File tree

10 files changed

+532
-65
lines changed

10 files changed

+532
-65
lines changed

.github/resources/firebase.asc.gpg

3.96 KB
Binary file not shown.
1.69 KB
Binary file not shown.

.github/resources/settings.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<interactiveMode>false</interactiveMode>
7+
8+
<servers>
9+
<server>
10+
<id>ossrh</id>
11+
<username>${env.NEXUS_OSSRH_USERNAME}</username>
12+
<password>${env.NEXUS_OSSRH_PASSWORD}</password>
13+
</server>
14+
</servers>
15+
16+
<profiles>
17+
<profile>
18+
<id>release</id>
19+
<activation>
20+
<activeByDefault>true</activeByDefault>
21+
</activation>
22+
<properties>
23+
<gpg.executable>gpg</gpg.executable>
24+
<gpg.keyname>B652FFD3865AF7A75830876F5F55C8F6985BB9DD</gpg.keyname>
25+
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
26+
</properties>
27+
</profile>
28+
</profiles>
29+
</settings>

.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/package_artifacts.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 integration_cert.json .github/resources/integ-service-account.json.gpg
22+
23+
echo "${FIREBASE_API_KEY}" > integration_apikey.txt
24+
25+
# Does the following:
26+
# 1. Runs the Checkstyle plugin (validate phase)
27+
# 2. Compiles the source (compile phase)
28+
# 3. Runs the unit tests (test phase)
29+
# 4. Packages the artifacts - src, bin, javadocs (package phase)
30+
# 5. Runs the integration tests (verify phase)
31+
mvn -B clean verify
32+
33+
# Maven target directory can consist of many files. Just copy the jar artifacts
34+
# into a new directory for upload.
35+
mkdir -p dist
36+
cp target/*.jar dist/

.github/scripts/publish_artifacts.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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="${GPG_PRIVATE_KEY}" \
21+
--output firebase.asc .github/resources/firebase.asc.gpg
22+
23+
gpg --import firebase.asc
24+
25+
# Does the following:
26+
# 1. Compiles the source (compile phase)
27+
# 2. Packages the artifacts - src, bin, javadocs (package phase)
28+
# 3. Signs the artifacts (verify phase)
29+
# 4. Publishes artifacts via Nexus (deploy phase)
30+
mvn -B clean deploy \
31+
-Dcheckstyle.skip \
32+
-DskipTests \
33+
-Prelease \
34+
--settings .github/resources/settings.xml
35+
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
###################################### Outputs #####################################
19+
20+
# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3).
21+
# 2. changelog: Formatted changelog text for this release.
22+
23+
####################################################################################
24+
25+
set -e
26+
set -u
27+
28+
function echo_info() {
29+
local MESSAGE=$1
30+
echo "[INFO] ${MESSAGE}"
31+
}
32+
33+
function echo_warn() {
34+
local MESSAGE=$1
35+
echo "[WARN] ${MESSAGE}"
36+
}
37+
38+
function terminate() {
39+
echo ""
40+
echo_warn "--------------------------------------------"
41+
echo_warn "PREFLIGHT FAILED"
42+
echo_warn "--------------------------------------------"
43+
exit 1
44+
}
45+
46+
47+
echo_info "Starting publish preflight check..."
48+
echo_info "Git revision : ${GITHUB_SHA}"
49+
echo_info "Workflow triggered by : ${GITHUB_ACTOR}"
50+
echo_info "GitHub event : ${GITHUB_EVENT_NAME}"
51+
52+
53+
echo_info ""
54+
echo_info "--------------------------------------------"
55+
echo_info "Extracting release version"
56+
echo_info "--------------------------------------------"
57+
echo_info ""
58+
59+
echo_info "Loading version from: pom.xml"
60+
readonly RELEASE_VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` || true
61+
if [[ -z "${RELEASE_VERSION}" ]]; then
62+
echo_warn "Failed to extract release version from: pom.xml"
63+
terminate
64+
fi
65+
66+
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
67+
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting."
68+
terminate
69+
fi
70+
71+
echo_info "Extracted release version: ${RELEASE_VERSION}"
72+
echo "::set-output name=version::v${RELEASE_VERSION}"
73+
74+
75+
echo_info ""
76+
echo_info "--------------------------------------------"
77+
echo_info "Checking previous releases"
78+
echo_info "--------------------------------------------"
79+
echo_info ""
80+
81+
readonly MAVEN_CENTRAL_URL="https://repo1.maven.org/maven2/com/google/firebase/firebase-admin/${RELEASE_VERSION}"
82+
readonly MAVEN_STATUS=`curl -s -o /dev/null -L -w "%{http_code}" ${MAVEN_CENTRAL_URL}`
83+
if [[ $MAVEN_STATUS -eq 404 ]]; then
84+
echo_info "Release version ${RELEASE_VERSION} not found in Maven Central."
85+
elif [[ $MAVEN_STATUS -eq 200 ]]; then
86+
echo_warn "Release version ${RELEASE_VERSION} already present in Maven Central."
87+
terminate
88+
else
89+
echo_warn "Unexpected ${MAVEN_STATUS} response from Maven Central. Exiting."
90+
terminate
91+
fi
92+
93+
94+
echo_info ""
95+
echo_info "--------------------------------------------"
96+
echo_info "Checking release tag"
97+
echo_info "--------------------------------------------"
98+
echo_info ""
99+
100+
echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---"
101+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
102+
echo ""
103+
104+
readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true
105+
if [[ -n "${EXISTING_TAG}" ]]; then
106+
echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting."
107+
echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again."
108+
echo_warn " $ git tag -d v${RELEASE_VERSION}"
109+
echo_warn " $ git push --delete origin v${RELEASE_VERSION}"
110+
111+
readonly RELEASE_URL="https://github.com/firebase/firebase-admin-java/releases/tag/v${RELEASE_VERSION}"
112+
echo_warn "Delete any corresponding releases at ${RELEASE_URL}."
113+
terminate
114+
fi
115+
116+
echo_info "Tag v${RELEASE_VERSION} does not exist."
117+
118+
119+
echo_info ""
120+
echo_info "--------------------------------------------"
121+
echo_info "Generating changelog"
122+
echo_info "--------------------------------------------"
123+
echo_info ""
124+
125+
echo_info "---< git fetch origin master --prune --unshallow >---"
126+
git fetch origin master --prune --unshallow
127+
echo ""
128+
129+
echo_info "Generating changelog from history..."
130+
readonly CURRENT_DIR=$(dirname "$0")
131+
readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh`
132+
echo "$CHANGELOG"
133+
134+
# Parse and preformat the text to handle multi-line output.
135+
# See https://i.8713187.xyzmunity/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870
136+
FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"`
137+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}"
138+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}"
139+
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}"
140+
echo "::set-output name=changelog::${FILTERED_CHANGELOG}"
141+
142+
143+
echo ""
144+
echo_info "--------------------------------------------"
145+
echo_info "PREFLIGHT SUCCESSFUL"
146+
echo_info "--------------------------------------------"

.github/workflows/ci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
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.
114
name: Continuous Integration
215

3-
on: [push, pull_request]
16+
on: push
417

518
jobs:
619
build:
720
runs-on: ubuntu-latest
21+
822
steps:
923
- uses: actions/checkout@v1
24+
1025
- name: Set up JDK 1.7
1126
uses: actions/setup-java@v1
1227
with:
1328
java-version: 1.7
29+
30+
# Does the following:
31+
# 1. Runs the Checkstyle plugin (validate phase)
32+
# 2. Compiles the source (compile phase)
33+
# 3. Runs the unit tests (test phase)
1434
- name: Build with Maven
15-
run: mvn -B package --file pom.xml
35+
run: mvn -B clean test

0 commit comments

Comments
 (0)