Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions .github/workflows/build-deploy-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
permissions:
contents: write
id-token: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -39,23 +40,49 @@ jobs:
FOLDER: tsdoc-src/out

- name: Publish package to NPM
if: ${{ success() && github.ref == 'refs/heads/main' }}
id: publish
if: ${{ success() && github.repository == 'gpuweb/types' && github.ref == 'refs/heads/main' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_VERSION=$(npm view @webgpu/types version)
git fetch --depth=1 origin tag "v${LATEST_VERSION}"
if git diff --quiet "v${LATEST_VERSION}" -- dist/index.d.ts; then
echo "dist/index.d.ts has not changed since v${LATEST_VERSION}; skipping publish."
git fetch --depth=1 --tags origin
LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -n 1)
echo "latest_tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT"
if git diff --quiet "${LATEST_TAG}" -- dist/index.d.ts; then
echo "dist/index.d.ts has not changed since ${LATEST_TAG}; skipping publish."
exit 0
fi

npm pkg set version="${LATEST_VERSION}"
npm pkg set version="${LATEST_TAG#v}"
NEW_VERSION=$(npm version patch --no-git-tag-version)
echo "Publishing new version: ${NEW_VERSION}"

npm publish
echo "new_version=${NEW_VERSION#v}" >> "$GITHUB_OUTPUT"

git tag "${NEW_VERSION}"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "${NEW_VERSION}"

- name: Comment on merged PR
if: ${{ (success() || failure()) && github.repository == 'gpuweb/types' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JOB_STATUS: ${{ job.status }}
LATEST_TAG: ${{ steps.publish.outputs.latest_tag }}
NEW_VERSION: ${{ steps.publish.outputs.new_version }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
PR_NUMBER=$(gh api "/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" --jq '.[0].number // empty')
if [ -z "${PR_NUMBER}" ]; then
echo "No associated PR found for commit ${GITHUB_SHA}; skipping PR comment."
exit 0
fi

if [ "${JOB_STATUS}" != "success" ]; then
gh pr comment "${PR_NUMBER}" --body "⚠️ Post-merge \`build-deploy-publish\` workflow failed on \`main\`: [workflow run](${RUN_URL})"
elif [ -n "${NEW_VERSION}" ]; then
gh pr comment "${PR_NUMBER}" --body "📦 Published [\`@webgpu/types@${NEW_VERSION}\`](https://www.npmjs.com/package/@webgpu/types/v/${NEW_VERSION}) ([workflow run](${RUN_URL}))."
else
gh pr comment "${PR_NUMBER}" --body "ℹ️ \`dist/index.d.ts\` has not changed since \`${LATEST_TAG}\`; skipped NPM publish ([workflow run](${RUN_URL}))."
fi

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ The following differences will remain.

New patch releases are published to NPM and tagged in Git automatically by [GitHub Actions](.github/workflows/build-deploy-publish.yml) on pushes to `main` when `dist/index.d.ts` has changed since the last release.

`package.json` intentionally omits a `version` field in Git; the workflow fetches the latest published version from NPM, increments the patch version in CI, publishes the package, and pushes the new Git tag.
`package.json` intentionally omits a `version` field in Git; the workflow finds the latest version tag in Git, increments the patch version, publishes the package, and pushes the new Git tag.

12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "@webgpu/types",
"repository": "gpuweb/types",
"repository": {
"type": "git",
"url": "git+https://github.com/gpuweb/types.git"
},
"homepage": "https://github.com/gpuweb/types",
"bugs": "https://github.com/gpuweb/types/issues",
"version": "",
"main": "",
"types": "dist/index.d.ts",
"license": "BSD-3-Clause",
Expand Down
Loading