Skip to content

Commit

Permalink
Refactor GitHub release workflows (#542)
Browse files Browse the repository at this point in the history
* Refactor GitHub release workflows

Refactor GitHub release workflows in order to comply with branch protection
rules. The new process:

1. Run the "Create new release PR" manually, selecting the release type
   ("major", "minor", or "patch"). This will create a new branch
including the Changelog update and the version bumo on the readme,
create-block-theme.php, and package.json files.
2. Merging the PR created on the previous step will trigger the deploy
   workflow, which remains unchanged, except for the conditions added in
order for it to run only if the merged PR matches the characteristics of
automated release PR.

1. Fork this repo
2. Checkout this branch
3. Merge intro trunk on the fork
4. Run the workflow, a new PR should be created on the fork
5. Merge the PR; the automated deploy step will run. At this point, the
   only thing that you'll be able to test on the fork is that the deploy
workflow correctly identifies the PR and branch as a new release. The
deploy itself requires credentials only available on the parent repo.

* add block themers as reviewers

* prefix tag with v

* add block themers as reviewers

* move version prefix to step where it's needed

* add deploy step name

* add trailing backslash

* remove reviewer

* add block-themers as reviewers for the release pr
  • Loading branch information
vcanales authored Apr 9, 2024
1 parent 14a6f16 commit fd372a6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 39,015 deletions.
85 changes: 24 additions & 61 deletions .github/workflows/deploy-to-dotorg.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Deploy to WordPress.org

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
inputs:
Expand All @@ -13,82 +11,47 @@ on:
- major
- minor
- patch
jobs:
update-google-fonts-json:
if: github.repository_owner == 'WordPress'
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

# Runs a single command using the runners shell
# This script fetchs the Goolgle Fonts API data and creates a PR if new data is available
- name: Update Google Fonts JSON file
env:
GOOGLE_FONTS_API_KEY: ${{ secrets.GOOGLE_FONTS_API_KEY }}
run: |
echo "Updating Google fonts JSON file"
node ./update-google-fonts-json-file.js
- name: Commit Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git config --global --add --bool push.autoSetupRemote true
pull_request:
types: [closed]
branches:
- trunk

git diff-index --quiet HEAD -- || \
( git add assets/google-fonts/fallback-fonts-list.json && \
git checkout trunk && \
git commit -m "Automation: update Google Fonts data file" --no-verify && \
git push
)
tag:
name: Checkout repo
jobs:
deploy-to-wordpress:
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/') &&
contains(github.event.pull_request.head.ref, '/major') || contains(github.event.pull_request.head.ref, '/minor') || contains(github.event.pull_request.head.ref, '/patch') &&
(github.event.pull_request.user.login == 'github-actions[bot]')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install node dependencies
run: npm install

- name: Compile Javascript App
run: npm run build

- name: Update version and changelog
id: update-version
env:
RELEASE_TYPE: ${{ github.event.inputs.release_type }}
run: npm run update-version
- name: Get New Version
id: get-version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Create Release
- name: Create Tag and Release on GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git config --global --add --bool push.autoSetupRemote true
git pull
git diff-index --quiet HEAD -- || ( git add package.json package-lock.json readme.txt create-block-theme.php && git commit -m "Version bump & changelog update" --no-verify && git push )
gh release create ${{steps.update-version.outputs.NEW_TAG }} --generate-notes
VERSION=v${{ steps.get-version.outputs.VERSION }}
git tag $VERSION
git push origin $VERSION
gh release create $VERSION --generate-notes
- name: Create Block Theme Plugin Deploy to WordPress.org
- name: Deploy Plugin to WordPress Plugin Directory
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
VERSION: ${{ steps.update-version.outputs.NEW_VERSION }}
VERSION: ${{ steps.get-version.outputs.VERSION }}

- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@stable
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/release-new-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Create new release PR

on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- major
- minor
- patch

jobs:
prepare-release:
if: github.event_name == 'workflow_dispatch'
name: Prepare Release PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Install node dependencies
run: npm install

- name: Compile Javascript App
run: npm run build

- name: Create version update branch
id: create-branch
run: |
BRANCH_NAME="release/$(date +%Y-%m-%d)/${{ github.event.inputs.release_type }}-release"
git checkout -b $BRANCH_NAME
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Update version and changelog
id: update-version
run: |
npm run update-version
echo "NEW_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
env:
RELEASE_TYPE: ${{ github.event.inputs.release_type }}

- name: Commit changes
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Version bump & changelog update" --no-verify
git push --set-upstream origin ${{ steps.create-branch.outputs.BRANCH_NAME }}
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--title "[Automation] New ${{ github.event.inputs.release_type }} Release: ${{ steps.update-version.outputs.NEW_VERSION }}" \
--base trunk \
--head ${{ steps.create-branch.outputs.BRANCH_NAME }} \
--label "Release: ${{ github.event.inputs.release_type }}" \
--reviewer "WordPress/block-themers" \
--body "
### Release PR 🤖
This is a release PR for version **${{ steps.update-version.outputs.NEW_VERSION }}**, run by **@${{ github.actor }}**.
It updates the version of the Plugin and adds changes since the last tag to the Changelog file.
Merging this PR will trigger a new release and update the Plugin in the WordPress Plugin Directory."
Loading

0 comments on commit fd372a6

Please sign in to comment.