-
Notifications
You must be signed in to change notification settings - Fork 264
chore: Added Actions-based release workflow #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
474ed04
chore: Added Actions-based release workflow
hiranya911 ff6e97c
Set GOPATH
hiranya911 041beea
Fixed working directory for tests
hiranya911 1c86dde
Decrypting credentials into the testdata directory
hiranya911 f71f1cb
Added preflight and post check scripts
hiranya911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e | ||
set -u | ||
|
||
function printChangelog() { | ||
local TITLE=$1 | ||
shift | ||
# Skip the sentinel value. | ||
local ENTRIES=("${@:2}") | ||
if [ ${#ENTRIES[@]} -ne 0 ]; then | ||
echo "### ${TITLE}" | ||
echo "" | ||
for ((i = 0; i < ${#ENTRIES[@]}; i++)) | ||
do | ||
echo "* ${ENTRIES[$i]}" | ||
done | ||
echo "" | ||
fi | ||
} | ||
|
||
if [[ -z "${GITHUB_SHA}" ]]; then | ||
GITHUB_SHA="HEAD" | ||
fi | ||
|
||
LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1) 2> /dev/null` || true | ||
if [[ -z "${LAST_TAG}" ]]; then | ||
echo "[INFO] No tags found. Including all commits up to ${GITHUB_SHA}." | ||
VERSION_RANGE="${GITHUB_SHA}" | ||
else | ||
echo "[INFO] Last release tag: ${LAST_TAG}." | ||
COMMIT_SHA=`git show-ref -s ${LAST_TAG}` | ||
echo "[INFO] Last release commit: ${COMMIT_SHA}." | ||
VERSION_RANGE="${COMMIT_SHA}..${GITHUB_SHA}" | ||
echo "[INFO] Including all commits in the range ${VERSION_RANGE}." | ||
fi | ||
|
||
echo "" | ||
|
||
# Older versions of Bash (< 4.4) treat empty arrays as unbound variables, which triggers | ||
# errors when referencing them. Therefore we initialize each of these arrays with an empty | ||
# sentinel value, and later skip them. | ||
CHANGES=("") | ||
FIXES=("") | ||
FEATS=("") | ||
MISC=("") | ||
|
||
while read -r line | ||
do | ||
COMMIT_MSG=`echo ${line} | cut -d ' ' -f 2-` | ||
if [[ $COMMIT_MSG =~ ^change(\(.*\))?: ]]; then | ||
CHANGES+=("$COMMIT_MSG") | ||
elif [[ $COMMIT_MSG =~ ^fix(\(.*\))?: ]]; then | ||
FIXES+=("$COMMIT_MSG") | ||
elif [[ $COMMIT_MSG =~ ^feat(\(.*\))?: ]]; then | ||
FEATS+=("$COMMIT_MSG") | ||
else | ||
MISC+=("${COMMIT_MSG}") | ||
fi | ||
done < <(git log ${VERSION_RANGE} --oneline) | ||
|
||
printChangelog "Breaking Changes" "${CHANGES[@]}" | ||
printChangelog "New Features" "${FEATS[@]}" | ||
printChangelog "Bug Fixes" "${FIXES[@]}" | ||
printChangelog "Miscellaneous" "${MISC[@]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
###################################### Outputs ##################################### | ||
|
||
# 1. version: The version of this release including the 'v' prefix (e.g. v1.2.3). | ||
# 2. changelog: Formatted changelog text for this release. | ||
|
||
#################################################################################### | ||
|
||
set -e | ||
set -u | ||
|
||
function echo_info() { | ||
local MESSAGE=$1 | ||
echo "[INFO] ${MESSAGE}" | ||
} | ||
|
||
function echo_warn() { | ||
local MESSAGE=$1 | ||
echo "[WARN] ${MESSAGE}" | ||
} | ||
|
||
function terminate() { | ||
echo "" | ||
echo_warn "--------------------------------------------" | ||
echo_warn "POST CHECK FAILED" | ||
echo_warn "--------------------------------------------" | ||
exit 1 | ||
} | ||
|
||
|
||
echo_info "Starting publish post check..." | ||
echo_info "Git revision : ${GITHUB_SHA}" | ||
echo_info "Git ref : ${GITHUB_REF}" | ||
echo_info "Workflow triggered by : ${GITHUB_ACTOR}" | ||
echo_info "GitHub event : ${GITHUB_EVENT_NAME}" | ||
|
||
|
||
echo_info "" | ||
echo_info "--------------------------------------------" | ||
echo_info "Extracting release version" | ||
echo_info "--------------------------------------------" | ||
echo_info "" | ||
|
||
echo_info "Loading version from: firebase.go" | ||
|
||
readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true | ||
if [[ -z "${RELEASE_VERSION}" ]]; then | ||
echo_warn "Failed to extract release version from: firebase.go" | ||
terminate | ||
fi | ||
|
||
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then | ||
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." | ||
terminate | ||
fi | ||
|
||
echo_info "Extracted release version: ${RELEASE_VERSION}" | ||
echo "::set-output name=version::v${RELEASE_VERSION}" | ||
|
||
|
||
echo_info "" | ||
echo_info "--------------------------------------------" | ||
echo_info "Generating changelog" | ||
echo_info "--------------------------------------------" | ||
echo_info "" | ||
|
||
echo_info "---< git fetch origin master --prune --unshallow >---" | ||
git fetch origin master --prune --unshallow | ||
echo "" | ||
|
||
echo_info "Generating changelog from history..." | ||
readonly CURRENT_DIR=$(dirname "$0") | ||
readonly CHANGELOG=`${CURRENT_DIR}/generate_changelog.sh` | ||
echo "$CHANGELOG" | ||
|
||
# Parse and preformat the text to handle multi-line output. | ||
# See https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870 | ||
FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"` | ||
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//'%'/'%25'}" | ||
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\n'/'%0A'}" | ||
FILTERED_CHANGELOG="${FILTERED_CHANGELOG//$'\r'/'%0D'}" | ||
echo "::set-output name=changelog::${FILTERED_CHANGELOG}" | ||
|
||
|
||
echo "" | ||
echo_info "--------------------------------------------" | ||
echo_info "POST CHECK SUCCESSFUL" | ||
echo_info "--------------------------------------------" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
set -e | ||
set -u | ||
|
||
function echo_info() { | ||
local MESSAGE=$1 | ||
echo "[INFO] ${MESSAGE}" | ||
} | ||
|
||
function echo_warn() { | ||
local MESSAGE=$1 | ||
echo "[WARN] ${MESSAGE}" | ||
} | ||
|
||
function terminate() { | ||
echo "" | ||
echo_warn "--------------------------------------------" | ||
echo_warn "PREFLIGHT FAILED" | ||
echo_warn "--------------------------------------------" | ||
exit 1 | ||
} | ||
|
||
|
||
echo_info "Starting publish preflight check..." | ||
echo_info "Git revision : ${GITHUB_SHA}" | ||
echo_info "Git ref : ${GITHUB_REF}" | ||
echo_info "Workflow triggered by : ${GITHUB_ACTOR}" | ||
echo_info "GitHub event : ${GITHUB_EVENT_NAME}" | ||
|
||
|
||
echo_info "" | ||
echo_info "--------------------------------------------" | ||
echo_info "Extracting release version" | ||
echo_info "--------------------------------------------" | ||
echo_info "" | ||
|
||
echo_info "Loading version from: firebase.go" | ||
|
||
readonly RELEASE_VERSION=`grep "const Version" firebase.go | awk '{print $4}' | tr -d \"` || true | ||
if [[ -z "${RELEASE_VERSION}" ]]; then | ||
echo_warn "Failed to extract release version from: firebase.go" | ||
terminate | ||
fi | ||
|
||
if [[ ! "${RELEASE_VERSION}" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then | ||
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting." | ||
terminate | ||
fi | ||
|
||
echo_info "Extracted release version: ${RELEASE_VERSION}" | ||
|
||
|
||
echo_info "" | ||
echo_info "--------------------------------------------" | ||
echo_info "Checking release tag" | ||
echo_info "--------------------------------------------" | ||
echo_info "" | ||
|
||
echo_info "---< git fetch --depth=1 origin +refs/tags/*:refs/tags/* >---" | ||
git fetch --depth=1 origin +refs/tags/*:refs/tags/* | ||
echo "" | ||
|
||
readonly EXISTING_TAG=`git rev-parse -q --verify "refs/tags/v${RELEASE_VERSION}"` || true | ||
if [[ -n "${EXISTING_TAG}" ]]; then | ||
echo_warn "Tag v${RELEASE_VERSION} already exists. Exiting." | ||
echo_warn "If the tag was created in a previous unsuccessful attempt, delete it and try again." | ||
echo_warn " $ git tag -d v${RELEASE_VERSION}" | ||
echo_warn " $ git push --delete origin v${RELEASE_VERSION}" | ||
|
||
readonly RELEASE_URL="https://github.com/firebase/firebase-admin-go/releases/tag/v${RELEASE_VERSION}" | ||
echo_warn "Delete any corresponding releases at ${RELEASE_URL}." | ||
terminate | ||
fi | ||
|
||
echo_info "Tag v${RELEASE_VERSION} does not exist." | ||
|
||
|
||
echo "" | ||
echo_info "--------------------------------------------" | ||
echo_info "PREFLIGHT SUCCESSFUL" | ||
echo_info "--------------------------------------------" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e | ||
set -u | ||
|
||
gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}" \ | ||
--output testdata/integration_cert.json .github/resources/integ-service-account.json.gpg | ||
|
||
echo "${FIREBASE_API_KEY}" > testdata/integration_apikey.txt | ||
|
||
go test -v -race firebase.google.com/go/... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: Continuous Integration | ||
on: [push, pull_request] | ||
on: push | ||
jobs: | ||
|
||
build: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: Publish Release | ||
|
||
on: | ||
# Only run the workflow when a PR is merged to the master branch. | ||
pull_request: | ||
branches: master | ||
types: closed | ||
|
||
jobs: | ||
publish_release: | ||
if: github.event.pull_request.merged | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Publish post check | ||
id: postcheck | ||
run: ./.github/scripts/publish_post_check.sh | ||
|
||
# We pull this action from a custom fork of a contributor until | ||
# https://github.com/actions/create-release/pull/32 is merged. Also note that v1 of | ||
# this action does not support the "body" parameter. | ||
- name: Create release tag | ||
uses: fleskesvor/create-release@1a72e235c178bf2ae6c51a8ae36febc24568c5fe | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.postcheck.outputs.version }} | ||
release_name: Firebase Admin Go SDK ${{ steps.postcheck.outputs.version }} | ||
body: ${{ steps.postcheck.outputs.changelog }} | ||
draft: false | ||
prerelease: false | ||
|
||
# Post to Twitter if explicitly opted-in by adding the label 'release:tweet'. | ||
- name: Post to Twitter | ||
if: success() && | ||
contains(github.event.pull_request.labels.*.name, 'release:tweet') | ||
uses: firebase/firebase-admin-node/.github/actions/send-tweet@master | ||
with: | ||
status: > | ||
${{ steps.postcheck.outputs.version }} of @Firebase Admin Go SDK is avaialble. | ||
https://github.com/firebase/firebase-admin-go/releases/tag/${{ steps.postcheck.outputs.version }} | ||
consumer-key: ${{ secrets.FIREBASE_TWITTER_CONSUMER_KEY }} | ||
consumer-secret: ${{ secrets.FIREBASE_TWITTER_CONSUMER_SECRET }} | ||
access-token: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN }} | ||
access-token-secret: ${{ secrets.FIREBASE_TWITTER_ACCESS_TOKEN_SECRET }} | ||
continue-on-error: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we close a PR without merging would that also trigger this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but then will get immediately skipped because of: