From a43537522094a109c22d8852b6e1d510a55c9313 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 25 Apr 2024 21:25:42 +0200 Subject: [PATCH] Improve releases flow (#51213) --- .github/workflows/releases.yml | 96 ++++++++++++++++++++------ .github/workflows/update-changelog.yml | 9 --- 2 files changed, 75 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/update-changelog.yml diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index fe41be64b0f7..359877d89f72 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -7,10 +7,19 @@ on: description: 'Version to release' required: true +permissions: + contents: write + jobs: release: runs-on: ubuntu-latest + name: Release ${{ inputs.version }} + + outputs: + version: ${{ steps.version.outputs.version }} + notes: ${{ steps.cleaned-notes.outputs.release-notes }} + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -21,6 +30,35 @@ jobs: VERSION=${{ inputs.version }} echo "version=${VERSION#v}" >> "$GITHUB_OUTPUT" + - name: Check if branch and version match + id: guard + run: | + MAJOR_VERSION="${NUMERIC_VERSION%%.*}" + BRANCH_MAJOR_VERSION="${BRANCH%%.*}" + + echo "MAJOR_VERSION=$(echo $MAJOR_VERSION)" >> $GITHUB_OUTPUT; + echo "BRANCH_MAJOR_VERSION=$(echo $BRANCH_MAJOR_VERSION)" >> $GITHUB_OUTPUT; + + if [ "$MAJOR_VERSION" != "$BRANCH_MAJOR_VERSION" ]; then + echo "Mismatched versions! Aborting." + VERSION_MISMATCH='true'; + else + echo "Versions match! Proceeding." + VERSION_MISMATCH='false'; + fi + + echo "VERSION_MISMATCH=$(echo $VERSION_MISMATCH)" >> $GITHUB_OUTPUT; + env: + BRANCH: ${{ github.ref_name }} + NUMERIC_VERSION: ${{ steps.version.outputs.version }} + + - name: Fail if branch and release tag do not match + if: ${{ steps.guard.outputs.VERSION_MISMATCH == 'true' }} + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Workflow failed. Release version does not match with selected target branch. Did you select the correct branch?') + - name: Update Application.php version run: sed -i "s/const VERSION = '.*';/const VERSION = '${{ steps.version.outputs.version }}';/g" src/Illuminate/Foundation/Application.php @@ -41,24 +79,40 @@ jobs: bash ./bin/release.sh v${{ steps.version.outputs.version }} script_stop: true - # - name: Generate release notes - # id: notes - # uses: RedCrafter07/release-notes-action@main - # with: - # tag-name: v${{ steps.version.outputs.version }} - # token: ${{ secrets.GITHUB_TOKEN }} - # branch: ${{ github.ref_name }} - - # - name: Cleanup release notes - # run: | - # sed -i '/## What/d' ${{ steps.notes.outputs.release-notes }} - # sed -i '/## New Contributors/,$d' ${{ steps.notes.outputs.release-notes }} - - # - name: Create release - # uses: softprops/action-gh-release@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # tag_name: v${{ steps.version.outputs.version }} - # name: v${{ steps.version.outputs.version }} - # body: ${{ steps.notes.outputs.release-notes }} + - name: Generate release notes + id: generated-notes + uses: RedCrafter07/release-notes-action@main + with: + tag-name: v${{ steps.version.outputs.version }} + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref_name }} + + - name: Cleanup release notes + id: cleaned-notes + run: | + NOTES="${{ steps.generated-notes.outputs.release-notes }}" + NOTES=$(echo $NOTES | sed '/## What/d') + NOTES=$(echo $NOTES | sed '/## New Contributors/,$d') + echo "release-notes=${NOTES}" >> "$GITHUB_OUTPUT" + + - name: Create release + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.version.outputs.version }} + name: v${{ steps.version.outputs.version }} + body: ${{ steps.cleaned-notes.outputs.release-notes }} + target_commitish: ${{ github.ref_name }} + make_latest: 'legacy' + + update-changelog: + needs: release + + name: Update changelog + + uses: laravel/.github/.github/workflows/update-changelog.yml@main + with: + branch: ${{ github.ref_name }} + version: "v${{ needs.release.outputs.version }}" + notes: ${{ needs.release.outputs.notes }} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml deleted file mode 100644 index 1625bda1002c..000000000000 --- a/.github/workflows/update-changelog.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: update changelog - -on: - release: - types: [released] - -jobs: - update: - uses: laravel/.github/.github/workflows/update-changelog.yml@main