Skip to content

[chore] Release 0.0.1rc0 #66

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 38 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2dfc848
Merge branch 'invertase-db-event-rename'
taeold Feb 1, 2023
b822a1c
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Feb 3, 2023
a38ca31
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Feb 7, 2023
2ec9ab8
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Feb 13, 2023
cbc9aad
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Feb 14, 2023
7cd59f7
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Feb 15, 2023
149d575
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Apr 17, 2023
7a7bd4f
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Apr 19, 2023
e334d11
Merge branch 'main' of https://github.com/firebase/firebase-functions…
taeold Apr 25, 2023
118df45
Fork firebase-admin python release scripts.
taeold Apr 25, 2023
6f6b7ac
Add release gh action.
taeold Apr 25, 2023
ed09ed7
Make linter happy.
taeold Apr 25, 2023
b928444
Use latest version of checkout.
taeold Apr 25, 2023
1f80deb
yaml does not like floating point numbers.
taeold Apr 25, 2023
b16be1e
Update release scripts.
taeold Apr 26, 2023
9b63e41
Fix formatting.
taeold Apr 26, 2023
b0224cd
Update releas script.
taeold Apr 26, 2023
8ccd424
Temporarily enable publish job for debugging.
taeold Apr 26, 2023
57da268
Actually enable publish job.
taeold Apr 26, 2023
f247921
Fix typo on preflight script.
taeold Apr 26, 2023
0a8bbdc
More fixes to the preflight script.
taeold Apr 26, 2023
8e2764d
Fix more things.
taeold Apr 26, 2023
714a992
migrate from deprecated set-output commands.
taeold Apr 26, 2023
a02738f
Fix another preflight script bug.
taeold Apr 26, 2023
8550fb8
Fix another preflight script bug.
taeold Apr 26, 2023
488625e
More diagnostics please.
taeold Apr 26, 2023
5f21c82
Remove git fetch instr.
taeold Apr 26, 2023
24c6750
Add long_description
taeold Apr 26, 2023
13a52ba
Use personal test account instead.
taeold Apr 26, 2023
40922e8
Fix formatting.
taeold Apr 26, 2023
acc68c0
Update action versions.
taeold Apr 26, 2023
9a90215
Fix issue with artifact download upgrade.
taeold Apr 26, 2023
aa76735
Fix typo on long description
taeold Apr 26, 2023
e924383
Test done. Bring back 'prod' release script.
taeold Apr 26, 2023
fb9eb29
Fixup changelog.
taeold Apr 26, 2023
0e46d86
Fix use of step output.
taeold Apr 26, 2023
cb3f34e
Fix multiline string step outputs.
taeold Apr 26, 2023
80ce781
Merge branch 'main' into dl-release-scripts
taeold Apr 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/scripts/generate_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Copyright 2023 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 =~ ^refactor(\(.*\))?: ]]; 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[@]}"
179 changes: 179 additions & 0 deletions .github/scripts/publish_preflight_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/bin/bash

# Copyright 2023 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 "PREFLIGHT FAILED"
echo_warn "--------------------------------------------"
exit 1
}


echo_info "Starting publish preflight check..."
echo_info "Git revision : ${GITHUB_SHA}"
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 ""

readonly INIT_FILE="src/firebase_functions/__init__.py"
echo_info "Loading version from: ${INIT_FILE}"

readonly RELEASE_VERSION=`grep "__version__" ${INIT_FILE} | awk '{print $3}' | tr -d \"` || true
if [[ -z "${RELEASE_VERSION}" ]]; then
echo_warn "Failed to extract release version from: ${INIT_FILE}"
terminate
fi

