Release - Create PR to trunk #90
This file contains 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
name: "Release - Create PR to trunk" | |
# This action will run inside the release code freeze workflow or when it is triggered manually | |
on: | |
workflow_call: | |
inputs: | |
releaseVersion: | |
description: 'The release version (e.g. 4.5.0)' | |
required: true | |
type: string | |
releaseDateString: | |
description: "The release date in human-readable format (default: 'next wednesday')." | |
required: false | |
default: "next wednesday" | |
type: string | |
skip-smoke-tests: | |
type: boolean | |
required: false | |
default: false | |
description: "Skip running smoke tests" | |
outputs: | |
release-pr-id: | |
description: "ID of the release PR created" | |
value: ${{ jobs.prepare-release.outputs.release-pr-id }} | |
workflow_dispatch: | |
inputs: | |
releaseVersion: | |
description: 'The release version (e.g. 4.5.0)' | |
required: true | |
type: string | |
releaseDateString: | |
description: "The release date in human-readable format (default: 'next wednesday')." | |
required: false | |
default: "next wednesday" | |
type: string | |
skip-build-zip: | |
type: boolean | |
required: false | |
default: true | |
description: "Skip building the zip file" | |
skip-smoke-tests: | |
type: boolean | |
required: false | |
default: false | |
description: "Skip running smoke tests" | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
prepare-release: | |
name: "Prepare a stable release" | |
runs-on: ubuntu-latest | |
outputs: | |
branch: ${{ steps.create_branch.outputs.branch-name }} | |
release-pr-id: ${{ steps.create-pr-to-trunk.outputs.RELEASE_PR_ID }} | |
env: | |
RELEASE_VERSION: ${{ inputs.releaseVersion }} | |
RELEASE_DATE_STRING: ${{ inputs.releaseDateString }} | |
steps: | |
- name: "Checkout repository" | |
uses: actions/checkout@v4 | |
- name: "Set up repository" | |
uses: ./.github/actions/setup-repo | |
- name: "Create a release branch" | |
id: create_branch | |
uses: ./.github/actions/create-branch | |
with: | |
version: ${{ env.RELEASE_VERSION }} | |
is-pre-release: 'false' | |
- name: "Define the release date" | |
id: define_var | |
run: | | |
RELEASE_DATE=$( date "+%Y-%m-%d" -d "$RELEASE_DATE_STRING" ) # Release date formatted as YYYY-MM-DD | |
echo "RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_OUTPUT | |
- name: "Generate the changelog" | |
id: generate_changelog | |
uses: ./.github/actions/process-changelog | |
with: | |
release-version: ${{ steps.create_branch.outputs.trimmed-version }} | |
release-date: ${{ steps.define_var.outputs.RELEASE_DATE }} | |
- name: "Bump version" | |
env: | |
RELEASE_VERSION: ${{ steps.create_branch.outputs.trimmed-version }} | |
RELEASE_DATE: ${{ steps.define_var.outputs.RELEASE_DATE }} | |
CHANGELOG: ${{ steps.generate_changelog.outputs.changelog }} | |
run: | | |
CURRENT_VERSION=$(jq '.version' package.json -r) | |
# 'Version' header in woocommerce-payments.php | |
sed -i "s/^ \* Version: .*$/ * Version: $RELEASE_VERSION/" woocommerce-payments.php | |
# 'version' field in package.json and package-lock.json | |
npm version $RELEASE_VERSION --no-git-tag-version | |
# 'Stable tag' header in readme.txt; | |
sed -i "s/^Stable tag: .*$/Stable tag: $RELEASE_VERSION/" readme.txt | |
- name: "Commit and push changes" | |
env: | |
RELEASE_VERSION: ${{ steps.create_branch.outputs.trimmed-version }} | |
BRANCH_NAME: ${{ steps.create_branch.outputs.branch-name }} | |
uses: ./.github/actions/commit-push-as-bot | |
with: | |
release-version: ${{ env.RELEASE_VERSION }} | |
branch: ${{ env.BRANCH_NAME }} | |
- name: "Create a PR to trunk" | |
id: create-pr-to-trunk | |
env: | |
GITHUB_TOKEN: ${{ secrets.BOTWOO_TOKEN }} | |
BRANCH_NAME: ${{ steps.create_branch.outputs.branch-name }} | |
CHANGELOG: ${{ steps.generate_changelog.outputs.changelog }} | |
RELEASE_VERSION: ${{ steps.create_branch.outputs.trimmed-version }} | |
run: | | |
PR_BODY=$(echo -e ":warning: Please do not merge the PR from the GitHub interface. :warning:\n\n Instead, you can use the following command:\n\`\`\`\n git checkout $BRANCH_NAME && git pull \n git checkout trunk && git pull \n git merge --no-ff $BRANCH_NAME -m 'Merge $BRANCH_NAME into trunk' \n git push origin trunk \n\`\`\` \n Changelog: \n\`\`\`\n${CHANGELOG}\n\`\`\`") | |
PR_URL=$(gh pr create --title "Release branch for $RELEASE_VERSION" --body="$PR_BODY" --base="trunk") | |
PR_ID=${PR_URL##*/} | |
if [[ $PR_ID =~ ^[0-9]+$ ]]; then | |
echo "RELEASE_PR_ID=$PR_ID" >> $GITHUB_OUTPUT | |
fi | |
- name: Add comment to PR | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_PR_ID: ${{ steps.create-pr-to-trunk.outputs.RELEASE_PR_ID }} | |
run: | | |
gh pr comment https://github.com/Automattic/woocommerce-payments/pull/$RELEASE_PR_ID --body="### Release zip build & Smoke tests | |
Check status of zip file build & smoke tests at https://github.com/Automattic/woocommerce-payments/actions/runs/${GITHUB_RUN_ID}" | |
build-zip-and-run-smoke-tests: | |
name: "Build zip & Run smoke tests" | |
needs: prepare-release | |
if: ${{ ! inputs.skip-build-zip }} | |
uses: ./.github/workflows/build-zip-and-run-smoke-tests.yml | |
with: | |
skip-smoke-tests: ${{ inputs.skip-smoke-tests }} | |
repo-branch: ${{ needs.prepare-release.outputs.branch }} | |
secrets: inherit |