feat: more message related logs #52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish npm Package | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| jobs: | |
| resolve-publish-context: | |
| name: Resolve publish context | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| dev_build_ref: ${{ steps.context.outputs.dev_build_ref }} | |
| dev_version: ${{ steps.context.outputs.dev_version }} | |
| release_build_ref: ${{ steps.context.outputs.release_build_ref }} | |
| release_version: ${{ steps.context.outputs.release_version }} | |
| should_publish_release: ${{ steps.context.outputs.should_publish_release }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve version and tags | |
| id: context | |
| env: | |
| REF_NAME: ${{ github.ref_name }} | |
| REF_TYPE: ${{ github.ref_type }} | |
| SHA: ${{ github.sha }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| read_version() { | |
| local target="$1" | |
| if [[ "$target" == "WORKTREE" ]]; then | |
| node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version" | |
| else | |
| git show "${target}:package.json" | node -p "let data=''; process.stdin.on('data', c => data += c); process.stdin.on('end', () => console.log(JSON.parse(data).version));" | |
| fi | |
| } | |
| create_tag_if_needed() { | |
| local commit="$1" | |
| local version="$2" | |
| local tag="v${version}" | |
| if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then | |
| local existing_commit | |
| existing_commit=$(git rev-list -n 1 "${tag}") | |
| if [[ "${existing_commit}" == "${commit}" ]]; then | |
| echo "${tag} already points to ${commit}." | |
| return | |
| fi | |
| echo "${tag} already exists on ${existing_commit}; refusing to reuse version ${version}." >&2 | |
| exit 1 | |
| fi | |
| git tag "${tag}" "${commit}" | |
| git push origin "refs/tags/${tag}" | |
| echo "Created ${tag} for ${commit}." | |
| } | |
| dev_build_ref="${SHA}" | |
| dev_version="0.0.0-dev.${SHA::12}" | |
| release_build_ref="" | |
| release_version="" | |
| should_publish_release="false" | |
| current_version=$(read_version WORKTREE) | |
| current_tag="v${current_version}" | |
| if [[ "${REF_TYPE}" == "tag" ]]; then | |
| release_build_ref="${SHA}" | |
| release_version="${current_version}" | |
| if [[ "${REF_NAME}" != "${current_tag}" ]]; then | |
| echo "Tag ${REF_NAME} does not match package.json version (${current_version})." >&2 | |
| exit 1 | |
| fi | |
| should_publish_release="true" | |
| elif ! git rev-parse -q --verify "refs/tags/${current_tag}" >/dev/null; then | |
| release_build_ref="${SHA}" | |
| release_version="${current_version}" | |
| create_tag_if_needed "${SHA}" "${release_version}" | |
| should_publish_release="true" | |
| fi | |
| echo "dev_build_ref=${dev_build_ref}" >> "${GITHUB_OUTPUT}" | |
| echo "dev_version=${dev_version}" >> "${GITHUB_OUTPUT}" | |
| echo "release_build_ref=${release_build_ref}" >> "${GITHUB_OUTPUT}" | |
| echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}" | |
| echo "should_publish_release=${should_publish_release}" >> "${GITHUB_OUTPUT}" | |
| prepare-release: | |
| name: Prepare GitHub release | |
| if: needs.resolve-publish-context.outputs.should_publish_release == 'true' | |
| runs-on: ubuntu-latest | |
| needs: resolve-publish-context | |
| permissions: | |
| contents: write | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| RELEASE_TAG: v${{ needs.resolve-publish-context.outputs.release_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Ensure GitHub release exists | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then | |
| echo "GitHub release already exists for $RELEASE_TAG." | |
| else | |
| gh release create "$RELEASE_TAG" --title "$RELEASE_TAG" --generate-notes | |
| fi | |
| publish-dev-package: | |
| name: Publish dev package | |
| if: github.ref_type != 'tag' | |
| runs-on: ubuntu-latest | |
| needs: resolve-publish-context | |
| concurrency: | |
| group: npm-publish-dev | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| env: | |
| VERSION: ${{ needs.resolve-publish-context.outputs.dev_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ needs.resolve-publish-context.outputs.dev_build_ref }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| shell: bash | |
| run: bun install --frozen-lockfile | |
| - name: Build | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| bun run build | |
| - name: Prepare dev package version | |
| shell: bash | |
| run: npm version "$VERSION" --no-git-tag-version | |
| - name: Publish dev package | |
| shell: bash | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| PACKAGE_NAME=$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).name") | |
| bash .github/scripts/publish-npm-with-retry.sh . "$PACKAGE_NAME" "$VERSION" dev | |
| publish-release-package: | |
| name: Publish release package | |
| if: needs.resolve-publish-context.outputs.should_publish_release == 'true' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - resolve-publish-context | |
| - prepare-release | |
| concurrency: | |
| group: npm-publish-release | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| VERSION: ${{ needs.resolve-publish-context.outputs.release_version }} | |
| RELEASE_TAG: v${{ needs.resolve-publish-context.outputs.release_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ needs.resolve-publish-context.outputs.release_build_ref }} | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| shell: bash | |
| run: bun install --frozen-lockfile | |
| - name: Build | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| actual_version=$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version") | |
| if [[ "$actual_version" != "$VERSION" ]]; then | |
| echo "package.json version $actual_version does not match release version $VERSION" >&2 | |
| exit 1 | |
| fi | |
| bun run build | |
| - name: Pack release artifact | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p release-assets | |
| npm pack --pack-destination release-assets | |
| - name: Publish release package | |
| shell: bash | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| PACKAGE_NAME=$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).name") | |
| bash .github/scripts/publish-npm-with-retry.sh . "$PACKAGE_NAME" "$VERSION" latest | |
| - name: Upload release artifact | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| gh release upload "$RELEASE_TAG" release-assets/*.tgz --clobber |