diff --git a/.github/workflows/build-deploy-publish.yml b/.github/workflows/build-deploy-publish.yml index ddc5f9b..be0345a 100644 --- a/.github/workflows/build-deploy-publish.yml +++ b/.github/workflows/build-deploy-publish.yml @@ -12,6 +12,7 @@ jobs: permissions: contents: write id-token: write + pull-requests: write steps: - uses: actions/checkout@v4 with: @@ -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 + diff --git a/README.md b/README.md index eb1364a..b30effd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package-lock.json b/package-lock.json index 1ea0c0f..a25ba0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -769,7 +769,8 @@ }, "node_modules/webidl2ts": { "version": "1.0.4", - "resolved": "git+ssh://git@github.com/toji/webidl2ts.git#d6d7e68a0e59e2c716b058ea437f7f49958a0e56", + "resolved": "git+ssh://git@github.com/toji/webidl2ts.git#9596655fbb3fd6147e1990304c7aa7b84ae0b71b", + "integrity": "sha512-Q4p/X615ifVpjPd9uQ2wrGAgQBAORZrTWRqG9ccsscpezWc76NHMpi2kIc8L1pQjLoRtJ+suY9/RFV1bmudRsQ==", "dev": true, "license": "MIT", "dependencies": { @@ -912,7 +913,7 @@ "dependencies": { "typescript": "=4.2.4", "webidl2": "^24.2.0", - "webidl2ts": "github:toji/webidl2ts", + "webidl2ts": "github:toji/webidl2ts#9596655fbb3fd6147e1990304c7aa7b84ae0b71b", "yargs": "^16.2.0" }, "bin": { @@ -998,7 +999,7 @@ "requires": { "typescript": "=4.2.4", "webidl2": "^24.2.0", - "webidl2ts": "github:toji/webidl2ts", + "webidl2ts": "github:toji/webidl2ts#9596655fbb3fd6147e1990304c7aa7b84ae0b71b", "yargs": "^16.2.0" } }, @@ -1509,9 +1510,10 @@ "dev": true }, "webidl2ts": { - "version": "git+ssh://git@github.com/toji/webidl2ts.git#d6d7e68a0e59e2c716b058ea437f7f49958a0e56", + "version": "git+ssh://git@github.com/toji/webidl2ts.git#9596655fbb3fd6147e1990304c7aa7b84ae0b71b", + "integrity": "sha512-Q4p/X615ifVpjPd9uQ2wrGAgQBAORZrTWRqG9ccsscpezWc76NHMpi2kIc8L1pQjLoRtJ+suY9/RFV1bmudRsQ==", "dev": true, - "from": "webidl2ts@github:toji/webidl2ts", + "from": "webidl2ts@github:toji/webidl2ts#9596655fbb3fd6147e1990304c7aa7b84ae0b71b", "requires": { "jsdom": "^16.4.0", "typescript": "^4.2.2", diff --git a/package.json b/package.json index 49809b6..9df0073 100644 --- a/package.json +++ b/package.json @@ -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",