|
| 1 | +name: Sync Release Notes from CHANGELOG |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag-name: |
| 7 | + type: string |
| 8 | + required: false |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + release-notes: |
| 17 | + name: Promote CHANGELOG and Sync Release Notes |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout main branch |
| 22 | + uses: actions/checkout@v6 |
| 23 | + with: |
| 24 | + ref: main |
| 25 | + token: ${{ github.token }} |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Cache Composer dependencies |
| 29 | + uses: actions/cache@v5 |
| 30 | + with: |
| 31 | + path: /tmp/composer-cache |
| 32 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 33 | + restore-keys: | |
| 34 | + ${{ runner.os }}-composer- |
| 35 | +
|
| 36 | + - name: Install dependencies |
| 37 | + uses: php-actions/composer@v6 |
| 38 | + env: |
| 39 | + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' |
| 40 | + COMPOSER_CACHE_DIR: /tmp/composer-cache |
| 41 | + with: |
| 42 | + php_version: '8.3' |
| 43 | + command: 'install' |
| 44 | + args: '--prefer-dist --no-progress --no-interaction --no-scripts' |
| 45 | + |
| 46 | + - name: Resolve release metadata |
| 47 | + id: release |
| 48 | + run: | |
| 49 | + TAG="${INPUT_TAG_NAME:-${EVENT_TAG_NAME:-${GITHUB_REF_NAME}}}" |
| 50 | + VERSION="${TAG#v}" |
| 51 | + DATE_VALUE="${EVENT_PUBLISHED_AT%%T*}" |
| 52 | +
|
| 53 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 54 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 55 | + echo "date=${DATE_VALUE:-$(date +%F)}" >> "$GITHUB_OUTPUT" |
| 56 | + env: |
| 57 | + INPUT_TAG_NAME: ${{ inputs.tag-name }} |
| 58 | + EVENT_TAG_NAME: ${{ github.event.release.tag_name }} |
| 59 | + EVENT_PUBLISHED_AT: ${{ github.event.release.published_at }} |
| 60 | + |
| 61 | + - name: Promote unreleased changelog entry |
| 62 | + run: | |
| 63 | + VERSION="${{ steps.release.outputs.version }}" |
| 64 | + DATE_VALUE="${{ steps.release.outputs.date }}" |
| 65 | +
|
| 66 | + if grep -q "^## ${VERSION} - " CHANGELOG.md; then |
| 67 | + echo "Release ${VERSION} already exists in CHANGELOG.md." |
| 68 | + elif grep -q "^## Unreleased - " CHANGELOG.md; then |
| 69 | + vendor/bin/keep-a-changelog unreleased:promote "${VERSION}" --date="${DATE_VALUE}" --no-interaction |
| 70 | + else |
| 71 | + echo "No Unreleased section found; skipping promotion." |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Ensure the next Unreleased section exists |
| 75 | + run: | |
| 76 | + if ! grep -q "^## Unreleased - " CHANGELOG.md; then |
| 77 | + vendor/bin/keep-a-changelog unreleased:create --no-interaction |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Commit CHANGELOG updates |
| 81 | + uses: EndBug/add-and-commit@v10 |
| 82 | + with: |
| 83 | + add: CHANGELOG.md |
| 84 | + message: "Sync changelog for ${{ steps.release.outputs.tag }}" |
| 85 | + default_author: github_actions |
| 86 | + pull: "--rebase --autostash" |
| 87 | + push: true |
| 88 | + |
| 89 | + - name: Export release notes from CHANGELOG |
| 90 | + run: vendor/bin/keep-a-changelog version:show "${{ steps.release.outputs.version }}" > release-notes.md |
| 91 | + |
| 92 | + - name: Update GitHub release notes |
| 93 | + run: gh release edit "${TAG}" --notes-file release-notes.md |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ github.token }} |
| 96 | + TAG: ${{ steps.release.outputs.tag }} |
0 commit comments