Skip to content

chore: Making the separation between staging and publishing explicit #407

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 5 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions .github/scripts/publish_preflight_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,41 @@ echo_info "Extracted release version: ${RELEASE_VERSION}"
echo "::set-output name=version::v${RELEASE_VERSION}"


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_admin-${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_admin-${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"
Expand Down
54 changes: 39 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Release
name: Release Candidate

on:
# Only run the workflow when a PR is updated or when a developer explicitly requests
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install wheel
pip install setuptools wheel

- name: Run unit tests
run: pytest
Expand All @@ -60,8 +60,9 @@ jobs:
FIREBASE_SERVICE_ACCT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCT_KEY }}
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}

# Build the Python Wheel and the source distribution.
- name: Package release artifacts
run: python setup.py bdist_wheel bdist_egg
run: python setup.py bdist_wheel sdist

# Attach the packaged artifacts to the workflow output. These can be manually
# downloaded for later inspection if necessary.
Expand All @@ -71,24 +72,48 @@ jobs:
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 title prefix '[chore] Release '.
if: github.event.pull_request.merged &&
github.ref == 'master' &&
startsWith(github.event.pull_request.title, '[chore] Release ')

runs-on: ubuntu-latest

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

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

# Python is needed to run Twine and some of the preflight checks.
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.6

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine

- name: Publish preflight check
if: success() && github.event.pull_request.merged &&
github.ref == 'master' &&
startsWith(github.event.pull_request.title, '[chore] Release ')
id: preflight
run: |
./.github/scripts/publish_preflight_check.sh
echo ::set-env name=FIREBASE_PUBLISH::true
run: ./.github/scripts/publish_preflight_check.sh

# Tag the release if not executing in the dryrun mode. We pull this action froma
# 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.
# 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
if: success() && env.FIREBASE_PUBLISH
uses: fleskesvor/create-release@1a72e235c178bf2ae6c51a8ae36febc24568c5fe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -100,12 +125,11 @@ jobs:
prerelease: false

- name: Publish to Pypi
if: success() && env.FIREBASE_PUBLISH
run: echo Publishing to Pypi

# Post to Twitter if explicitly opted-in by adding the label 'release:tweet'.
- name: Post to Twitter
if: success() && env.FIREBASE_PUBLISH &&
if: success() &&
contains(github.event.pull_request.labels.*.name, 'release:tweet')
run: echo Posting Tweet
continue-on-error: true