Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
---

chore: Initial beta release of hwp-previews.

5 changes: 0 additions & 5 deletions .changeset/proud-mayflies-sip.md

This file was deleted.

100 changes: 100 additions & 0 deletions .github/workflows/create-release-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

# This creates a release branch for a plugin when changes are pushed to the main branch.
# We cannot commit to a protected branch directly, so we create a new branch to make these changes.
name: Create Release Branch

on:
push:
branches:
- main
paths:
- "plugins/**"

permissions:
contents: write # Allow actions to read and write repository contents
pull-requests: write # Allow actions to create and manage pull requests
actions: read # Allow actions to read repository metadata but not write to it

jobs:
create-release-branch:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2' # Note all plugins are compatible with PHP 8.2
extensions: mbstring, json, zip

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x. # Min version required by the repo

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10 # Min version required by the repo

- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT

- name: Validate plugin detection
continue-on-error: false
run: |
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
echo "Plugin directory does not exist"
exit 1
fi

- name: Install dependencies
run: pnpm install

- name: Create release branch and apply changesets
run: |
# Create a unique branch name with timestamp
BRANCH_NAME="release/${{ steps.plugin.outputs.plugin_slug }}-$(date +%Y%m%d-%H%M%S)"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV

# Create and switch to release branch
git checkout -b "$BRANCH_NAME"

# Apply version bumps from changesets
pnpm changeset version

# Configure git
git config user.name "github-actions"
git config user.email "[email protected]"

# Commit changes
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: apply version bump from changesets for ${{ steps.plugin.outputs.plugin_slug }}"
git push origin "$BRANCH_NAME"

# Create PR
gh pr create \
--title "Release: ${{ steps.plugin.outputs.plugin_slug }} version bump" \
--body "Automated release PR for ${{ steps.plugin.outputs.plugin_slug }} plugin.

This PR applies version bumps from changesets. Once merged, it will trigger the pre-release creation workflow.

Plugin: ${{ steps.plugin.outputs.plugin_slug }}" \
--base main \
--head "$BRANCH_NAME"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
name: Pre-release Tag
# Part of create-release-branch.yml
# Changesets are applied to the release branch instead of main as this is a production branch
# Once merged, the PR should create the pre-release tag

name: Create Pre-release Tag

on:
push:
pull_request:
types: [closed]
branches:
- main
paths:
- "plugins/**"

permissions:
contents: write # Allow actions to read and write repository contents
actions: read # Allow actions to read repository metadata but not write
contents: write
actions: read

jobs:
tag-pre-release:
# Only run if PR was merged and branch name starts with 'release/'
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
runs-on: ubuntu-latest

steps:
Expand All @@ -23,52 +31,38 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.2' # Note: All plugins are compatible with PHP 8.2
extensions: mbstring, json, zip

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 18.x # Min version required by the repo

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10
version: 10 # Min version required by the repo

- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
# Get files changed in the merged PR
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
if [ -z "$plugin" ]; then
# Fallback: extract from branch name if no plugin changes detected
branch_name="${{ github.head_ref }}"
plugin=$(echo "$branch_name" | sed 's/release\/\([^-]*\)-.*/\1/')
fi
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT

- name: Validate plugin detection
continue-on-error: false
run: |
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
echo "Plugin directory does not exist"
echo "Plugin directory does not exist: plugins/${{ steps.plugin.outputs.plugin_slug }}"
exit 1
fi

- name: Install dependencies
run: pnpm install

- name: Apply version bumps from changesets
run: pnpm changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit updated package.json and changelogs
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add .
git commit -m "chore: apply version bump from changesets" || echo "No changes to commit"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Read package metadata
id: metadata
run: |
Expand All @@ -95,26 +89,31 @@ jobs:
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Git tag
continue-on-error: false
run: |
TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"

# Check if tag already exists
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists. Skipping tag creation."
exit 0
echo "tag_exists=true" >> $GITHUB_ENV
exit 1
fi

git config user.name "github-actions"
git config user.email "[email protected]"
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
echo "tag_exists=false" >> $GITHUB_ENV
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: pnpm install

- name: Run composer install
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
run: composer install --no-dev --optimize-autoloader
Expand All @@ -141,7 +140,7 @@ jobs:
- name: Upload archive to GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
tag_name: ${{ env.TAG_NAME }}
name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
prerelease: true
files: |
Expand Down
2 changes: 1 addition & 1 deletion plugins/hwp-previews/TESTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Testing HWP Previews

This plugin uses [Codeception](https://codeception.com/) with [WPBrowser](https://wpbrowser.wptestkit.dev/) for automated testing.
Tests are organized into suites for unit, integration (wpunit), functional, and acceptance testing.
Tests are organized into suites for integration (wpunit), functional, and acceptance testing.

---

Expand Down
Loading