diff --git a/.changeset/fast-bikes-glow.md b/.changeset/lazy-tools-vanish.md similarity index 99% rename from .changeset/fast-bikes-glow.md rename to .changeset/lazy-tools-vanish.md index 8ec19a93..eb6b0874 100644 --- a/.changeset/fast-bikes-glow.md +++ b/.changeset/lazy-tools-vanish.md @@ -3,3 +3,4 @@ --- chore: Initial beta release of hwp-previews. + diff --git a/.changeset/proud-mayflies-sip.md b/.changeset/proud-mayflies-sip.md deleted file mode 100644 index 3792de8a..00000000 --- a/.changeset/proud-mayflies-sip.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@wpengine/hwp-previews-wordpress-plugin": patch ---- - -chore: Initial beta release of hwp-previews wordpress plugin. diff --git a/.github/workflows/create-release-branch.yml b/.github/workflows/create-release-branch.yml new file mode 100644 index 00000000..fe3fd1bf --- /dev/null +++ b/.github/workflows/create-release-branch.yml @@ -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 "github-actions@github.com" + + # 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 }} diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release-tag.yml similarity index 76% rename from .github/workflows/pre-release.yml rename to .github/workflows/pre-release-tag.yml index 940a0b2b..c17f22e9 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release-tag.yml @@ -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: @@ -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 "github-actions@github.com" - 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: | @@ -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 "github-actions@github.com" 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 @@ -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: | diff --git a/plugins/hwp-previews/TESTING.md b/plugins/hwp-previews/TESTING.md index 5df38667..b51ad609 100644 --- a/plugins/hwp-previews/TESTING.md +++ b/plugins/hwp-previews/TESTING.md @@ -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. ---