From 8fb013613edff2616bcd654dd6d9589ba72fd06a Mon Sep 17 00:00:00 2001 From: Peter Kosztolanyi Date: Mon, 8 Dec 2025 20:56:48 +0000 Subject: [PATCH 1/2] Automate release creation on package version bumps --- .github/workflows/release-on-version-bump.yml | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/release-on-version-bump.yml diff --git a/.github/workflows/release-on-version-bump.yml b/.github/workflows/release-on-version-bump.yml new file mode 100644 index 0000000..0c1f4d3 --- /dev/null +++ b/.github/workflows/release-on-version-bump.yml @@ -0,0 +1,80 @@ +name: Release on Version Bump + +on: + push: + branches: + - main + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Detect version bump + id: version + run: | + set -euo pipefail + + NEW_VERSION=$(jq -r .version precise/package.json) + + if git show HEAD^:precise/package.json >/tmp/previous-package.json 2>/dev/null; then + PREVIOUS_VERSION=$(jq -r .version /tmp/previous-package.json) + else + PREVIOUS_VERSION="" + fi + + { + echo "new_version=$NEW_VERSION" + echo "previous_version=$PREVIOUS_VERSION" + } >> "$GITHUB_OUTPUT" + + if [ "$NEW_VERSION" = "$PREVIOUS_VERSION" ]; then + echo "bumped=false" >> "$GITHUB_OUTPUT" + echo "No version bump detected; skipping release creation." + exit 0 + fi + + echo "bumped=true" >> "$GITHUB_OUTPUT" + + - name: Generate changelog + id: changelog + if: steps.version.outputs.bumped == 'true' + run: | + set -euo pipefail + + PREVIOUS_TAG=$(git tag --list "*.*.*" --sort=-v:refname | head -n 1 || true) + + if [ -n "$PREVIOUS_TAG" ]; then + RANGE="${PREVIOUS_TAG}..HEAD" + LOG=$(git log --no-merges --pretty=format:"- %s (%h)" "$RANGE") + else + LOG=$(git log --no-merges --pretty=format:"- %s (%h)") + fi + + if [ -z "$LOG" ]; then + LOG="Changelog not available." + fi + + { + echo "changelog<<'EOF'" + echo "$LOG" + echo "EOF" + } >> "$GITHUB_OUTPUT" + + - name: Create GitHub release + if: steps.version.outputs.bumped == 'true' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.version.outputs.new_version }} + name: ${{ steps.version.outputs.new_version }} + body: ${{ steps.changelog.outputs.changelog }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 525420ca174cc8590649f615c992c3f29b4084ee Mon Sep 17 00:00:00 2001 From: Peter Kosztolanyi Date: Tue, 9 Dec 2025 07:29:17 +0000 Subject: [PATCH 2/2] simplify things --- .github/workflows/release-on-version-bump.yml | 80 ------------------- .github/workflows/release.yml | 46 +++++++---- 2 files changed, 29 insertions(+), 97 deletions(-) delete mode 100644 .github/workflows/release-on-version-bump.yml diff --git a/.github/workflows/release-on-version-bump.yml b/.github/workflows/release-on-version-bump.yml deleted file mode 100644 index 0c1f4d3..0000000 --- a/.github/workflows/release-on-version-bump.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Release on Version Bump - -on: - push: - branches: - - main - -permissions: - contents: write - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Detect version bump - id: version - run: | - set -euo pipefail - - NEW_VERSION=$(jq -r .version precise/package.json) - - if git show HEAD^:precise/package.json >/tmp/previous-package.json 2>/dev/null; then - PREVIOUS_VERSION=$(jq -r .version /tmp/previous-package.json) - else - PREVIOUS_VERSION="" - fi - - { - echo "new_version=$NEW_VERSION" - echo "previous_version=$PREVIOUS_VERSION" - } >> "$GITHUB_OUTPUT" - - if [ "$NEW_VERSION" = "$PREVIOUS_VERSION" ]; then - echo "bumped=false" >> "$GITHUB_OUTPUT" - echo "No version bump detected; skipping release creation." - exit 0 - fi - - echo "bumped=true" >> "$GITHUB_OUTPUT" - - - name: Generate changelog - id: changelog - if: steps.version.outputs.bumped == 'true' - run: | - set -euo pipefail - - PREVIOUS_TAG=$(git tag --list "*.*.*" --sort=-v:refname | head -n 1 || true) - - if [ -n "$PREVIOUS_TAG" ]; then - RANGE="${PREVIOUS_TAG}..HEAD" - LOG=$(git log --no-merges --pretty=format:"- %s (%h)" "$RANGE") - else - LOG=$(git log --no-merges --pretty=format:"- %s (%h)") - fi - - if [ -z "$LOG" ]; then - LOG="Changelog not available." - fi - - { - echo "changelog<<'EOF'" - echo "$LOG" - echo "EOF" - } >> "$GITHUB_OUTPUT" - - - name: Create GitHub release - if: steps.version.outputs.bumped == 'true' - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ steps.version.outputs.new_version }} - name: ${{ steps.version.outputs.new_version }} - body: ${{ steps.changelog.outputs.changelog }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8343944..2a0ed9d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,33 +1,45 @@ -name: Publish Package to npmjs +name: Release and Publish on: - release: - types: [created] + push: + branches: + - main + +permissions: + contents: write jobs: - publish: + release-and-publish: runs-on: ubuntu-latest defaults: run: working-directory: precise steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Setup node - uses: actions/setup-node@v4 + - uses: actions/checkout@v6 with: - node-version: '22' - registry-url: 'https://registry.npmjs.org' + fetch-depth: 0 - - name: Install dependencies - run: npm ci + - id: version + uses: EndBug/version-check@v2 - - name: Build package - run: npm run build + - if: steps.version.outputs.changed == 'true' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.version.outputs.version }} + name: ${{ steps.version.outputs.version }} + generate_release_notes: true + + - if: steps.version.outputs.changed == 'true' + uses: actions/setup-node@v6 + with: + node-version: '24' + registry-url: https://registry.npmjs.org - - name: Publish to npm - run: npm publish + - if: steps.version.outputs.changed == 'true' + run: | + npm ci + npm run build + npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}