Refactor workflows to address Gradle cache usage #2
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
name: PR-Test | |
on: | |
pull_request: | |
merge_group: | |
permissions: | |
contents: read | |
concurrency: | |
group: "PR-Test: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" | |
cancel-in-progress: true | |
jobs: | |
primary-tests: | |
name: Determine workflows to run | |
runs-on: ubuntu-latest | |
outputs: | |
run_docs: ${{ steps.docs-changed.outputs.exists }} | |
run_tests: ${{ steps.non-docs-changed.outputs.exists }} | |
steps: | |
# https://github.com/actions/checkout | |
- name: "Checkout" | |
uses: "actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332" # v4.1.7 | |
- name: "Doc changes" | |
uses: yumemi-inc/changed-files@v3 | |
id: docs-changed | |
with: | |
patterns: | | |
documentation/** | |
- name: "Non-doc changes" | |
uses: yumemi-inc/changed-files@v3 | |
id: non-docs-changed | |
with: | |
patterns: | | |
!documentation/** | |
- name: Setup build | |
if: ${{ steps.non-docs-changed.outputs.exists }} | |
uses: ./.github/actions/setup-build | |
with: | |
cc-encryption-key: ${{ secrets.GRADLE_CONFIGURATION_CACHE_ENCRYPTION_KEY }} | |
- name: "Run tests" | |
if: ${{ steps.non-docs-changed.outputs.exists }} | |
run: ./gradlew apiCheck --continue | |
- uses: actions/setup-node@v4 | |
if: ${{ steps.docs-changed.outputs.exists }} | |
with: | |
node-version: '18.4.0' | |
- name: Build static docusaurus pages | |
if: ${{ steps.docs-changed.outputs.exists }} | |
run: | | |
npm --prefix documentation ci | |
npm --prefix documentation run build | |
- name: Post build | |
uses: ./.github/actions/post-build | |
secondary-tests: | |
name: Run gradle check | |
if: ${{ needs.primary-tests.outputs.run_tests == 'true' }} | |
needs: [ primary-tests ] | |
strategy: | |
matrix: | |
include: | |
- os: macos-latest | |
- os: ubuntu-latest | |
- os: windows-latest | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
steps: | |
# https://github.com/actions/checkout | |
- name: "Checkout" | |
uses: "actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332" # v4.1.7 | |
- name: Setup build | |
uses: ./.github/actions/setup-build | |
with: | |
cc-encryption-key: ${{ secrets.GRADLE_CONFIGURATION_CACHE_ENCRYPTION_KEY }} | |
- name: Validate tests | |
run: ./gradlew check --continue | |
shell: bash | |
- name: Post build | |
uses: ./.github/actions/post-build | |
finalize: | |
# see https://github.community/t/status-check-for-a-matrix-jobs/127354/7 | |
name: Final PR results | |
needs: [ primary-tests, secondary-tests ] | |
if: ${{ always() }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check all job status | |
# see https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context | |
# see https://stackoverflow.com/a/67532120/4907315 | |
# Note: skipped results are OK in our case, we don't run code tests if there's only docs changes | |
if: >- | |
${{ | |
contains(needs.*.result, 'failure') | |
|| contains(needs.*.result, 'cancelled') | |
}} | |
run: exit 1 |