v0.1.4 #5
Workflow file for this run
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: Release | |
| on: | |
| release: | |
| types: [published] | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
| steps: | |
| - 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 | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Validate version consistency | |
| 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 | |
| - 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 | |
| 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 }}" \ | |
| | jq -r '.body // ""') | |
| # Get current date | |
| CURRENT_DATE=$(date +%Y-%m-%d) | |
| # 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 | |
| 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 | |
| else | |
| # Remove the placeholder if no release notes | |
| sed -i 's/{{RELEASE_NOTES}}//' 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 | |
| - name: Commit and push CHANGELOG update | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add 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 | |
| fi |