From c808fdaf1a2746fbda7a396723f805a31fe8475a Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Wed, 13 Nov 2024 12:53:55 +0100 Subject: [PATCH] Add more check for PR's merged during release --- .github/workflows/create-release.yaml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index 4681858533..05f06baa26 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -218,7 +218,7 @@ jobs: - name: Check if any PR was merged during release run: | - COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits/main -q '.sha') + COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha') echo "Latest commit sha: $COMMIT_SHA" echo "Workflow sha: ${{ github.sha }}" if [ "$COMMIT_SHA" != "${{ github.sha }}" ]; then @@ -268,6 +268,16 @@ jobs: echo "Step skipped" fi + - name: Check if any PR have been merged before merging the bump PR + run: | + COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[1].sha') + echo "Latest commit sha: $COMMIT_SHA" + echo "Bump sha: ${{ github.sha }}" + if [ "$COMMIT_SHA" != "${{ github.sha }}" ]; then + echo "::error ::a PR have been merged before merging the bump PR. Don't rerun this workflow. Create a new release with the same version" + exit 1 + fi + - name: Save latest commit ref id: pull-ref env: @@ -296,7 +306,7 @@ jobs: - name: Check if any PR was merged after bumps run: | - COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits/main -q '.sha') + COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha') echo "Latest commit sha: $COMMIT_SHA" echo "Bump sha: ${{ needs.bumps.outputs.latest_commit}}" if [ "$COMMIT_SHA" != "${{ needs.bumps.outputs.latest_commit}}" ]; then @@ -318,6 +328,16 @@ jobs: git tag ${{ github.event.inputs.name }} git push origin ${{ github.event.inputs.name }} + - name: Check if any PR may have been merged before creating the tag and draft release + run: | + COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha') + echo "Latest commit sha: $COMMIT_SHA" + echo "Bump sha: ${{ needs.bumps.outputs.latest_commit}}" + if [ "$COMMIT_SHA" != "${{ needs.bumps.outputs.latest_commit}}" ]; then + echo "::error ::a PR may have been merged before the tag and draft release were created. Delete the tag and the draft release. Don't rerun this workflow. Create a new release with the same version" + exit 1 + fi + outputs: release_id: ${{ steps.create-draft.outputs.release_id }}