[GR-74716] Reduce GitHub action usage #215
This file contains hidden or 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
| name: Run CI unittests | |
| on: | |
| pull_request: | |
| types: [opened, ready_for_review, synchronize] | |
| workflow_dispatch: | |
| jobs: | |
| should-run: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| run_ci: ${{ steps.decision.outputs.run_ci }} | |
| reason: ${{ steps.decision.outputs.reason }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Check file changes | |
| id: changes | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| if (!pr) { | |
| core.setOutput('workflow_or_suite', 'false'); | |
| core.setOutput('docs_only', 'false'); | |
| return; | |
| } | |
| const changedFiles = await github.paginate( | |
| github.rest.pulls.listFiles, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number, | |
| per_page: 100, | |
| } | |
| ); | |
| const hasWorkflowOrSuiteChanges = changedFiles.some(file => | |
| file.filename.startsWith('.github/') || file.filename === 'mx.graalpython/suite.py' | |
| ); | |
| const hasOnlyDocsChanges = changedFiles.length > 0 && changedFiles.every(file => file.filename.startsWith('docs/')); | |
| core.setOutput('workflow_or_suite', hasWorkflowOrSuiteChanges ? 'true' : 'false'); | |
| core.setOutput('docs_only', hasOnlyDocsChanges ? 'true' : 'false'); | |
| - name: Check if workflow should run | |
| id: decision | |
| uses: actions/github-script@v8 | |
| env: | |
| HAS_WORKFLOW_OR_SUITE_CHANGES: ${{ steps.changes.outputs.workflow_or_suite || 'false' }} | |
| HAS_ONLY_DOCS_CHANGES: ${{ steps.changes.outputs.docs_only || 'false' }} | |
| with: | |
| script: | | |
| const eventName = context.eventName; | |
| const hasWorkflowOrSuiteChanges = process.env.HAS_WORKFLOW_OR_SUITE_CHANGES === 'true'; | |
| const hasOnlyDocsChanges = process.env.HAS_ONLY_DOCS_CHANGES === 'true'; | |
| if (eventName === 'workflow_dispatch') { | |
| core.setOutput('run_ci', 'true'); | |
| core.setOutput('reason', 'manual dispatch'); | |
| return; | |
| } | |
| if (eventName !== 'pull_request') { | |
| core.setOutput('run_ci', 'false'); | |
| core.setOutput('reason', `unsupported event: ${eventName}`); | |
| return; | |
| } | |
| const pr = context.payload.pull_request; | |
| if (pr.draft) { | |
| core.setOutput('run_ci', 'false'); | |
| core.setOutput('reason', 'draft PR'); | |
| return; | |
| } | |
| if (hasOnlyDocsChanges) { | |
| core.setOutput('run_ci', 'false'); | |
| core.setOutput('reason', 'docs-only changes'); | |
| return; | |
| } | |
| if (hasWorkflowOrSuiteChanges) { | |
| core.setOutput('run_ci', 'true'); | |
| core.setOutput('reason', '.github or suite.py changes'); | |
| return; | |
| } | |
| if (pr.user?.login === 'graalvmbot') { | |
| const isMergedOrClosed = pr.merged === true || pr.merged_at != null || pr.state !== 'open'; | |
| if (isMergedOrClosed) { | |
| core.setOutput('run_ci', 'false'); | |
| core.setOutput('reason', 'graalvmbot PR already merged/closed'); | |
| return; | |
| } | |
| } | |
| if (pr.head?.repo?.fork) { | |
| core.setOutput('run_ci', 'true'); | |
| core.setOutput('reason', 'fork PR'); | |
| return; | |
| } | |
| core.setOutput('run_ci', 'false'); | |
| core.setOutput('reason', 'non-fork PR without .github/suite.py changes'); | |
| - name: Print results | |
| run: | | |
| echo "run_ci=${{ steps.decision.outputs.run_ci }}" | |
| echo "reason=${{ steps.decision.outputs.reason }}" | |
| abi-check: | |
| if: needs.should-run.outputs.run_ci == 'true' | |
| needs: should-run | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install libabigail | |
| shell: bash | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y abigail-tools | |
| - name: Get mx and labsjdk | |
| shell: bash | |
| run: | | |
| git config --global http.timeout 600 | |
| git clone https://github.com/graalvm/mx | |
| ./mx/mx fetch-jdk -A --jdk-id labsjdk-ce-latest | |
| - name: Setup mx and JAVA_HOME | |
| shell: bash | |
| run: | | |
| echo "$(pwd)/mx/" >> "$GITHUB_PATH" | |
| echo "JAVA_HOME=$HOME/.mx/jdks/labsjdk-ce-latest" >> "$GITHUB_ENV" | |
| echo "JVMCI_VERSION_CHECK=ignore" >> "$GITHUB_ENV" | |
| - name: Run abi-check | |
| shell: bash | |
| run: mx abi-check | |
| build-standalone-artifacts: | |
| if: needs.should-run.outputs.run_ci == 'true' && success() | |
| needs: should-run | |
| uses: ./.github/workflows/ci-matrix-gen.yml | |
| with: | |
| jobs_to_run: ^(?:python-svm-build|style|style-ecj)-gate-.*$ | |
| logs_retention_days: 0 | |
| artifacts_retention_days: 0 | |
| run-tests: | |
| if: needs.should-run.outputs.run_ci == 'true' && success() | |
| needs: [should-run, build-standalone-artifacts] | |
| uses: ./.github/workflows/ci-matrix-gen.yml | |
| with: | |
| jobs_to_run: ^(?!python-svm-build|style).*-gate.*$ | |
| export_test_reports: true | |
| collect-reports: | |
| if: needs.should-run.outputs.run_ci == 'true' && always() | |
| needs: [should-run, run-tests] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download test reports | |
| uses: actions/download-artifact@v5 | |
| with: | |
| pattern: '*_test_reports' | |
| merge-multiple: true | |
| path: test-reports | |
| - name: Merge test reports | |
| run: | | |
| python3 .github/scripts/merge_reports.py \ | |
| --outfile merged_test_reports.json \ | |
| --dir test-reports \ | |
| --pattern "**/*.json" \ | |
| --status-filter "failed" | |
| - name: Upload merged test report | |
| if: always() | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: merged_test_reports | |
| path: merged_test_reports.json | |
| if-no-files-found: ignore |