0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

rewrite pr comment creation to use actions/upload-artifact@v4

This commit is contained in:
TrianguloY 2024-08-20 18:43:56 +02:00
parent 24dfbb14db
commit b6d599e5ce
2 changed files with 39 additions and 66 deletions

View File

@ -1,57 +0,0 @@
# 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=@- <<EOF
This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.
| [Download testing apk](https://github.com/$OWNER/$REPO/suites/$PREVIOUS_SUITE_ID/artifacts/$ARTIFACT_ID) |
| - |
You must be logged in for the link to work.
The link will expire at $EXPIRES_AT.
<hr>
<sub>This is an automatic comment created by a [Github Action](https://github.com/$OWNER/$REPO/actions/runs/$CURRENT_JOB_ID)</sub>
EOF

View File

@ -19,6 +19,7 @@ concurrency:
env:
VARIANT: evaluation
NAME: URLCheck_evaluation.apk
RETENTION_DAYS: 14
jobs:
build:
@ -57,17 +58,46 @@ jobs:
assemble${{ env.VARIANT }}
- name: Upload apk as artifact
id: artifact-upload-step
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ./app/build/outputs/apk/${{ env.VARIANT }}/app-${{ env.VARIANT }}.apk
name: ${{ env.NAME }}
retention-days: 14
retention-days: ${{ env.RETENTION_DAYS }}
- name: Upload PR id as artifact
outputs:
artifact-url: ${{ steps.artifact-upload-step.outputs.artifact-url }}
comment:
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
with:
path: /dev/null
name: ${{ github.event.number }}
retention-days: 1
runs-on: ubuntu-latest
needs: build
permissions:
pull-requests: write # need to write the comment
steps:
- name: Create comment
env:
GH_TOKEN: ${{ github.token }}
run: |
# post link comment
URL="${{ github.event.pull_request.html_url }}"
BODY="
This PR builds correctly, here is the generated apk.
This unsigned version can be installed alongside the original app and should only be used for testing the changes, not for daily usage.
| [Download testing apk](${{ needs.build.outputs.artifact-url }}) |
| - |
You must be logged in for the link to work.
The link will expire at $(date -d "+$RETENTION_DAYS days").
<hr>
<sub>This is an automatic comment created by a [Github Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})</sub>
"
# use --edit-last-or-create whenever it is ready: https://github.com/cli/cli/issues/6790
gh pr comment "$URL" --edit-last --body "$BODY" || gh pr comment "$URL" --body "$BODY"