diff --git a/.github/actions/get-pr-number/action.yml b/.github/actions/get-pr-number/action.yml index 84f360ca4..47225256a 100644 --- a/.github/actions/get-pr-number/action.yml +++ b/.github/actions/get-pr-number/action.yml @@ -2,7 +2,7 @@ name: 'get-pr-number' description: 'Gets the PR number from an artifact' outputs: pr-number: - description: "PR number" + description: "PR number or empty string" value: ${{ steps.cat.outputs.pr-number }} runs: using: "composite" @@ -10,7 +10,8 @@ runs: - uses: ./.github/actions/download-workflow-run-artifact with: artifact-name: pr-number - expect-files: "./pr_number" + + - run: touch ./pr_number - id: cat run: echo pr-number="$(cat ./pr_number)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/android-device-test.yml b/.github/workflows/android-device-test.yml index 7c06614c8..e7e9c8816 100644 --- a/.github/workflows/android-device-test.yml +++ b/.github/workflows/android-device-test.yml @@ -7,7 +7,21 @@ on: - completed jobs: - create-check: + pre_job: + runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.check_skip.outputs.should_skip }} + steps: + # if android-build in android-ci was skipped, the android-device-test job can be skipped entirely + - id: check_skip + run: | + conclusion=$(curl ${{ github.event.workflow_run.jobs_url }} | jq -r '.jobs[] | select(.name == "android-build").conclusion') + should_skip=$([ "$conclusion" = "skipped" ] && echo "true" || echo "false") + echo "should_skip=$should_skip" >> "$GITHUB_OUTPUT" + + android-device-test: + needs: pre_job + if: needs.pre_job.outputs.should_skip == 'false' strategy: max-parallel: 2 matrix: @@ -34,29 +48,48 @@ jobs: } ] runs-on: ubuntu-latest - if: github.event.workflow_run.event == 'pull_request' steps: - uses: actions/checkout@v4 + - name: Sanity check, test files should exist + uses: andstor/file-existence-action@v2.0.0 + with: + files: "${{ matrix.test.testFile }}, ${{ matrix.test.appFile }}" + fail: true + + # get comment from PR + + - uses: ./.github/actions/get-pr-number + id: get-pr-number + - name: Generate token + if: matrix.test.name == 'Android Benchmark' && steps.get-pr-number.outputs.pr-number id: generate_token uses: tibdex/github-app-token@v2 with: app_id: ${{ secrets.MAPLIBRE_NATIVE_BOT_APP_ID }} private_key: ${{ secrets.MAPLIBRE_NATIVE_BOT_PRIVATE_KEY }} - - uses: ./.github/actions/get-pr-number - id: get-pr-number - - name: Check if comment on PR contains '!benchmark android' + if: matrix.test.name == 'Android Benchmark' && steps.get-pr-number.outputs.pr-number uses: peter-evans/find-comment@v3 - id: fc + id: benchmark_comment with: issue-number: ${{ steps.get-pr-number.outputs.pr-number }} body-regex: '^!benchmark.*android.*$' + - name: Should we run this device test? + # always run when something was merged into main + # run benchmark when comment with '!benchmark android' exists in PR + if: | + (github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.event == 'push') || + matrix.test.name == 'Android Benchmark' && steps.benchmark_comment.outputs.comment-id || + matrix.test.name != 'Android Benchmark' + run: + echo "run_device_test=true" >> "$GITHUB_ENV" + - uses: LouisBrunner/checks-action@v2.0.0 - if: matrix.test.name != 'Android Benchmark' || steps.fc.outputs.comment-id + if: env.run_device_test == 'true' id: create_check with: token: ${{ steps.generate_token.outputs.token }} @@ -66,19 +99,12 @@ jobs: sha: ${{ github.event.workflow_run.head_sha }} - uses: ./.github/actions/download-workflow-run-artifact - if: matrix.test.name != 'Android Benchmark' || steps.fc.outputs.comment-id + if: env.run_device_test == 'true' with: artifact-name: ${{ matrix.test.artifactName }} - - name: Check if test files exist (otherwise the parent workflow was skipped) - if: matrix.test.name != 'Android Benchmark' || steps.fc.outputs.comment-id - id: check_files - uses: andstor/file-existence-action@v2.0.0 - with: - files: "${{ matrix.test.testFile }}, ${{ matrix.test.appFile }}" - - name: Configure AWS Credentials - if: matrix.test.name == 'Android Benchmark' + if: env.run_device_test == 'true' && matrix.test.name == 'Android Benchmark' uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -89,7 +115,7 @@ jobs: role-session-name: MySessionName - name: Upload external data for benchmark - if: matrix.test.name == 'Android Benchmark' + if: env.run_device_test == 'true' && matrix.test.name == 'Android Benchmark' run: | export RESULTS_API=${{ secrets.MLN_RESULTS_API }} export AWS_DEVICE_FARM_PROJECT_ARN=${{ vars.AWS_DEVICE_FARM_PROJECT_ARN }} @@ -97,7 +123,7 @@ jobs: echo external_data_arn="$upload_arn" >> "$GITHUB_ENV" - uses: ./.github/actions/aws-device-farm-run - if: steps.check_files.outputs.files_exists == 'true' && (matrix.test.name != 'Android Benchmark' || steps.fc.outputs.comment-id) + if: env.run_device_test == 'true' with: name: ${{ matrix.test.name }} appType: ANDROID_APP @@ -115,7 +141,7 @@ jobs: testSpecArn: ${{ matrix.test.testSpecArn }} - uses: LouisBrunner/checks-action@v2.0.0 - if: always() && (matrix.test.name != 'Android Benchmark' || steps.fc.outputs.comment-id) + if: always() && env.run_device_test == 'true' with: token: ${{ steps.generate_token.outputs.token }} check_id: ${{ steps.create_check.outputs.check_id }} diff --git a/.github/workflows/pr-bloaty-ios.yml b/.github/workflows/pr-bloaty-ios.yml index bbc4f14ee..ec731132f 100644 --- a/.github/workflows/pr-bloaty-ios.yml +++ b/.github/workflows/pr-bloaty-ios.yml @@ -13,8 +13,22 @@ permissions: id-token: write # This is required for requesting the AWS JWT jobs: - pr-bloaty-ios: + pre_job: if: github.event.workflow_run.event == 'pull_request' + runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.check_skip.outputs.should_skip }} + steps: + # if ios-build in ios-ci was skipped, the rest of the workflow can be skipped + - id: check_skip + run: | + conclusion=$(curl ${{ github.event.workflow_run.jobs_url }} | jq -r '.jobs[] | select(.name == "ios-build").conclusion') + should_skip=$([ "$conclusion" = "skipped" ] && echo "true" || echo "false") + echo "should_skip=$should_skip" >> "$GITHUB_OUTPUT" + + pr-bloaty-ios: + needs: pre_job + if: needs.pre_job.outputs.should_skip == 'false' runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-linux-tests.yml similarity index 90% rename from .github/workflows/pr-tests.yml rename to .github/workflows/pr-linux-tests.yml index c77e1fe4c..25610ce8a 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-linux-tests.yml @@ -1,5 +1,5 @@ # Runs Bloaty (size test) and Google Benchmark and reports results on PR -name: pr-tests +name: pr-linux-tests on: workflow_run: @@ -16,8 +16,22 @@ permissions: id-token: write # This is required for requesting the AWS JWT jobs: - pr-bloaty: + pre_job: if: github.event.workflow_run.event == 'pull_request' + runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.check_skip.outputs.should_skip }} + steps: + # if linux-build-and-test in linux-ci was skipped, the rest of the workflow can be skipped + - id: check_skip + run: | + conclusion=$(curl ${{ github.event.workflow_run.jobs_url }} | jq -r '.jobs[] | select(.name == "linux-build-and-test").conclusion') + should_skip=$([ "$conclusion" = "skipped" ] && echo "true" || echo "false") + echo "should_skip=$should_skip" >> "$GITHUB_OUTPUT" + + pr-bloaty: + needs: pre_job + if: needs.pre_job.outputs.should_skip == 'false' runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pr-render-test-result.yml b/.github/workflows/pr-render-test-result.yml deleted file mode 100644 index 5461753ee..000000000 --- a/.github/workflows/pr-render-test-result.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: pr-upload-render-test-result - -permissions: - pull-requests: write # This is required to leave a comment on the PR - id-token: write # This is required for requesting the AWS JWT - -on: - workflow_run: - workflows: [linux-ci] - types: - - completed - -jobs: - upload-render-test-result: - runs-on: ubuntu-22.04 - if: github.event.workflow_run.event == 'pull_request' - env: - html_filename: "linux-drawable.html" - steps: - - uses: actions/checkout@v4 - - - uses: ./.github/actions/get-pr-number - id: get-pr-number - - - uses: ./.github/actions/download-workflow-run-artifact - with: - artifact-name: render-test-result - - # when there are no results, the render test succeeded - # in this case the subsequent steps can be skipped - - name: "Check existence render test results HTML" - id: render_test_results - uses: andstor/file-existence-action@v2.0.0 - with: - files: ${{ env.html_filename }} - - - name: Configure AWS Credentials - if: steps.render_test_results.outputs.files_exists - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: us-west-2 - role-to-assume: ${{ vars.OIDC_AWS_ROLE_TO_ASSUME }} - role-session-name: ${{ github.run_id }} - - - name: Upload render test results to S3 - if: steps.render_test_results.outputs.files_exists - id: upload_render_test_results - run: | - aws s3 cp metrics/${{ env.html_filename }} \ - s3://maplibre-native-test-artifacts/${{ github.run_id }}-${{ env.html_filename }} \ - --expires "$(date -d '+30 days' --utc +'%Y-%m-%dT%H:%M:%SZ')" - - - name: 'Leave comment on PR with test results' - if: steps.render_test_results.outputs.files_exists - uses: marocchino/sticky-pull-request-comment@v2 - with: - header: render-test-result - number: ${{ steps.get-pr-number.outputs.pr-number }} - message: | - Render test results at https://maplibre-native-test-artifacts.s3.eu-central-1.amazonaws.com/${{ github.run_id }}-${{ env.html_filename }} diff --git a/.github/workflows/upload-coverage.yml b/.github/workflows/upload-coverage.yml index 6cd083629..046b2fdb8 100644 --- a/.github/workflows/upload-coverage.yml +++ b/.github/workflows/upload-coverage.yml @@ -7,7 +7,20 @@ on: - completed jobs: + pre_job: + runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.check_skip.outputs.should_skip }} + steps: + - id: check_skip + run: | + conclusion=$(curl ${{ github.event.workflow_run.jobs_url }} | jq -r '.jobs[] | select(.name == "linux-coverage").conclusion') + should_skip=$([ "$conclusion" = "skipped" ] && echo "true" || echo "false") + echo "should_skip=$should_skip" >> "$GITHUB_OUTPUT" + upload-coverage: + needs: pre_job + if: needs.pre_job.outputs.should_skip == 'false' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4