From b08de805ba41c226fc5f2fd28889aee769e96665 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 13:56:22 +0900 Subject: [PATCH 1/9] Refactor release workflow to update version and CHANGELOG handling --- .github/changelog_template.md | 11 ---- .github/workflows/main.yml | 1 - .github/workflows/release.yml | 116 +++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 .github/changelog_template.md diff --git a/.github/changelog_template.md b/.github/changelog_template.md deleted file mode 100644 index 550176e..0000000 --- a/.github/changelog_template.md +++ /dev/null @@ -1,11 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [{{VERSION}}] - {{DATE}} - -{{RELEASE_NOTES}} - diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9d279e..c36d729 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,7 +39,6 @@ jobs: - name: Set Rails version run: | echo "RAILS_VERSION=${{ matrix.rails }}" >> $GITHUB_ENV - bundle config set --local gemfile Gemfile - name: Install dependencies run: | bundle install --jobs 4 --retry 3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 637890e..89b3c36 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,89 +1,101 @@ name: Release on: - release: - types: [published] + push: + tags: + - 'v*' jobs: - release: + update-version-and-release: runs-on: ubuntu-latest permissions: contents: write - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + steps: - - uses: actions/checkout@v5 + - name: Checkout code + uses: actions/checkout@v5 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - ref: main # Ensure we checkout main branch explicitly - - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.4' - bundler-cache: true - name: Extract version from tag - id: version + id: extract_version run: | - VERSION=${GITHUB_REF#refs/tags/v} + TAG_NAME=${GITHUB_REF#refs/tags/} + VERSION=${TAG_NAME#v} echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT - - name: Validate version consistency + - name: Update version file run: | - GEMSPEC_VERSION=$(ruby -r "./lib/structured_params/version" -e "puts StructuredParams::VERSION") - if [ "$GEMSPEC_VERSION" != "${{ steps.version.outputs.version }}" ]; then - echo "Version mismatch: tag ${{ steps.version.outputs.version }} vs gemspec $GEMSPEC_VERSION" - exit 1 - fi + VERSION="${{ steps.extract_version.outputs.version }}" + sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb - - name: Build gem - run: gem build structured_params.gemspec - - - name: Publish to RubyGems - uses: rubygems/release-gem@v1 - # No API key needed with trusted publishing! - - - name: Update CHANGELOG + - name: Extract release notes from GitHub release + id: release_notes run: | - # Extract release notes from GitHub release RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.version.outputs.tag_name }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.extract_version.outputs.tag_name }}" \ | jq -r '.body // ""') - # Get current date + # Escape newlines and quotes for use in sed + RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n$//' | sed 's/"/\\"/g') + echo "release_notes=$RELEASE_NOTES" >> $GITHUB_OUTPUT + + - name: Update CHANGELOG + run: | + VERSION="${{ steps.extract_version.outputs.version }}" CURRENT_DATE=$(date +%Y-%m-%d) + RELEASE_NOTES="${{ steps.release_notes.outputs.release_notes }}" - # Create new changelog entry using template with safer substitution - # Use | as delimiter instead of / to avoid conflicts with URLs in release notes - sed -e "s|{{VERSION}}|${{ steps.version.outputs.version }}|g" \ - -e "s|{{DATE}}|$CURRENT_DATE|g" \ - .github/changelog_template.md > temp_changelog.md - - # Add release notes separately to avoid sed escaping issues + # Create temporary changelog entry + echo "## [$VERSION] - $CURRENT_DATE" > temp_changelog.md + echo "" >> temp_changelog.md if [ -n "$RELEASE_NOTES" ]; then - # Replace the placeholder with actual release notes - awk -v notes="$RELEASE_NOTES" '{gsub(/{{RELEASE_NOTES}}/, notes); print}' temp_changelog.md > temp_changelog2.md - mv temp_changelog2.md temp_changelog.md + echo -e "$RELEASE_NOTES" >> temp_changelog.md else - # Remove the placeholder if no release notes - sed -i 's/{{RELEASE_NOTES}}//' temp_changelog.md + echo "- Release $VERSION" >> temp_changelog.md fi - - # Append existing changelog content (skip the header) echo "" >> temp_changelog.md - tail -n +9 CHANGELOG.md >> temp_changelog.md - mv temp_changelog.md CHANGELOG.md + + # Prepend to existing CHANGELOG (skip the header) + if [ -f CHANGELOG.md ]; then + tail -n +3 CHANGELOG.md >> temp_changelog.md + fi + + # Add header back + echo "# Changelog" > CHANGELOG.md + echo "" >> CHANGELOG.md + cat temp_changelog.md >> CHANGELOG.md + rm temp_changelog.md - - name: Commit and push CHANGELOG update + - name: Commit version and CHANGELOG updates run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git add CHANGELOG.md + git add lib/structured_params/version.rb CHANGELOG.md if git diff --staged --quiet; then echo "No changes to commit" else - git commit -m "Update CHANGELOG for v${{ steps.version.outputs.version }}" - git push origin HEAD:main + git commit -m "Release ${{ steps.extract_version.outputs.tag_name }}: Update version and CHANGELOG" + git push origin main fi + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + + - name: Build gem + run: | + gem build structured_params.gemspec + + - name: Publish to RubyGems + run: | + mkdir -p ~/.gem + echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials + chmod 0600 ~/.gem/credentials + gem push structured_params-*.gem + env: + RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} From 7d7b185f4c186afe42807faf34c5e0ac8356254f Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 13:58:25 +0900 Subject: [PATCH 2/9] Update release workflow to include id-token permissions --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 89b3c36..07bc44f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + id-token: write steps: - name: Checkout code From 51c62938f560411048a57acb286d9642b172f86a Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 13:59:29 +0900 Subject: [PATCH 3/9] Update .github/workflows/release.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07bc44f..a25b1e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,7 @@ jobs: - name: Checkout code uses: actions/checkout@v5 with: + ref: main fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} From 8c060536b7e649ff6826690f39716fb3e8b9ad2a Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:19:01 +0900 Subject: [PATCH 4/9] Add Git configuration action and update release workflow for CHANGELOG management --- .github/actions/configure-git/action.yml | 11 +++++ .github/workflows/release.yml | 63 +++++++++--------------- .github/workflows/tagging.yml | 45 +++++++++++++++++ 3 files changed, 79 insertions(+), 40 deletions(-) create mode 100644 .github/actions/configure-git/action.yml create mode 100644 .github/workflows/tagging.yml diff --git a/.github/actions/configure-git/action.yml b/.github/actions/configure-git/action.yml new file mode 100644 index 0000000..ae80d89 --- /dev/null +++ b/.github/actions/configure-git/action.yml @@ -0,0 +1,11 @@ +name: 'Configure Git for GitHub Actions' +description: 'Configure Git user for automated commits' + +runs: + using: 'composite' + steps: + - name: Configure Git + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07bc44f..aba5527 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,61 +1,49 @@ -name: Release +name: Release and Publish on: - push: - tags: - - 'v*' + release: + types: [published] jobs: - update-version-and-release: + update-changelog-and-publish: runs-on: ubuntu-latest permissions: contents: write - id-token: write + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - name: Checkout code uses: actions/checkout@v5 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} + ref: main - - name: Extract version from tag + - name: Configure Git + uses: ./.github/actions/configure-git + + - name: Extract version from release id: extract_version run: | - TAG_NAME=${GITHUB_REF#refs/tags/} + TAG_NAME=${{ github.event.release.tag_name }} VERSION=${TAG_NAME#v} echo "version=$VERSION" >> $GITHUB_OUTPUT echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT - - name: Update version file - run: | - VERSION="${{ steps.extract_version.outputs.version }}" - sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb - - - name: Extract release notes from GitHub release - id: release_notes - run: | - RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.extract_version.outputs.tag_name }}" \ - | jq -r '.body // ""') - - # Escape newlines and quotes for use in sed - RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n$//' | sed 's/"/\\"/g') - echo "release_notes=$RELEASE_NOTES" >> $GITHUB_OUTPUT - - name: Update CHANGELOG run: | VERSION="${{ steps.extract_version.outputs.version }}" CURRENT_DATE=$(date +%Y-%m-%d) - RELEASE_NOTES="${{ steps.release_notes.outputs.release_notes }}" + RELEASE_NOTES="${{ github.event.release.body }}" # Create temporary changelog entry echo "## [$VERSION] - $CURRENT_DATE" > temp_changelog.md echo "" >> temp_changelog.md + + # Add release notes from GitHub release if [ -n "$RELEASE_NOTES" ]; then - echo -e "$RELEASE_NOTES" >> temp_changelog.md + echo "$RELEASE_NOTES" >> temp_changelog.md else - echo "- Release $VERSION" >> temp_changelog.md + echo "- Release ${{ steps.extract_version.outputs.tag_name }}" >> temp_changelog.md fi echo "" >> temp_changelog.md @@ -68,17 +56,17 @@ jobs: echo "# Changelog" > CHANGELOG.md echo "" >> CHANGELOG.md cat temp_changelog.md >> CHANGELOG.md - rm temp_changelog.md + + # Clean up temporary file + rm -f temp_changelog.md - - name: Commit version and CHANGELOG updates + - name: Commit CHANGELOG update run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add lib/structured_params/version.rb CHANGELOG.md + git add CHANGELOG.md if git diff --staged --quiet; then - echo "No changes to commit" + echo "No CHANGELOG changes to commit" else - git commit -m "Release ${{ steps.extract_version.outputs.tag_name }}: Update version and CHANGELOG" + git commit -m "Update CHANGELOG for ${{ steps.extract_version.outputs.tag_name }}" git push origin main fi @@ -94,9 +82,4 @@ jobs: - name: Publish to RubyGems run: | - mkdir -p ~/.gem - echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials - chmod 0600 ~/.gem/credentials gem push structured_params-*.gem - env: - RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml new file mode 100644 index 0000000..3660ddf --- /dev/null +++ b/.github/workflows/tagging.yml @@ -0,0 +1,45 @@ +name: Update Version + +on: + push: + tags: + - 'v*' + +jobs: + update-version: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + ref: main + + - name: Configure Git + uses: ./.github/actions/configure-git + + - name: Extract version from tag + id: extract_version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + VERSION=${TAG_NAME#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + + - name: Update version file + run: | + VERSION="${{ steps.extract_version.outputs.version }}" + sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb + + - name: Commit version update + run: | + git add lib/structured_params/version.rb + if git diff --staged --quiet; then + echo "No version changes to commit" + else + git commit -m "Update version to ${{ steps.extract_version.outputs.version }}" + git push origin main + fi From 5b3bb1a5efc7f078335acb92921b611b06f6d225 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:21:09 +0900 Subject: [PATCH 5/9] Update .github/workflows/release.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8beef3d..b772447 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,6 @@ jobs: with: ref: main fetch-depth: 0 - ref: main - name: Configure Git uses: ./.github/actions/configure-git From 9f85b1bcc37ae949481ad1f1b1b2bdad29da205e Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:22:11 +0900 Subject: [PATCH 6/9] Refactor GitHub Actions workflows for improved readability and consistency --- .github/workflows/main.yml | 32 ++++----- .github/workflows/release.yml | 130 +++++++++++++++++----------------- .github/workflows/tagging.yml | 54 +++++++------- 3 files changed, 108 insertions(+), 108 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c36d729..4a8a8e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,19 +30,19 @@ jobs: rails: '~> 8.0.0' steps: - - uses: actions/checkout@v5 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: false - - name: Set Rails version - run: | - echo "RAILS_VERSION=${{ matrix.rails }}" >> $GITHUB_ENV - - name: Install dependencies - run: | - bundle install --jobs 4 --retry 3 - env: - RAILS_VERSION: ${{ matrix.rails }} - - name: Run the default task - run: bundle exec rake + - uses: actions/checkout@v5 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: false + - name: Set Rails version + run: | + echo "RAILS_VERSION=${{ matrix.rails }}" >> $GITHUB_ENV + - name: Install dependencies + run: | + bundle install --jobs 4 --retry 3 + env: + RAILS_VERSION: ${{ matrix.rails }} + - name: Run the default task + run: bundle exec rake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b772447..bccf5af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release and Publish on: release: - types: [published] + types: [ published ] jobs: update-changelog-and-publish: @@ -12,74 +12,74 @@ jobs: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - ref: main - fetch-depth: 0 + - name: Checkout code + uses: actions/checkout@v5 + with: + ref: main + fetch-depth: 0 - - name: Configure Git - uses: ./.github/actions/configure-git + - name: Configure Git + uses: ./.github/actions/configure-git - - name: Extract version from release - id: extract_version - run: | - TAG_NAME=${{ github.event.release.tag_name }} - VERSION=${TAG_NAME#v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + - name: Extract version from release + id: extract_version + run: | + TAG_NAME=${{ github.event.release.tag_name }} + VERSION=${TAG_NAME#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT - - name: Update CHANGELOG - run: | - VERSION="${{ steps.extract_version.outputs.version }}" - CURRENT_DATE=$(date +%Y-%m-%d) - RELEASE_NOTES="${{ github.event.release.body }}" - - # Create temporary changelog entry - echo "## [$VERSION] - $CURRENT_DATE" > temp_changelog.md - echo "" >> temp_changelog.md - - # Add release notes from GitHub release - if [ -n "$RELEASE_NOTES" ]; then - echo "$RELEASE_NOTES" >> temp_changelog.md - else - echo "- Release ${{ steps.extract_version.outputs.tag_name }}" >> temp_changelog.md - fi - echo "" >> temp_changelog.md - - # Prepend to existing CHANGELOG (skip the header) - if [ -f CHANGELOG.md ]; then - tail -n +3 CHANGELOG.md >> temp_changelog.md - fi - - # Add header back - echo "# Changelog" > CHANGELOG.md - echo "" >> CHANGELOG.md - cat temp_changelog.md >> CHANGELOG.md - - # Clean up temporary file - rm -f temp_changelog.md + - name: Update CHANGELOG + run: | + VERSION="${{ steps.extract_version.outputs.version }}" + CURRENT_DATE=$(date +%Y-%m-%d) + RELEASE_NOTES="${{ github.event.release.body }}" + + # Create temporary changelog entry + echo "## [$VERSION] - $CURRENT_DATE" > temp_changelog.md + echo "" >> temp_changelog.md + + # Add release notes from GitHub release + if [ -n "$RELEASE_NOTES" ]; then + echo "$RELEASE_NOTES" >> temp_changelog.md + else + echo "- Release ${{ steps.extract_version.outputs.tag_name }}" >> temp_changelog.md + fi + echo "" >> temp_changelog.md + + # Prepend to existing CHANGELOG (skip the header) + if [ -f CHANGELOG.md ]; then + tail -n +3 CHANGELOG.md >> temp_changelog.md + fi + + # Add header back + echo "# Changelog" > CHANGELOG.md + echo "" >> CHANGELOG.md + cat temp_changelog.md >> CHANGELOG.md + + # Clean up temporary file + rm -f temp_changelog.md - - name: Commit CHANGELOG update - run: | - git add CHANGELOG.md - if git diff --staged --quiet; then - echo "No CHANGELOG changes to commit" - else - git commit -m "Update CHANGELOG for ${{ steps.extract_version.outputs.tag_name }}" - git push origin main - fi + - name: Commit CHANGELOG update + run: | + git add CHANGELOG.md + if git diff --staged --quiet; then + echo "No CHANGELOG changes to commit" + else + git commit -m "Update CHANGELOG for ${{ steps.extract_version.outputs.tag_name }}" + git push origin main + fi - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.4' - bundler-cache: true + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true - - name: Build gem - run: | - gem build structured_params.gemspec + - name: Build gem + run: | + gem build structured_params.gemspec - - name: Publish to RubyGems - run: | - gem push structured_params-*.gem + - name: Publish to RubyGems + run: | + gem push structured_params-*.gem diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml index 3660ddf..8fc1e11 100644 --- a/.github/workflows/tagging.yml +++ b/.github/workflows/tagging.yml @@ -12,34 +12,34 @@ jobs: contents: write steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - fetch-depth: 0 - ref: main + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + ref: main - - name: Configure Git - uses: ./.github/actions/configure-git + - name: Configure Git + uses: ./.github/actions/configure-git - - name: Extract version from tag - id: extract_version - run: | - TAG_NAME=${GITHUB_REF#refs/tags/} - VERSION=${TAG_NAME#v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT + - name: Extract version from tag + id: extract_version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + VERSION=${TAG_NAME#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT - - name: Update version file - run: | - VERSION="${{ steps.extract_version.outputs.version }}" - sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb + - name: Update version file + run: | + VERSION="${{ steps.extract_version.outputs.version }}" + sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb - - name: Commit version update - run: | - git add lib/structured_params/version.rb - if git diff --staged --quiet; then - echo "No version changes to commit" - else - git commit -m "Update version to ${{ steps.extract_version.outputs.version }}" - git push origin main - fi + - name: Commit version update + run: | + git add lib/structured_params/version.rb + if git diff --staged --quiet; then + echo "No version changes to commit" + else + git commit -m "Update version to ${{ steps.extract_version.outputs.version }}" + git push origin main + fi From 99ca0110696036926c3e293bb0f59cd25916bf8a Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:26:10 +0900 Subject: [PATCH 7/9] Enhance gem build and publish steps in release workflow for better error handling --- .github/workflows/release.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bccf5af..cb15a70 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,9 +77,16 @@ jobs: bundler-cache: true - name: Build gem + id: build_gem run: | - gem build structured_params.gemspec + gem_file=$(gem build structured_params.gemspec | awk '/File:/ {print $2}') + echo "gem_file=$gem_file" >> $GITHUB_OUTPUT - name: Publish to RubyGems run: | - gem push structured_params-*.gem + gem_file="${{ steps.build_gem.outputs.gem_file }}" + if [ -z "$gem_file" ]; then + echo "Error: Gem file not found." + exit 1 + fi + gem push "$gem_file" From b9caeaaf577b79addbed0768fe6901be15ad742f Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:28:42 +0900 Subject: [PATCH 8/9] Update .github/workflows/release.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb15a70..b191733 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -80,7 +80,7 @@ jobs: id: build_gem run: | gem_file=$(gem build structured_params.gemspec | awk '/File:/ {print $2}') - echo "gem_file=$gem_file" >> $GITHUB_OUTPUT + echo "gem_file=$gem_file" >> $GITHUB_OUTPUT - name: Publish to RubyGems run: | From 91ea2c9c64e41bdceb78972f8bbd5aa0dc5280f8 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Sat, 6 Sep 2025 14:29:07 +0900 Subject: [PATCH 9/9] Update .github/workflows/release.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b191733..ee13b07 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,11 +82,7 @@ jobs: gem_file=$(gem build structured_params.gemspec | awk '/File:/ {print $2}') echo "gem_file=$gem_file" >> $GITHUB_OUTPUT - - name: Publish to RubyGems - run: | - gem_file="${{ steps.build_gem.outputs.gem_file }}" - if [ -z "$gem_file" ]; then - echo "Error: Gem file not found." - exit 1 - fi - gem push "$gem_file" + - name: Publish to RubyGems (trusted publishing) + uses: rubygems/release-gem@v1 + with: + gem_file: ${{ steps.build_gem.outputs.gem_file }}