Skip to content

Commit 404b098

Browse files
authored
Merge pull request #5 from woocommerce/update/release-workflow
Update release workflow to workflow_dispatch-only pattern
2 parents cb5d38a + 8279765 commit 404b098

1 file changed

Lines changed: 81 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,79 @@
1-
name: Release
1+
name: Release Plugin
2+
3+
# Produce a distributable `hey-woo.zip` and publish it as a GitHub Release.
4+
#
5+
# Trigger: manual workflow_dispatch only — tag pushes do NOT trigger this
6+
# workflow; the tag + Release are CREATED by the workflow, not consumed by it.
7+
# This makes the release a deliberate UI action that goes through the full
8+
# build + validation path.
9+
#
10+
# Prerequisites (enforced at runtime, workflow fails fast if not met):
11+
# - The `version` input must match the `Version:` header in hey-woo.php.
12+
# Bump the header on a PR and merge it first, then dispatch this workflow
13+
# with the matching version.
14+
# - The tag `v<version>` must not already exist on the remote.
215

316
on:
4-
push:
5-
tags:
6-
- 'v*'
717
workflow_dispatch:
18+
inputs:
19+
version:
20+
description: 'Release version, e.g. 0.1.0 (must match the Version header in hey-woo.php)'
21+
required: true
22+
type: string
23+
draft:
24+
description: 'Create the Release as a draft (review/edit before publishing)'
25+
type: boolean
26+
default: false
27+
prerelease:
28+
description: 'Mark the Release as a pre-release'
29+
type: boolean
30+
default: false
31+
32+
permissions:
33+
contents: write # required for softprops/action-gh-release to create the tag + Release
834

935
jobs:
10-
build:
11-
name: Build plugin zip
36+
release:
37+
name: Build and release
1238
runs-on: ubuntu-latest
1339

1440
steps:
1541
- name: Checkout
1642
uses: actions/checkout@v4
1743

44+
- name: Validate version input matches plugin header
45+
run: |
46+
# Strip an optional leading 'v' so both "0.1.0" and "v0.1.0" are accepted.
47+
INPUT_VERSION="${{ inputs.version }}"
48+
INPUT_VERSION="${INPUT_VERSION#v}"
49+
50+
HEADER_VERSION="$(awk '/^ \* Version:/ { print $3; exit }' hey-woo.php)"
51+
if [[ -z "${HEADER_VERSION}" ]]; then
52+
echo "ERROR: could not read Version header from hey-woo.php" >&2
53+
exit 1
54+
fi
55+
56+
if [[ "${INPUT_VERSION}" != "${HEADER_VERSION}" ]]; then
57+
echo "ERROR: input version '${INPUT_VERSION}' does not match the Version header ('${HEADER_VERSION}')." >&2
58+
echo " Bump hey-woo.php on a PR first, merge it, then re-run this workflow." >&2
59+
exit 1
60+
fi
61+
62+
echo "VERSION=${INPUT_VERSION}" >> "$GITHUB_ENV"
63+
echo "TAG_NAME=v${INPUT_VERSION}" >> "$GITHUB_ENV"
64+
65+
- name: Verify tag does not already exist
66+
run: |
67+
if git rev-parse -q --verify "refs/tags/${TAG_NAME}" > /dev/null 2>&1; then
68+
echo "ERROR: tag ${TAG_NAME} already exists locally in this checkout" >&2
69+
exit 1
70+
fi
71+
if git ls-remote --exit-code --tags origin "${TAG_NAME}" > /dev/null 2>&1; then
72+
echo "ERROR: tag ${TAG_NAME} already exists on origin" >&2
73+
echo " Either bump the version or delete the existing tag." >&2
74+
exit 1
75+
fi
76+
1877
- name: Setup Node
1978
uses: actions/setup-node@v4
2079
with:
@@ -27,16 +86,27 @@ jobs:
2786
- name: Build plugin zip
2887
run: npm run plugin-zip
2988

30-
- name: Upload zip artifact
89+
- name: Verify zip was produced
90+
run: |
91+
if [ ! -f hey-woo.zip ]; then
92+
echo "ERROR: hey-woo.zip not found" >&2
93+
exit 1
94+
fi
95+
96+
- name: Upload workflow artifact
3197
uses: actions/upload-artifact@v4
3298
with:
33-
name: hey-woo
99+
name: hey-woo-${{ env.VERSION }}
34100
path: hey-woo.zip
35-
retention-days: 7
101+
retention-days: 30
36102

37-
- name: Create GitHub release
38-
if: startsWith(github.ref, 'refs/tags/')
103+
- name: Create GitHub Release
39104
uses: softprops/action-gh-release@v2
40105
with:
106+
tag_name: ${{ env.TAG_NAME }}
107+
name: ${{ env.TAG_NAME }}
108+
target_commitish: ${{ github.sha }}
41109
files: hey-woo.zip
42110
generate_release_notes: true
111+
draft: ${{ inputs.draft }}
112+
prerelease: ${{ inputs.prerelease }}

0 commit comments

Comments
 (0)