|
| 1 | +name: Pre-release Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "plugins/**" |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write # Allow actions to read and write repository contents |
| 12 | + actions: read # Allow actions to read repository metadata but not write |
| 13 | +jobs: |
| 14 | + tag-pre-release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up PHP |
| 24 | + uses: shivammathur/setup-php@v2 |
| 25 | + with: |
| 26 | + php-version: '8.2' |
| 27 | + extensions: mbstring, json, zip |
| 28 | + |
| 29 | + - name: Setup Node.js |
| 30 | + uses: actions/setup-node@v4 |
| 31 | + with: |
| 32 | + node-version: 18.x |
| 33 | + |
| 34 | + - name: Setup pnpm |
| 35 | + uses: pnpm/action-setup@v3 |
| 36 | + with: |
| 37 | + version: 8 |
| 38 | + |
| 39 | + - name: Get changed plugin directory |
| 40 | + id: plugin |
| 41 | + run: | |
| 42 | + git fetch --prune --unshallow |
| 43 | + plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2) |
| 44 | + echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + - name: Validate plugin detection |
| 47 | + run: | |
| 48 | + if [ -z "${{ steps.plugin.outputs.plugin_slug }}" ]; then |
| 49 | + echo "No plugin detected in changes" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then |
| 54 | + echo "Plugin directory does not exist" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Install dependencies |
| 59 | + run: pnpm install |
| 60 | + |
| 61 | + - name: Apply version bumps from changesets |
| 62 | + run: pnpm changeset version |
| 63 | + |
| 64 | + - name: Commit updated package.json and changelogs |
| 65 | + run: | |
| 66 | + git config user.name "github-actions" |
| 67 | + git config user.email "[email protected]" |
| 68 | + git add . |
| 69 | + git commit -m "chore: apply version bump from changesets" || echo "No changes to commit" |
| 70 | + git push |
| 71 | +
|
| 72 | + - name: Read package metadata |
| 73 | + id: metadata |
| 74 | + run: | |
| 75 | + PLUGIN_DIR="plugins/${{ steps.plugin.outputs.plugin_slug }}" |
| 76 | +
|
| 77 | + if [ ! -f "$PLUGIN_DIR/package.json" ]; then |
| 78 | + echo "package.json not found in $PLUGIN_DIR" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + package_name=$(jq -r '.name // empty' "$PLUGIN_DIR/package.json") |
| 83 | + package_version=$(jq -r '.version // empty' "$PLUGIN_DIR/package.json") |
| 84 | +
|
| 85 | + if [ -z "$package_name" ] || [ "$package_name" = "null" ] || [ "$package_name" = "empty" ]; then |
| 86 | + echo "Missing or invalid name in $PLUGIN_DIR/package.json" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +
|
| 90 | + if [ -z "$package_version" ] || [ "$package_version" = "null" ] || [ "$package_version" = "empty" ]; then |
| 91 | + echo "Missing or invalid version in $PLUGIN_DIR/package.json" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +
|
| 95 | + echo "package_name=$package_name" >> $GITHUB_OUTPUT |
| 96 | + echo "package_version=$package_version" >> $GITHUB_OUTPUT |
| 97 | + echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT |
| 98 | +
|
| 99 | + - name: Create Git tag |
| 100 | + run: | |
| 101 | + TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}" |
| 102 | +
|
| 103 | + # Check if tag already exists |
| 104 | + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then |
| 105 | + echo "Tag $TAG_NAME already exists. Skipping tag creation." |
| 106 | + exit 0 |
| 107 | + fi |
| 108 | +
|
| 109 | + git config user.name "github-actions" |
| 110 | + git config user.email "[email protected]" |
| 111 | + git tag "$TAG_NAME" |
| 112 | + git push origin "$TAG_NAME" |
| 113 | +
|
| 114 | + - name: Run composer install |
| 115 | + working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }} |
| 116 | + run: composer install --no-dev --optimize-autoloader |
| 117 | + |
| 118 | + - name: Validate composer setup |
| 119 | + working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }} |
| 120 | + run: | |
| 121 | + composer validate --no-check-publish --no-check-lock |
| 122 | +
|
| 123 | + - name: Create plugin archive |
| 124 | + working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }} |
| 125 | + run: | |
| 126 | + mkdir -p plugin-build |
| 127 | + composer archive --format=zip --file="plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" |
| 128 | +
|
| 129 | + # Verify archive was created |
| 130 | + if [ ! -f "plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" ]; then |
| 131 | + echo "Failed to create plugin archive" |
| 132 | + exit 1 |
| 133 | + fi |
| 134 | +
|
| 135 | + echo "Archive created successfully: $(ls -lh plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip)" |
| 136 | +
|
| 137 | + - name: Upload archive to GitHub Release |
| 138 | + uses: softprops/action-gh-release@v2 |
| 139 | + with: |
| 140 | + tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }} |
| 141 | + name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}" |
| 142 | + prerelease: true |
| 143 | + files: | |
| 144 | + ${{ steps.metadata.outputs.PLUGIN_DIR }}/plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip |
| 145 | + env: |
| 146 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments