Release Plugin #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Plugin | |
| # Produce a distributable `woocommerce-claude.zip` and publish it as a GitHub Release. | |
| # | |
| # Trigger: manual workflow_dispatch only — tag pushes do NOT trigger this | |
| # workflow; the tag + Release are CREATED by the workflow, not consumed by it. | |
| # This makes the release a deliberate UI action that goes through the full | |
| # build + validation path. | |
| # | |
| # Prerequisites (enforced at runtime, workflow fails fast if not met): | |
| # - The `version` input must match the `Version:` header in woocommerce-claude.php. | |
| # Bump the header on a PR and merge it first, then dispatch this workflow | |
| # with the matching version. | |
| # - The tag `v<version>` must not already exist on the remote. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version, e.g. 0.1.0 (must match the Version header in woocommerce-claude.php)' | |
| required: true | |
| type: string | |
| draft: | |
| description: 'Create the Release as a draft (review/edit before publishing)' | |
| type: boolean | |
| default: false | |
| prerelease: | |
| description: 'Mark the Release as a pre-release' | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write # required for softprops/action-gh-release to create the tag + Release | |
| jobs: | |
| release: | |
| name: Build and release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Validate version input matches plugin header | |
| run: | | |
| # Strip an optional leading 'v' so both "0.1.0" and "v0.1.0" are accepted. | |
| INPUT_VERSION="${{ inputs.version }}" | |
| INPUT_VERSION="${INPUT_VERSION#v}" | |
| HEADER_VERSION="$(awk '/^ \* Version:/ { print $3; exit }' woocommerce-claude.php)" | |
| if [[ -z "${HEADER_VERSION}" ]]; then | |
| echo "ERROR: could not read Version header from woocommerce-claude.php" >&2 | |
| exit 1 | |
| fi | |
| if [[ "${INPUT_VERSION}" != "${HEADER_VERSION}" ]]; then | |
| echo "ERROR: input version '${INPUT_VERSION}' does not match the Version header ('${HEADER_VERSION}')." >&2 | |
| echo " Bump woocommerce-claude.php on a PR first, merge it, then re-run this workflow." >&2 | |
| exit 1 | |
| fi | |
| echo "VERSION=${INPUT_VERSION}" >> "$GITHUB_ENV" | |
| echo "TAG_NAME=v${INPUT_VERSION}" >> "$GITHUB_ENV" | |
| - name: Verify tag does not already exist | |
| run: | | |
| if git rev-parse -q --verify "refs/tags/${TAG_NAME}" > /dev/null 2>&1; then | |
| echo "ERROR: tag ${TAG_NAME} already exists locally in this checkout" >&2 | |
| exit 1 | |
| fi | |
| if git ls-remote --exit-code --tags origin "${TAG_NAME}" > /dev/null 2>&1; then | |
| echo "ERROR: tag ${TAG_NAME} already exists on origin" >&2 | |
| echo " Either bump the version or delete the existing tag." >&2 | |
| exit 1 | |
| fi | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build plugin zip | |
| run: npm run plugin-zip | |
| - name: Verify zip was produced | |
| run: | | |
| if [ ! -f woocommerce-claude.zip ]; then | |
| echo "ERROR: woocommerce-claude.zip not found" >&2 | |
| exit 1 | |
| fi | |
| - name: Upload workflow artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: woocommerce-claude-${{ env.VERSION }} | |
| path: woocommerce-claude.zip | |
| retention-days: 30 | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.TAG_NAME }} | |
| name: ${{ env.TAG_NAME }} | |
| target_commitish: ${{ github.sha }} | |
| files: woocommerce-claude.zip | |
| generate_release_notes: true | |
| draft: ${{ inputs.draft }} | |
| prerelease: ${{ inputs.prerelease }} |