@@ -139,6 +139,14 @@ jobs:
139139 echo "version=$version" >> "$GITHUB_OUTPUT"
140140 echo "tag=$tag" >> "$GITHUB_OUTPUT"
141141
142+ - name : Ensure workflow runs on branch
143+ run : |
144+ if [[ '${{ github.ref_type }}' != 'branch' ]]; then
145+ echo "This workflow must run on a branch ref to push version updates."
146+ echo "Current ref_type: ${{ github.ref_type }}"
147+ exit 1
148+ fi
149+
142150 - name : Update package version
143151 run : |
144152 node -e "const fs=require('fs');const path='packages/${{ steps.metadata.outputs.package }}/package.json';const version='${{ steps.metadata.outputs.version }}';const pkg=JSON.parse(fs.readFileSync(path,'utf8'));pkg.version=version;const hasPrivate=Object.prototype.hasOwnProperty.call(pkg,'private');if(hasPrivate&&(pkg.name==='create-hikkaku'||pkg.name==='vite-plugin-turbowarp-packager')){pkg.private=false;}fs.writeFileSync(path,JSON.stringify(pkg,null,2)+'\n');"
@@ -159,30 +167,82 @@ jobs:
159167 if : steps.metadata.outputs.package == 'hikkaku'
160168 run : bun run --filter gpts-zip build
161169
162- - name : Publish hikkaku to npm
163- if : steps.metadata.outputs.package == 'hikkaku'
164- run : npm publish --provenance --access public
165- working-directory : packages/hikkaku/dist
170+ - name : Resolve publish directory
171+ id : publish_dir
172+ shell : bash
173+ run : |
174+ case '${{ steps.metadata.outputs.package }}' in
175+ hikkaku)
176+ dir='packages/hikkaku/dist'
177+ ;;
178+ create-hikkaku)
179+ dir='packages/create-hikkaku'
180+ ;;
181+ vite-plugin-turbowarp-packager)
182+ dir='packages/vite-plugin-turbowarp-packager'
183+ ;;
184+ *)
185+ echo "Unsupported package: ${{ steps.metadata.outputs.package }}"
186+ exit 1
187+ ;;
188+ esac
166189
167- - name : Publish create-hikkaku to npm
168- if : steps.metadata.outputs.package == 'create-hikkaku'
169- run : npm publish --provenance --access public
170- working-directory : packages/create-hikkaku
190+ echo "dir=$dir" >> "$GITHUB_OUTPUT"
171191
172- - name : Publish vite-plugin-turbowarp-packager to npm
173- if : steps.metadata.outputs.package == 'vite-plugin-turbowarp-packager'
174- run : npm publish --provenance --access public
175- working-directory : packages/vite-plugin-turbowarp-packager
192+ - name : Pack package tarball
193+ id : pack
194+ shell : bash
195+ run : |
196+ publish_dir='${{ steps.publish_dir.outputs.dir }}'
197+ tarball_output="$(cd "$publish_dir" && bun pm pack --quiet --destination "$RUNNER_TEMP")"
198+ tarball_output="$(echo "$tarball_output" | tr -d '\n')"
199+
200+ if [[ "$tarball_output" = /* ]]; then
201+ tarball_path="$tarball_output"
202+ else
203+ tarball_path="$RUNNER_TEMP/$tarball_output"
204+ fi
205+
206+ if [[ ! -f "$tarball_path" ]]; then
207+ echo "Tarball was not generated at expected path: $tarball_path"
208+ exit 1
209+ fi
210+
211+ echo "path=$tarball_path" >> "$GITHUB_OUTPUT"
212+
213+ - name : Publish package tarball to npm
214+ run : npm publish '${{ steps.pack.outputs.path }}' --provenance --access public
215+
216+ - name : Commit and push version update
217+ id : version_commit
218+ shell : bash
219+ run : |
220+ file_path="packages/${{ steps.metadata.outputs.package }}/package.json"
221+
222+ git config user.name 'github-actions[bot]'
223+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
224+
225+ git add "$file_path"
226+
227+ if git diff --cached --quiet; then
228+ echo "No version updates to commit."
229+ echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
230+ exit 0
231+ fi
232+
233+ git commit -m 'chore(release): bump ${{ steps.metadata.outputs.package }} to v${{ steps.metadata.outputs.version }}'
234+ git push origin "HEAD:${{ github.ref_name }}"
235+ echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
176236
177237 - name : Create release with generated notes
178238 run : |
179239 if [[ '${{ steps.metadata.outputs.package }}' == 'hikkaku' ]]; then
180240 gh release create '${{ steps.metadata.outputs.tag }}' \
181241 'packages/gpts-zip/dist.zip#gpts.zip' \
182242 --generate-notes \
183- --target '${{ github .sha }}'
243+ --target '${{ steps.version_commit.outputs .sha }}'
184244 else
185245 gh release create '${{ steps.metadata.outputs.tag }}' \
186246 --generate-notes \
187- --target '${{ github .sha }}'
247+ --target '${{ steps.version_commit.outputs .sha }}'
188248 fi
0 commit comments