if [[ ! "${RELEASE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9]+)?$ ]]; then
echo_warn "Malformed release version string: ${RELEASE_VERSION}. Exiting."
terminate
fi

echo_info "Extracted release version: ${RELEASE_VERSION}"
echo "version=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT"


echo_info ""
echo_info "--------------------------------------------"
echo_info "Check release artifacts"
echo_info "--------------------------------------------"
echo_info ""

if [[ ! -d dist ]]; then
echo_warn "dist directory does not exist."
terminate
fi

readonly BIN_DIST="dist/firebase_functions-${RELEASE_VERSION}-py3-none-any.whl"
if [[ -f "${BIN_DIST}" ]]; then
echo_info "Found binary distribution (bdist_wheel): ${BIN_DIST}"
else
echo_warn "Binary distribution ${BIN_DIST} not found."
terminate
fi

readonly SRC_DIST="dist/firebase_functions-${RELEASE_VERSION}.tar.gz"
if [[ -f "${SRC_DIST}" ]]; then
echo_info "Found source distribution (sdist): ${SRC_DIST}"
else
echo_warn "Source distribution ${SRC_DIST} not found."
terminate
fi

readonly ARTIFACT_COUNT=`ls dist/ | wc -l`
if [[ $ARTIFACT_COUNT -ne 2 ]]; then
echo_warn "Unexpected artifacts in the distribution directory."
ls -l dist
terminate
fi


echo_info ""
echo_info "--------------------------------------------"
echo_info "Checking previous releases"
echo_info "--------------------------------------------"
echo_info ""

readonly PYPI_URL="https://pypi.org/pypi/firebase-functions/${RELEASE_VERSION}/json"
readonly PYPI_STATUS=`curl -s -o /dev/null -L -w "%{http_code}" ${PYPI_URL}`
if [[ $PYPI_STATUS -eq 404 ]]; then
echo_info "Release version ${RELEASE_VERSION} not found in Pypi."
elif [[ $PYPI_STATUS -eq 200 ]]; then
echo_warn "Release version ${RELEASE_VERSION} already present in Pypi."
terminate
else
echo_warn "Unexpected ${PYPI_STATUS} response from Pypi. Exiting."
terminate
fi


echo_info ""
echo_info "--------------------------------------------"
echo_info "Checking release tag"
echo_info "--------------------------------------------"
echo_info ""

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-functions-python/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_info ""
echo_info "--------------------------------------------"
echo_info "Generating changelog"
echo_info "--------------------------------------------"
echo_info ""

echo_info "---< git fetch origin main >---"
git fetch origin main
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.
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
FILTERED_CHANGELOG=`echo "$CHANGELOG" | grep -v "\\[INFO\\]"`
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "changelog=<<$EOF" >> "$GITHUB_OUTPUT"
echo $CHANGELOG >> "$GITHUB_OUTPUT"
echo $EOF >> "$GITHUG_OUTPUT"


echo ""
echo_info "--------------------------------------------"
echo_info "PREFLIGHT SUCCESSFUL"
echo_info "--------------------------------------------"
113 changes: 113 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2023 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: Release Candidate

on:
pull_request:
types: [opened, synchronize, closed]
# Allow workflow to be triggered manually.
workflow_dispatch:

jobs:
stage_release:
# To publish a release, merge the release PR with the label 'release:publish'.
# To stage a release without publishing it, manually invoke the workflow.
# . or apply the 'release:stage' label to a PR.
if: (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'release:publish')) ||
github.event.workflow_dispatch ||
contains(github.event.pull_request.labels.*.name, 'release:stage')

runs-on: ubuntu-latest

steps:
- name: Checkout source for staging
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
pip install --upgrade pip
python -m pip install -e ".[dev]"

- name: Test with pytest & coverage
run: |
python -m pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv

# Build the Python Wheel and the source distribution.
- name: Package release artifacts
run: |
python -m pip install setuptools wheel
python setup.py bdist_wheel sdist

# Attach the packaged artifacts to the workflow output. These can be manually
# downloaded for later inspection if necessary.
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/

publish_release:
needs: stage_release

# Check whether the release should be published. We publish only when the trigger PR is
# 1. merged
# 2. to the master branch
# 3. with the label 'release:publish', and
# 4. the title prefix '[chore] Release '.
if: github.event.pull_request.merged &&
github.ref == 'master' &&
contains(github.event.pull_request.labels.*.name, 'release:publish') &&
startsWith(github.event.pull_request.title, '[chore] Release ')

runs-on: ubuntu-latest

steps:
- name: Checkout source for publish
uses: actions/checkout@v3

# Download the artifacts created by the stage_release job.
- name: Download release candidates
uses: actions/download-artifact@v3
with:
name: dist
path: dist

- name: Publish preflight check
id: preflight
run: ./.github/scripts/publish_preflight_check.sh

- name: Create release tag
# Skip creating a release tag for prereleases
if: (!contains(github.event.pull_request.labels.*.name, 'release:prerelease'))
uses: elgohr/Github-Release-Action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.preflight.outputs.version }}
release_name: Firebase Functions Python SDK ${{ steps.preflight.outputs.version }}
body: ${{ steps.preflight.outputs.changelog }}
draft: false
prerelease: false

- name: Publish to Pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: firebase
password: ${{ secrets.PYPI_PASSWORD }}
Loading