|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v5 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 17 | + |
| 18 | + - name: Set up Ruby |
| 19 | + uses: ruby/setup-ruby@v1 |
| 20 | + with: |
| 21 | + ruby-version: '3.4' |
| 22 | + bundler-cache: true |
| 23 | + |
| 24 | + - name: Extract version from tag |
| 25 | + id: version |
| 26 | + run: | |
| 27 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 28 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 29 | + echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + - name: Validate version consistency |
| 32 | + run: | |
| 33 | + GEMSPEC_VERSION=$(ruby -r "./lib/structured_params/version" -e "puts StructuredParams::VERSION") |
| 34 | + if [ "$GEMSPEC_VERSION" != "${{ steps.version.outputs.version }}" ]; then |
| 35 | + echo "Version mismatch: tag ${{ steps.version.outputs.version }} vs gemspec $GEMSPEC_VERSION" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Build gem |
| 40 | + run: gem build structured_params.gemspec |
| 41 | + |
| 42 | + - name: Publish to RubyGems |
| 43 | + run: | |
| 44 | + mkdir -p $HOME/.gem |
| 45 | + touch $HOME/.gem/credentials |
| 46 | + chmod 0600 $HOME/.gem/credentials |
| 47 | + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials |
| 48 | + gem push *.gem |
| 49 | + env: |
| 50 | + GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} |
| 51 | + |
| 52 | + - name: Update CHANGELOG |
| 53 | + run: | |
| 54 | + # Extract release notes from GitHub release |
| 55 | + RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 56 | + "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.version.outputs.tag_name }}" \ |
| 57 | + | jq -r '.body // ""') |
| 58 | + |
| 59 | + # Get current date |
| 60 | + CURRENT_DATE=$(date +%Y-%m-%d) |
| 61 | + |
| 62 | + # Create temporary file with new changelog entry |
| 63 | + cat > temp_changelog.md << EOF |
| 64 | +# Changelog |
| 65 | + |
| 66 | +All notable changes to this project will be documented in this file. |
| 67 | + |
| 68 | +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
| 69 | +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 70 | + |
| 71 | +## [${{ steps.version.outputs.version }}] - $CURRENT_DATE |
| 72 | + |
| 73 | +$RELEASE_NOTES |
| 74 | + |
| 75 | +EOF |
| 76 | + |
| 77 | + # Append existing changelog content (skip the header) |
| 78 | + tail -n +9 CHANGELOG.md >> temp_changelog.md |
| 79 | + mv temp_changelog.md CHANGELOG.md |
| 80 | + |
| 81 | + - name: Commit and push CHANGELOG update |
| 82 | + run: | |
| 83 | + git config --local user.email "action@github.com" |
| 84 | + git config --local user.name "GitHub Action" |
| 85 | + git add CHANGELOG.md |
| 86 | + if git diff --staged --quiet; then |
| 87 | + echo "No changes to commit" |
| 88 | + else |
| 89 | + git commit -m "Update CHANGELOG for v${{ steps.version.outputs.version }}" |
| 90 | + git push origin main |
| 91 | + fi |
0 commit comments