176 lines
6.2 KiB
YAML
176 lines
6.2 KiB
YAML
name: Release (Part 1 of 2)
|
|
|
|
on:
|
|
schedule:
|
|
# every tuesday at 10:20am PST (6:20pm UTC)
|
|
# cron doesn't support "first tuesday of the month", so we will use github
|
|
# actions syntax below to skip tuesdays that aren't in the first week.
|
|
# it is recommended not to start on the hour to avoid peak traffic
|
|
- cron: "20 18 * * 2"
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
required: true
|
|
type: string
|
|
|
|
env:
|
|
VERSION: ${{ inputs.version }}
|
|
AUTORELEASE_BRANCH: autorelease/${{ inputs.version }}
|
|
# use a personal access token here which has permissions to trigger further actions
|
|
# this is necessary for the pr checks
|
|
GITHUB_TOKEN: ${{ secrets.AUTORELEASE_BOT_PAT }}
|
|
|
|
jobs:
|
|
start-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
# skip scheduled runs that aren't the first tuesday of the month
|
|
- name: Check day of month
|
|
run: |
|
|
if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" || $(date +%d) -le 7 ]]; then
|
|
echo "RUN=true" >> $GITHUB_ENV
|
|
else
|
|
echo "RUN=false" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- uses: actions/checkout@v4
|
|
if: env.RUN == 'true'
|
|
with:
|
|
fetch-depth: 0 # fetch entire history, for versioning
|
|
token: ${{ secrets.AUTORELEASE_BOT_PAT }}
|
|
|
|
- name: Install dependencies
|
|
if: env.RUN == 'true'
|
|
run: pip install rst2html5 setuptools_scm
|
|
|
|
- name: Get current version number (scheduled runs only)
|
|
if: github.event_name == 'schedule'
|
|
run: echo "CURRENT_VERSION=$(python -m setuptools_scm)" > $GITHUB_ENV
|
|
|
|
- name: Get next bugfix version number (scheduled runs only)
|
|
if: github.event_name == 'schedule'
|
|
shell: python
|
|
run: |
|
|
import os
|
|
major, minor, bugfix, *_ = os.environ['CURRENT_VERSION'].split('.')
|
|
with open(os.environ['GITHUB_ENV']) as env_file:
|
|
env_file.write(f'VERSION={major}.{minor}.{int(bugfix) + 1}')
|
|
|
|
- name: Configure git
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
git config user.name "GitHub Actions"
|
|
git config user.email "<>"
|
|
|
|
# Members of the natcap software team can push to the autorelease branch on
|
|
# natcap/invest; this branch is a special case for our release process.
|
|
- name: Create autorelease branch
|
|
if: env.RUN == 'true'
|
|
run: git checkout -b "$AUTORELEASE_BRANCH"
|
|
|
|
# Replace
|
|
#
|
|
# Unreleased Changes
|
|
# ------------------
|
|
#
|
|
# with
|
|
#
|
|
# ..
|
|
# Unreleased Changes
|
|
# ------------------
|
|
#
|
|
# X.X.X (XXXX-XX-XX)
|
|
# ------------------
|
|
- name: Update HISTORY.rst
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
HEADER="$VERSION ($(date '+%Y-%m-%d'))"
|
|
HEADER_LENGTH=${#HEADER}
|
|
UNDERLINE=$(for i in $(seq 1 $HEADER_LENGTH); do echo -n "-"; done)
|
|
perl -0777 -i -pe \
|
|
"s/Unreleased Changes\n------------------/..\n Unreleased Changes\n ------------------\n\n${HEADER}\n${UNDERLINE}/g" \
|
|
HISTORY.rst
|
|
|
|
- name: Generate changelog.html
|
|
if: env.RUN == 'true'
|
|
run: rst2html5 HISTORY.rst workbench/changelog.html
|
|
|
|
- name: Update package.json version
|
|
if: ${{ env.RUN }}
|
|
uses: BellCubeDev/update-package-version-by-release-tag@v2
|
|
with:
|
|
version: ${{ inputs.version }}
|
|
package-json-path: workbench/package.json
|
|
|
|
- name: Commit updated HISTORY.rst, changelog.html, and package.json
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
git add HISTORY.rst
|
|
git add workbench/changelog.html
|
|
git add workbench/package.json
|
|
git commit -m "Committing the $VERSION release."
|
|
|
|
- name: Tag and push
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
git tag $VERSION
|
|
git push --atomic origin $AUTORELEASE_BRANCH $VERSION
|
|
|
|
- name: Find actions run for the version tag
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
# wait a few seconds to make sure the actions run exists before querying it
|
|
sleep 5
|
|
echo "TAG_RUN_URL=$( \
|
|
gh run list \
|
|
--branch $VERSION \
|
|
--limit 1 \
|
|
--json url \
|
|
--jq .[].url)" >> $GITHUB_ENV
|
|
|
|
- name: Create a PR from the autorelease branch into main
|
|
if: env.RUN == 'true'
|
|
run: |
|
|
gh pr create \
|
|
--base main \
|
|
--head $AUTORELEASE_BRANCH \
|
|
--title "$VERSION release" \
|
|
--reviewer $GITHUB_ACTOR \
|
|
--assignee $GITHUB_ACTOR \
|
|
--body "
|
|
# Release $VERSION and merge into \`main\`
|
|
|
|
This PR contains automated changes made for the $VERSION release.
|
|
|
|
Merging this PR will trigger an action that publishes the \
|
|
release. Closing this PR without merging will trigger an action that \
|
|
rolls back any release steps that have completed so far.
|
|
|
|
## Review this PR
|
|
- [ ] Make sure that the automated changes look correct
|
|
- [ ] Wait for BOTH the PR checks below AND the [$VERSION tag checks]($TAG_RUN_URL) \
|
|
to complete. The $VERSION tag workflow is most important \
|
|
because it produces the artifacts that will be used in the \
|
|
next steps of the release process.
|
|
- [ ] Download and try out the [tag build artifacts]($TAG_RUN_URL)
|
|
|
|
**If everything looks good**, approve and merge this PR. This will \
|
|
trigger a Github Action that will publish the release. Then go \
|
|
back to the [Release Checklist](https://github.com/natcap/invest/wiki/Release-Checklist) \
|
|
and complete any remaining tasks.
|
|
|
|
**If there is a bug**, decline this PR. Submit a fix in a separate \
|
|
PR into \`main\`. Once the fix has been merged, restart the release \
|
|
process from the beginning.
|
|
|
|
**If either workflow fails due to an intermittent problem**, \
|
|
rerun it through the GitHub UI. Proceed to approve and merge this \
|
|
PR once it succeeds."
|
|
|
|
- name: Roll back on failure
|
|
if: failure()
|
|
uses: ./.github/actions/rollback_release
|
|
with:
|
|
VERSION: ${{ env.VERSION }}
|
|
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
|