diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8568ad1f2..2510abcfa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,12 +70,17 @@ jobs: if: github.event_name == 'issue_comment' env: COMMENT_BODY: ${{ github.event.comment.body }} + COMMENT_DATE: ${{ github.event.comment.created_at }} run: | - echo "repo_name=${{ fromJson(steps.request.outputs.data).head.repo.full_name }}" >> $GITHUB_OUTPUT + PR_PUSHED_AT="${{ fromJson(steps.request.outputs.data).pushed_at }}" comment_hash=`echo "$COMMENT_BODY" | cut -d' ' -f2` # get commit hash if any if [[ "${comment_hash}" == "/runsim" ]]; then - # use default head ref - echo "ref=${{ fromJson(steps.request.outputs.data).head.ref }}" >> $GITHUB_OUTPUT + # use default head ref, if the PR hasn't changed since the comment + if [[ $(date -d "$PR_PUSHED_AT" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then + echo "The PR has changed since the comment, and is therefore not safe to use. Exiting." + exit 1 + fi + echo "ref=${{ fromJson(steps.request.outputs.data).head.sha }}" >> $GITHUB_OUTPUT else # use comment provided ref echo "ref=${comment_hash}" >> $GITHUB_OUTPUT @@ -90,7 +95,6 @@ jobs: with: submodules: true token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ steps.pr_data.outputs.repo_name }} ref: ${{ steps.pr_data.outputs.ref }} - name: Normal check out code uses: actions/checkout@v3 @@ -210,7 +214,6 @@ jobs: with: submodules: true token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ needs.build.outputs.repo_name }} ref: ${{ needs.build.outputs.ref }} - name: Normal check out code uses: actions/checkout@v3 @@ -257,7 +260,6 @@ jobs: with: submodules: true token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ needs.build.outputs.repo_name }} ref: ${{ needs.build.outputs.ref }} - name: Normal check out code uses: actions/checkout@v3 @@ -304,7 +306,6 @@ jobs: with: submodules: true token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ needs.build.outputs.repo_name }} ref: ${{ needs.build.outputs.ref }} - name: Normal check out code uses: actions/checkout@v3