1- name : Pre-release Tag
1+ # Part of create-release-branch.yml
2+ # Changesets are applied to the release branch instead of main as this is a production branch
3+ # Once merged, the PR should create the pre-release tag
4+
5+ name : Create Pre-release Tag
26
37on :
4- push :
8+ pull_request :
9+ types : [closed]
510 branches :
611 - main
712 paths :
813 - " plugins/**"
914
1015permissions :
11- contents : write # Allow actions to read and write repository contents
12- actions : read # Allow actions to read repository metadata but not write
16+ contents : write
17+ actions : read
18+
1319jobs :
1420 tag-pre-release :
21+ # Only run if PR was merged and branch name starts with 'release/'
22+ if : github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
1523 runs-on : ubuntu-latest
1624
1725 steps :
@@ -23,52 +31,38 @@ jobs:
2331 - name : Set up PHP
2432 uses : shivammathur/setup-php@v2
2533 with :
26- php-version : ' 8.2'
34+ php-version : ' 8.2' # Note: All plugins are compatible with PHP 8.2
2735 extensions : mbstring, json, zip
2836
2937 - name : Setup Node.js
3038 uses : actions/setup-node@v4
3139 with :
32- node-version : 18.x
40+ node-version : 18.x # Min version required by the repo
3341
3442 - name : Setup pnpm
3543 uses : pnpm/action-setup@v3
3644 with :
37- version : 10
45+ version : 10 # Min version required by the repo
3846
3947 - name : Get changed plugin directory
4048 id : plugin
4149 run : |
42- git fetch --prune --unshallow 2>/dev/null || git fetch --prune
50+ # Get files changed in the merged PR
4351 plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
52+ if [ -z "$plugin" ]; then
53+ # Fallback: extract from branch name if no plugin changes detected
54+ branch_name="${{ github.head_ref }}"
55+ plugin=$(echo "$branch_name" | sed 's/release\/\([^-]*\)-.*/\1/')
56+ fi
4457 echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
4558
4659 - name : Validate plugin detection
47- continue-on-error : false
4860 run : |
4961 if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
50- echo "Plugin directory does not exist"
62+ echo "Plugin directory does not exist: plugins/${{ steps.plugin.outputs.plugin_slug }} "
5163 exit 1
5264 fi
5365
54- - name : Install dependencies
55- run : pnpm install
56-
57- - name : Apply version bumps from changesets
58- run : pnpm changeset version
59- env :
60- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61-
62- - name : Commit updated package.json and changelogs
63- run : |
64- git config user.name "github-actions"
65- git config user.email "[email protected] " 66- git add .
67- git commit -m "chore: apply version bump from changesets" || echo "No changes to commit"
68- git push
69- env :
70- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
71-
7266 - name : Read package metadata
7367 id : metadata
7468 run : |
@@ -95,26 +89,31 @@ jobs:
9589 echo "package_name=$package_name" >> $GITHUB_OUTPUT
9690 echo "package_version=$package_version" >> $GITHUB_OUTPUT
9791 echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
98- env :
99- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
10092
10193 - name : Create Git tag
94+ continue-on-error : false
10295 run : |
10396 TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"
10497
10598 # Check if tag already exists
10699 if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
107100 echo "Tag $TAG_NAME already exists. Skipping tag creation."
108- exit 0
101+ echo "tag_exists=true" >> $GITHUB_ENV
102+ exit 1
109103 fi
110104
111105 git config user.name "github-actions"
112106 git config user.email "[email protected] " 113107 git tag "$TAG_NAME"
114108 git push origin "$TAG_NAME"
109+ echo "tag_exists=false" >> $GITHUB_ENV
110+ echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
115111 env :
116112 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117113
114+ - name : Install dependencies
115+ run : pnpm install
116+
118117 - name : Run composer install
119118 working-directory : ${{ steps.metadata.outputs.PLUGIN_DIR }}
120119 run : composer install --no-dev --optimize-autoloader
@@ -141,7 +140,7 @@ jobs:
141140 - name : Upload archive to GitHub Release
142141 uses : softprops/action-gh-release@v2
143142 with :
144- tag_name : ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
143+ tag_name : ${{ env.TAG_NAME }}
145144 name : " Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
146145 prerelease : true
147146 files : |
0 commit comments