From 8a9e239e36a2ca85876f3c8c89160727762761e2 Mon Sep 17 00:00:00 2001 From: TrianguloY Date: Tue, 18 Apr 2023 23:00:46 +0200 Subject: [PATCH] don't use pull_requests object (is empty for external forks) --- .github/workflows/comment-download-link.yml | 31 +++++++++++-------- .../workflows/validate-gradle-build-test.yml | 8 ++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/comment-download-link.yml b/.github/workflows/comment-download-link.yml index 489084d..9e8358c 100644 --- a/.github/workflows/comment-download-link.yml +++ b/.github/workflows/comment-download-link.yml @@ -15,34 +15,39 @@ permissions: jobs: comment-on-pr: - if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.pull_requests[0] != null + if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - name: Post url to artifact - timeout-minutes: 5 env: GITHUB_TOKEN: ${{ github.token }} OWNER: ${{ github.repository_owner }} REPO: ${{ github.event.repository.name }} + CURRENT_JOB_ID: ${{ github.run_id }} PREVIOUS_JOB_ID: ${{ github.event.workflow_run.id }} PREVIOUS_SUITE_ID: ${{ github.event.workflow_run.check_suite_id }} - PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} run: | - # get artifact id - while true; do - ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/runs/$PREVIOUS_JOB_ID/artifacts" --jq ".artifacts[0].id") - if [ -n "$ARTIFACT_ID" ]; then break; fi - # the artifact isn't available immediately, retry - echo No artifact, will retry shortly - sleep 10 - done + # get artifacts + read PR_NUMBER ARTIFACT_ID EXPIRES_AT <<< $(gh api "/repos/$OWNER/$REPO/actions/runs/$PREVIOUS_JOB_ID/artifacts" --jq '"\(.artifacts[0].name) \(.artifacts[1].id) \(.artifacts[1].expires_at)"') + if [ "$ARTIFACT_ID" == "null" ]; then + echo "No artifacts, (probably) not a PR, exiting" + exit + fi + echo "PR NUMBER: $PR_NUMBER" echo "ARTIFACT ID: $ARTIFACT_ID" + echo "EXPIRES_AT: $EXPIRES_AT" # post link comment gh api "/repos/$OWNER/$REPO/issues/$PR_NUMBER/comments" -F body=@- < + + This is an automatic comment created by a [Github Action](https://github.com/$OWNER/$REPO/actions/runs/$CURRENT_JOB_ID) EOF \ No newline at end of file diff --git a/.github/workflows/validate-gradle-build-test.yml b/.github/workflows/validate-gradle-build-test.yml index ee70190..f6355e8 100644 --- a/.github/workflows/validate-gradle-build-test.yml +++ b/.github/workflows/validate-gradle-build-test.yml @@ -49,7 +49,6 @@ jobs: uses: gradle/gradle-build-action@v2 with: arguments: > - build assemble${{ env.VARIANT }} - name: Upload apk as artifact @@ -58,3 +57,10 @@ jobs: with: path: ./app/build/outputs/apk/${{ env.VARIANT }}/app-${{ env.VARIANT }}.apk name: ${{ env.NAME }} + + - name: Upload PR id as artifact + if: ${{ github.event_name == 'pull_request' }} + uses: actions/upload-artifact@v3 + with: + path: /dev/null + name: ${{ github.event.number }}