diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..a0a688449 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release + +on: + push: + branches: [main] + paths: + - lib/factory_bot/version.rb + +jobs: + release: + name: Release gem + runs-on: ubuntu-latest + permissions: + contents: write # create git tag + GitHub release + id-token: write # OIDC token for RubyGems trusted publishing + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + - name: Extract release notes from NEWS.md + id: release_notes + run: | + VERSION=$(ruby -e "require_relative 'lib/factory_bot/version'; puts FactoryBot::VERSION") + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + NOTES=$(awk "BEGIN{p=0} /^## $VERSION/{p=1; next} p && /^## /{exit} p{print}" NEWS.md) + echo "notes<> "$GITHUB_OUTPUT" + echo "$NOTES" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + - uses: rubygems/release-gem@v1 + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "v${{ steps.release_notes.outputs.version }}" \ + --title "v${{ steps.release_notes.outputs.version }}" \ + --notes "${{ steps.release_notes.outputs.notes }}" diff --git a/.github/workflows/validate-changelog.yml b/.github/workflows/validate-changelog.yml new file mode 100644 index 000000000..68e932592 --- /dev/null +++ b/.github/workflows/validate-changelog.yml @@ -0,0 +1,21 @@ +name: Validate changelog + +on: + pull_request: + paths: + - lib/factory_bot/version.rb + +jobs: + validate: + name: Check NEWS.md has release section + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Check NEWS.md contains version section + run: | + VERSION=$(ruby -e "require_relative 'lib/factory_bot/version'; puts FactoryBot::VERSION") + if ! grep -q "^## $VERSION" NEWS.md; then + echo "ERROR: NEWS.md is missing a section for version $VERSION" + echo "Add a '## $VERSION (date)' entry to NEWS.md before bumping the version." + exit 1 + fi