From 8bad0cd2fee236a591dd60d220265b075f1b4234 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Fri, 16 Aug 2024 20:34:37 -0400 Subject: [PATCH] Infer SHA from github context --- .github/workflows/ci-pipeline.yml | 39 ++++++++++++++----------------- .github/workflows/ci-security.yml | 7 +----- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index c65da107c1..7066b20529 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -30,9 +30,6 @@ on: pull_request_number: description: 'Pull Request Number' required: true - pull_request_current_merge_sha: - description: 'Pull Request Merge SHA' - required: true env: TGS_DOTNET_VERSION: 8 @@ -78,7 +75,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -107,7 +104,7 @@ jobs: path: ./release_notes_bins/ - name: Set CI Check Run (Started) - run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.inputs.pull_request_current_merge_sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Started ${{ github.run_id }} + run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Started ${{ github.run_id }} code-scanning: name: Code Scanning @@ -143,7 +140,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -249,7 +246,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -326,7 +323,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -393,7 +390,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -541,7 +538,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -616,7 +613,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -706,7 +703,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -864,7 +861,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1112,7 +1109,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1224,7 +1221,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1272,7 +1269,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1585,7 +1582,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1708,7 +1705,7 @@ jobs: - name: Abort if PR Merge SHA has Changed uses: actions/github-script@v7 - if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != inputs.pull_request_current_merge_sha + if: github.event_name != 'push' && github.event_name != 'schedule' && steps.get-pr-sha.outputs.head_sha != github.sha with: script: | const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -1886,15 +1883,15 @@ jobs: - name: Update CI Check Run (Cancelled) if: cancelled() - run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.inputs.pull_request_current_merge_sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Cancelled ${{ github.run_id }} + run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.github.sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Cancelled ${{ github.run_id }} - name: Update CI Check Run (Failure) if: (!cancelled() && failure()) - run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.inputs.pull_request_current_merge_sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Failure ${{ github.run_id }} + run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.github.sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Failure ${{ github.run_id }} - name: Update CI Check Run (Success) if: (!cancelled() && failure()) - run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.inputs.pull_request_current_merge_sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Success ${{ github.run_id }} + run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.event.github.sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Success ${{ github.run_id }} - name: Fail Job if Prerequisites Failed if: failure() diff --git a/.github/workflows/ci-security.yml b/.github/workflows/ci-security.yml index 6fb53695fb..7571f5c4c0 100644 --- a/.github/workflows/ci-security.yml +++ b/.github/workflows/ci-security.yml @@ -82,10 +82,6 @@ jobs: - name: Build ReleaseNotes run: dotnet publish -c Release -p:TGS_HOST_NO_WEBPANEL=true -o release_notes_bins tools/Tgstation.Server.ReleaseNotes/Tgstation.Server.ReleaseNotes.csproj - - name: Read Current SHA - id: get-pr-sha - run: echo "head_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - - name: Generate Temporary Branch to Reference Merge run: | git checkout -b ${{ github.event.pull_request.number }}-merge @@ -104,11 +100,10 @@ jobs: workflow-inputs: | { "pull_request_number": "${{ github.event.pull_request.number }}" - "pull_request_current_merge_sha": "${{ steps.get-pr-sha.outputs.head_sha }}" } - name: Set CI Check Run (Pending) - run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ steps.get-pr-sha.outputs.head_sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Pending ${{ steps.dispatch.outputs.run-id }} + run: dotnet release_notes_bins/Tgstation.Server.ReleaseNotes.dll --ci-check ${{ github.sha }} ${{ secrets.TGS_CI_GITHUB_APP_TOKEN_BASE64 }} Pending ${{ steps.dispatch.outputs.run-id }} - name: Delete Temporary Branch if: always()