Skip to content

Commit 55edcd8

Browse files
committed
refactor: move version bump and release creation into caller workflow
- Add bump-version job: owns npm version, git tag, and push to main - The publish job receives the version already set in package.json - The create-release job depends on bump-version output, not publish - Remove bump-type pass-through to reusable workflow (no longer needed) - The reusable workflow now only builds and publishes
1 parent 14e6c70 commit 55edcd8

1 file changed

Lines changed: 68 additions & 5 deletions

File tree

.github/workflows/publish-ui-npm.yaml

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
default: patch
1414

1515
jobs:
16+
# ── Detect release mode ──────────────────────────────────────────────────
17+
# Reads the merged PR's labels to decide dev vs release, and which semver
18+
# component to bump. workflow_dispatch always triggers a release.
1619
detect-mode:
1720
name: Detect release mode
1821
runs-on: ubuntu-latest
@@ -33,13 +36,17 @@ jobs:
3336
fi
3437
3538
# For push events, check the merged PR's labels to decide dev vs release.
39+
# NOTE: relies on merge commits (not squash/rebase) so github.sha matches
40+
# the PR's merge commit SHA in the search results.
3641
LABELS=$(gh pr list \
3742
--state merged \
3843
--base main \
3944
--search "${{ github.sha }}" \
4045
--json labels \
4146
--jq '.[0].labels[].name' 2>/dev/null || true)
4247
48+
# Match "release" or "release:<type>" but not unrelated labels like
49+
# "release-blocker" or "release-notes".
4350
if echo "$LABELS" | grep -qE "^release(:|$)"; then
4451
echo "mode=release" >> "$GITHUB_OUTPUT"
4552
if echo "$LABELS" | grep -q "release:major"; then
@@ -54,28 +61,84 @@ jobs:
5461
echo "bump-type=patch" >> "$GITHUB_OUTPUT"
5562
fi
5663
57-
publish:
64+
# ── Bump version ─────────────────────────────────────────────────────────
65+
# Runs only for release mode. Bumps the version in package.json, commits,
66+
# creates the git tag, and pushes to main. All downstream jobs read the
67+
# version from this job's output — the npm publish workflow receives it
68+
# already set in package.json.
69+
bump-version:
70+
name: Bump version
5871
needs: detect-mode
72+
if: needs.detect-mode.outputs.release-mode == 'release'
73+
runs-on: ubuntu-latest
74+
permissions:
75+
contents: write
76+
outputs:
77+
new-version: ${{ steps.bump.outputs.new-version }}
78+
steps:
79+
- name: Checkout
80+
uses: actions/checkout@v4
81+
with:
82+
ref: main
83+
84+
- name: Setup pnpm
85+
uses: pnpm/action-setup@v4
86+
with:
87+
package_json_file: ui/package.json
88+
89+
- name: Setup Node.js
90+
uses: actions/setup-node@v4
91+
with:
92+
node-version: 24
93+
cache: pnpm
94+
cache-dependency-path: ui/pnpm-lock.yaml
95+
96+
- name: Configure git
97+
run: |
98+
git config user.name "github-actions[bot]"
99+
git config user.email "github-actions[bot]@users.noreply.github.com"
100+
101+
- name: Bump version and push tag
102+
id: bump
103+
working-directory: ui
104+
env:
105+
BUMP_TYPE: ${{ needs.detect-mode.outputs.bump-type }}
106+
run: |
107+
if [[ "$BUMP_TYPE" != "major" && "$BUMP_TYPE" != "minor" && "$BUMP_TYPE" != "patch" ]]; then
108+
echo "::error::Invalid bump-type '$BUMP_TYPE'. Must be major, minor, or patch."
109+
exit 1
110+
fi
111+
NEW_VERSION=$(npm version "$BUMP_TYPE" \
112+
--message "chore: release @datum-cloud/activity-ui v%s [skip ci]")
113+
echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
114+
git push origin main --follow-tags
115+
116+
# ── Publish to npm ───────────────────────────────────────────────────────
117+
# For release: package.json already has the bumped version from bump-version.
118+
# For dev: the reusable workflow computes a pre-release version from the SHA.
119+
publish:
120+
needs: [detect-mode, bump-version]
121+
if: always() && !failure() && !cancelled() && needs.detect-mode.result == 'success'
59122
uses: datum-cloud/actions/.github/workflows/publish-npm-package.yaml@v1.13.0
60123
with:
61124
package-name: "@datum-cloud/activity-ui"
62125
package-path: ui
63126
release-mode: ${{ needs.detect-mode.outputs.release-mode }}
64-
bump-type: ${{ needs.detect-mode.outputs.bump-type }}
65127
secrets: inherit
66128

129+
# ── Create GitHub Release ────────────────────────────────────────────────
67130
create-release:
68131
name: Create GitHub Release
69-
needs: [detect-mode, publish]
70-
if: needs.detect-mode.outputs.release-mode == 'release'
132+
needs: [bump-version, publish]
133+
if: needs.bump-version.result == 'success'
71134
runs-on: ubuntu-latest
72135
permissions:
73136
contents: write
74137
steps:
75138
- name: Create GitHub Release
76139
env:
77140
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78-
RELEASE_VERSION: ${{ needs.publish.outputs.new-version }}
141+
RELEASE_VERSION: ${{ needs.bump-version.outputs.new-version }}
79142
run: |
80143
gh release create "$RELEASE_VERSION" \
81144
--title "@datum-cloud/activity-ui $RELEASE_VERSION" \

0 commit comments

Comments
 (0)