diff --git a/.github/workflows/comment-download-link.yml b/.github/workflows/comment-download-link.yml new file mode 100644 index 00000000..34726a62 --- /dev/null +++ b/.github/workflows/comment-download-link.yml @@ -0,0 +1,57 @@ +# This action will send a comment to the pr for download the built apk. +# Needs to be as a separate action, artifacts are not available on the action used to upload them +name: Comment Artifact URL on PR + +on: + workflow_run: + workflows: + - "Validate gradle build test" + types: + - "completed" + +permissions: + actions: read # need to read the artifacts url + pull-requests: write # need to write the comment + +jobs: + comment-on-pr: + if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + steps: + + - name: Post url to artifact + 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 }} + run: | + + # 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 4ade9ee9..7ea85bc3 100644 --- a/.github/workflows/validate-gradle-build-test.yml +++ b/.github/workflows/validate-gradle-build-test.yml @@ -1,5 +1,5 @@ # This actions validates the gradle files and runs a build test to ensure the app is not corrupted -# if succeeded, and the source is a pull request, builds an evaluation apk and posts a comment to download it +# if succeeded and the source is a pull request, builds an evaluation apk name: Validate gradle build test on: @@ -14,16 +14,6 @@ on: env: VARIANT: evaluation NAME: URLCheck_evaluation.apk - DAYS: 14 - -permissions: - contents: read # to checkout the repo - pull-requests: write # to write the comment - -# this will cancel running actions if a newer commit is added to the pr -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true jobs: build: @@ -54,48 +44,25 @@ jobs: # the following steps will only run for PRs - - name: "[PR] Generate apk" + - name: Generate apk if: ${{ github.event_name == 'pull_request' }} uses: gradle/gradle-build-action@v3 with: arguments: > assemble${{ env.VARIANT }} - - name: "[PR] Upload apk as artifact" + - name: Upload apk as artifact if: ${{ github.event_name == 'pull_request' }} - id: upload-artifact-step - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v3 with: path: ./app/build/outputs/apk/${{ env.VARIANT }}/app-${{ env.VARIANT }}.apk name: ${{ env.NAME }} - retention-days: ${{ env.DAYS }} + retention-days: 14 - - name: "[PR] Comment url to artifact" + - name: Upload PR id as artifact if: ${{ github.event_name == 'pull_request' }} - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ github.event.pull_request.number }} - ARTIFACT: ${{ steps.upload-artifact-step.outputs.artifact-url }} - ACTION: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}" - run: | - - # calculate expiration date - EXPIRATION=$(date -d "+$DAYS days") - echo "EXPIRATION=$EXPIRATION" - - # post link comment - gh pr comment $PR -F - < - - This is an automatic comment created by a [Github Action]($ACTION) - EOF + uses: actions/upload-artifact@v3 + with: + path: /dev/null + name: ${{ github.event.number }} + retention-days: 1