From 693bab616088b7e3aecc9152fc488bcd02b87087 Mon Sep 17 00:00:00 2001 From: anitarua Date: Mon, 13 Jan 2025 14:16:45 -0800 Subject: [PATCH] ci: add checks for commit SHAs --- .github/workflows/on-pull-request.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml index de966a9..e2f9019 100644 --- a/.github/workflows/on-pull-request.yml +++ b/.github/workflows/on-pull-request.yml @@ -22,6 +22,22 @@ jobs: echo "Job originally triggered by ${{ github.actor }}" exit 1 + check-commits-exists: + needs: verify-user-permissions + runs-on: ubuntu-latest + steps: + - name: Check if merge commit sha exists + if: github.event.pull_request.merge_commit_sha == '' + run: | + echo "No merge commit sha found for this pull request." + exit 1 + + - name: Check if head sha exists + if: github.event.pull_request.head.sha == '' + run: | + echo "No head sha found for this pull request." + exit 1 + checkout-default: needs: verify-user-permissions name: Checkout action using default ref @@ -53,7 +69,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - ref: ${{ github.event.pull_request.merge_commit_sha }} + ref: ${{ github.event.pull_request.merge_commit_sha || github.event.pull_request.head.sha }} - name: Test secret access if: env.SUPER_SECRET == ''