|
| 1 | +name: Upload Release Asset |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + upload: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Resolve release tag |
| 17 | + id: release |
| 18 | + run: | |
| 19 | + tag="${{ github.event.release.tag_name }}" |
| 20 | +
|
| 21 | + if ! printf '%s' "$tag" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 22 | + echo "Release asset uploads only run for numeric semver tags like 1.0.0 or 2.40.4." |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +
|
| 26 | + echo "tag=${tag}" >> "$GITHUB_OUTPUT" |
| 27 | +
|
| 28 | + - name: Setup workflow context |
| 29 | + id: workflow |
| 30 | + working-directory: ${{ runner.temp }} |
| 31 | + run: | |
| 32 | + mkdir dist |
| 33 | + echo "DIST=${PWD}/dist" >> "$GITHUB_OUTPUT" |
| 34 | + echo "PACKAGE=wp-plugin-mcp" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v7 |
| 38 | + with: |
| 39 | + ref: ${{ steps.release.outputs.tag }} |
| 40 | + |
| 41 | + - name: Validate plugin version |
| 42 | + env: |
| 43 | + RELEASE_TAG: ${{ steps.release.outputs.tag }} |
| 44 | + run: | |
| 45 | + plugin_header_version="$(awk -F ': ' '/^[[:space:]]*\* Version:/ { print $2; exit }' wp-plugin-mcp.php)" |
| 46 | + plugin_constant_version="$(sed -n "s/^define( 'WP_FORGE_MCP_VERSION', '\([^']*\)' );$/\1/p" wp-plugin-mcp.php)" |
| 47 | +
|
| 48 | + if [ "$plugin_header_version" != "$RELEASE_TAG" ]; then |
| 49 | + echo "Plugin header version ${plugin_header_version} does not match release tag ${RELEASE_TAG}." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + if [ "$plugin_constant_version" != "$RELEASE_TAG" ]; then |
| 54 | + echo "WP_FORGE_MCP_VERSION ${plugin_constant_version} does not match release tag ${RELEASE_TAG}." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Setup PHP |
| 59 | + uses: shivammathur/setup-php@v2 |
| 60 | + with: |
| 61 | + php-version: '8.3' |
| 62 | + coverage: none |
| 63 | + |
| 64 | + - name: Install production dependencies |
| 65 | + run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader |
| 66 | + |
| 67 | + - name: Prepare files |
| 68 | + env: |
| 69 | + DIST: ${{ steps.workflow.outputs.DIST }} |
| 70 | + PACKAGE: ${{ steps.workflow.outputs.PACKAGE }} |
| 71 | + run: | |
| 72 | + mkdir -p "$DIST/$PACKAGE" |
| 73 | + rsync -r --delete --exclude-from=.distignore ./ "$DIST/$PACKAGE/" |
| 74 | +
|
| 75 | + - name: Build zip |
| 76 | + env: |
| 77 | + DIST: ${{ steps.workflow.outputs.DIST }} |
| 78 | + PACKAGE: ${{ steps.workflow.outputs.PACKAGE }} |
| 79 | + run: | |
| 80 | + cd "$DIST" |
| 81 | + zip -r "${PACKAGE}.zip" "$PACKAGE" |
| 82 | +
|
| 83 | + - name: Upload release asset |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ github.token }} |
| 86 | + DIST: ${{ steps.workflow.outputs.DIST }} |
| 87 | + PACKAGE: ${{ steps.workflow.outputs.PACKAGE }} |
| 88 | + RELEASE_TAG: ${{ steps.release.outputs.tag }} |
| 89 | + run: gh release upload "$RELEASE_TAG" "$DIST/${PACKAGE}.zip" --clobber |
0 commit comments