-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (164 loc) · 6.32 KB
/
Copy pathpublish.yml
File metadata and controls
181 lines (164 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Publish
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type (ignored if version is set)"
required: false
type: choice
default: "patch"
options:
- patch
- minor
- major
- none
version:
description: "Custom version (e.g. 1.2.3) — overrides bump"
required: false
type: string
default: ""
tag:
description: "npm dist-tag (default: latest)"
required: false
type: string
default: "latest"
dry_run:
description: "Dry run — bump the version but do not publish"
required: false
type: boolean
default: false
permissions:
contents: write
id-token: write
jobs:
publish:
name: Build & Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install deps
run: pnpm install --frozen-lockfile
- name: Determine target version
id: version
# Compute the next version in pure bash against the CLI subpackage.
# `npm version --dry-run` mutates package.json in npm 11.x, so we
# don't use it.
run: |
set -euo pipefail
CURRENT=$(node -p "require('./packages/cli/package.json').version")
bump_semver() {
local ver="$1" kind="$2"
local core="${ver%%-+}"
core="${core#v}"
local IFS='.'
read -r major minor patch <<< "$core"
case "$kind" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) echo "::error::Unknown bump kind: $kind" >&2; return 1 ;;
esac
printf '%d.%d.%d' "$major" "$minor" "$patch"
}
if [ -n "${{ inputs.version }}" ]; then
TARGET="${{ inputs.version }}"
BUMP_KIND="custom"
elif [ "${{ inputs.bump }}" != "none" ]; then
TARGET=$(bump_semver "$CURRENT" "${{ inputs.bump }}")
BUMP_KIND="${{ inputs.bump }}"
else
TARGET="$CURRENT"
BUMP_KIND="none"
fi
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "target=$TARGET" >> "$GITHUB_OUTPUT"
echo "bump=$BUMP_KIND" >> "$GITHUB_OUTPUT"
- name: Bump version in packages/cli/package.json
if: steps.version.outputs.target != steps.version.outputs.current
run: |
set -euo pipefail
cd packages/cli
npm version "${{ steps.version.outputs.target }}" --no-git-tag-version --workspaces=false
- name: Build
run: pnpm --filter @iamcoder18/huly-cli build
# The committed `packages/cli/package.json` keeps the legacy
# `@iamcoder18/huly-cli` name (the preferred one) so internal scripts
# and the monorepo filter keep working. The preferred publish runs
# first from the unchanged manifest. The second publish temporarily
# rewrites the name to `@huly-cli/cli`, publishes, and an EXIT trap
# restores only the `name` field — leaving the version bump in place
# so the `Commit & tag version bump` step below can commit it.
- name: Publish @iamcoder18/huly-cli (preferred)
id: publish_legacy
if: ${{ !inputs.dry_run }}
env:
TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
pnpm publish --filter @iamcoder18/huly-cli --access public --tag "$TAG" --no-git-checks
- name: Publish @huly-cli/cli
id: publish_new
if: ${{ !inputs.dry_run }}
env:
TAG: ${{ inputs.tag }}
ORIGINAL_NAME: '@iamcoder18/huly-cli'
run: |
set -euo pipefail
# Always restore the original `name` field on exit (success or
# failure) so a failed publish can't leak the temporary rename
# into the subsequent `Commit & tag version bump` step.
trap 'cd "$GITHUB_WORKSPACE/packages/cli" && npm pkg set "name=$ORIGINAL_NAME" >/dev/null 2>&1 || true' EXIT
cd "$GITHUB_WORKSPACE/packages/cli"
npm pkg set name=@huly-cli/cli
npm publish --access public --tag "$TAG"
- name: Commit & tag version bump
if: ${{ !inputs.dry_run && steps.version.outputs.target != steps.version.outputs.current }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add packages/cli/package.json pnpm-lock.yaml
git commit -m "chore(release): v${{ steps.version.outputs.target }}"
git tag "v${{ steps.version.outputs.target }}"
git push
git push --tags
- name: Summary
if: always()
env:
DRY_RUN: ${{ inputs.dry_run }}
LEGACY_RESULT: ${{ steps.publish_legacy.conclusion }}
NEW_RESULT: ${{ steps.publish_new.conclusion }}
run: |
{
echo "### Publish summary"
echo
echo "- Previous version: \`${{ steps.version.outputs.current }}\`"
echo "- Target version: \`${{ steps.version.outputs.target }}\`"
echo "- Bump kind: \`${{ steps.version.outputs.bump }}\`"
echo "- Tag: \`${{ inputs.tag }}\`"
echo "- Dry run: \`${{ inputs.dry_run }}\`"
published=()
if [ "$DRY_RUN" != "true" ] && [ "$LEGACY_RESULT" = "success" ]; then
published+=("\`@iamcoder18/huly-cli\` (preferred)")
fi
if [ "$DRY_RUN" != "true" ] && [ "$NEW_RESULT" = "success" ]; then
published+=("\`@huly-cli/cli\`")
fi
if [ "${#published[@]}" -eq 0 ]; then
echo "- Published names: _none_"
else
joined=$(IFS=', '; echo "${published[*]}")
echo "- Published names: ${joined}"
fi
} >> "$GITHUB_STEP_SUMMARY"