Merge branch 'TrianguloY:master' into master #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
name: Validate gradle build test | |
on: | |
push: | |
branches: | |
- master | |
pull_request_target: | |
branches: | |
- master | |
# Cancel running actions if new commits are added | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
# parameters | |
env: | |
VARIANT: evaluation | |
NAME: URLCheck_evaluation.apk | |
RETENTION_DAYS: 14 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Build & test | |
run: ./gradlew build test | |
# the following steps will only run for PRs | |
- name: "[PR] Generate apk" | |
if: ${{ github.event_name == 'pull_request_target' }} | |
run: ./gradlew assemble${{ env.VARIANT }} | |
- name: "[PR] Upload apk as artifact" | |
id: artifact-upload-step | |
if: ${{ github.event_name == 'pull_request_target' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
path: ./app/build/outputs/apk/${{ env.VARIANT }}/app-${{ env.VARIANT }}.apk | |
name: ${{ env.NAME }} | |
retention-days: ${{ env.RETENTION_DAYS }} | |
outputs: | |
artifact-url: ${{ steps.artifact-upload-step.outputs.artifact-url }} | |
comment: | |
if: ${{ github.event_name == 'pull_request_target' }} | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
pull-requests: write # need to write the comment | |
steps: | |
- name: "[PR] Comment url to artifact" | |
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 in $RETENTION_DAYS days, 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 }}?pr=${{ github.event.pull_request.number }})</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" |