diff --git a/.github/.cache_version b/.github/.cache_version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/.github/.cache_version @@ -0,0 +1 @@ +1 diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 33c3574b29..fad3ac8125 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -13,6 +13,10 @@ inputs: runs: using: composite steps: + - name: Read current GitHub Actions cache version + shell: bash + run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV + # JavaScript setup - name: Get yarn cache directory path shell: bash diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 32432b407e..4e89564a6f 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -5,6 +5,10 @@ description: Setup CI environment. runs: using: composite steps: + - name: Read current GitHub Actions cache version + shell: bash + run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV + - name: Install Java uses: actions/setup-java@v2 with: @@ -29,9 +33,11 @@ runs: shell: bash run: | previousCommit=${{ github.event.before }} - baseRef=${{ steps.diff.outputs.ORIGIN_BRANCH }} + baseRef=${{ github.base_ref }} origin=$( [[ -z $baseRef ]] && echo $previousCommit || echo "origin/$baseRef" ) + echo "Checking diff with branch: $origin" + echo "::set-output name=GITHUB_ACTIONS_CHANGED::$(git diff --shortstat $origin..HEAD -- .github/actions .github/workflows | wc -l)" echo "::set-output name=SPECS_CHANGED::$(git diff --shortstat $origin..HEAD -- specs | wc -l)" @@ -87,9 +93,9 @@ runs: algoliasearch_client='{"name": "algoliasearch","folder": "clients/algoliasearch-client-javascript/packages/algoliasearch"}' if [[ $matrix == '{"client":["no-run"]}' ]]; then - matrix="{'client': [$algoliasearch_client]}" + matrix="{\"client\": [$algoliasearch_client]}" else - matrix="{'client': $(echo $matrix | jq ".client + [$algoliasearch_client]" -c)}" + matrix="{\"client\": $(echo $matrix | jq ".client + [$algoliasearch_client]" -c)}" fi fi @@ -152,15 +158,19 @@ runs: outputs: RUN_SPECS: - description: Whether to run specs or not + description: Determine if the `specs` job should run value: ${{ steps.spec-matrix.outputs.RUN_SPECS }} + RUN_SCRIPTS: + description: Determine if the `scripts` job should run + value: ${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 }} + SPECS_MATRIX: - description: Generate the matrix for specs + description: The generated `specs` matrix value: ${{ steps.spec-matrix.outputs.MATRIX }} RUN_JS: - description: Whether to run js client or not + description: Determine if the `client-javascript` job should run value: ${{ steps.js-matrix.outputs.RUN_CLIENT }} RUN_JS_COMMON: @@ -168,25 +178,41 @@ outputs: value: ${{ steps.js-matrix.outputs.RUN_COMMON }} JS_MATRIX: - description: Generate the matrix for the Javascript client + description: The generated `client-javascript` matrix value: ${{ steps.js-matrix.outputs.MATRIX }} RUN_JAVA: - description: Whether to run java client or not + description: Determine if the `client-java` job should run value: ${{ steps.java-matrix.outputs.RUN_CLIENT }} JAVA_MATRIX: - description: Generate the matrix for the Java client + description: The generated `client-java` matrix value: ${{ steps.java-matrix.outputs.MATRIX }} RUN_PHP: - description: Whether to run php client or not + description: Determine if the `client-php` job should run value: ${{ steps.php-matrix.outputs.RUN_CLIENT }} PHP_MATRIX: - description: Generate the matrix for the PHP client + description: The generated `client-php` matrix value: ${{ steps.php-matrix.outputs.MATRIX }} RUN_CTS: description: Determine if the `cts` job should run - value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.SPECS_CHANGED > 0 || steps.diff.outputs.TESTS_CHANGED > 0 || steps.diff.outputs.JS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }} + value: ${{ + steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || + steps.diff.outputs.SCRIPTS_CHANGED > 0 || + steps.diff.outputs.SPECS_CHANGED > 0 || + steps.diff.outputs.TESTS_CHANGED > 0 || + steps.diff.outputs.JS_CLIENT_CHANGED > 0 || + steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || + steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || + steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }} + + RUN_CODEGEN: + description: Determine if the `codegen` job should run + value: ${{ + steps.spec-matrix.outputs.RUN_SPECS == 'true' || + steps.js-matrix.outputs.RUN_CLIENT == 'true' || + steps.java-matrix.outputs.RUN_CLIENT == 'true' || + steps.php-matrix.outputs.RUN_CLIENT == 'true' }} diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index b7ae1804b7..a0a1907f9a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -7,9 +7,6 @@ on: branches: - main -env: - CACHE_VERSION: '9' - concurrency: group: ${{ github.ref }} cancel-in-progress: true @@ -31,6 +28,8 @@ jobs: run: yarn github-actions:lint outputs: + RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }} + RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }} SPECS_MATRIX: ${{ steps.setup.outputs.SPECS_MATRIX }} @@ -46,10 +45,13 @@ jobs: RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }} + RUN_CODEGEN: ${{ steps.setup.outputs.RUN_CODEGEN }} + scripts: runs-on: ubuntu-20.04 - needs: setup timeout-minutes: 20 + needs: setup + if: ${{ needs.setup.outputs.RUN_SCRIPTS == 'true' }} steps: - uses: actions/checkout@v2 @@ -66,7 +68,7 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 10 needs: setup - if: ${{ always() && needs.setup.outputs.RUN_SPECS == 'true' }} + if: ${{ needs.setup.outputs.RUN_SPECS == 'true' }} strategy: matrix: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX) }} steps: @@ -95,7 +97,7 @@ jobs: timeout-minutes: 10 runs-on: ubuntu-20.04 needs: setup - if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }} + if: ${{ needs.setup.outputs.RUN_JS_COMMON == 'true' }} strategy: matrix: client: @@ -131,7 +133,7 @@ jobs: - setup - specs - client_javascript_common - if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }} + if: ${{ needs.setup.outputs.RUN_JS == 'true' }} strategy: matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }} steps: @@ -170,7 +172,7 @@ jobs: needs: - setup - specs - if: ${{ always() && needs.setup.outputs.RUN_JAVA == 'true' }} + if: ${{ needs.setup.outputs.RUN_JAVA == 'true' }} strategy: matrix: ${{ fromJSON(needs.setup.outputs.JAVA_MATRIX) }} steps: @@ -209,7 +211,7 @@ jobs: needs: - setup - specs - if: ${{ always() && needs.setup.outputs.RUN_PHP == 'true' }} + if: ${{ needs.setup.outputs.RUN_PHP == 'true' }} strategy: matrix: ${{ fromJSON(needs.setup.outputs.PHP_MATRIX) }} steps: @@ -248,7 +250,11 @@ jobs: - client_javascript - client_java - client_php - if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }} + if: | + always() && + needs.setup.outputs.RUN_CTS == 'true' && + contains(needs.*.result, 'success') && + !contains(needs.*.result, 'failure') steps: - uses: actions/checkout@v2 @@ -271,8 +277,11 @@ jobs: codegen: runs-on: ubuntu-20.04 timeout-minutes: 10 - if: ${{ always() }} needs: cts + if: | + always() && + needs.setup.outputs.RUN_CODEGEN == 'true' && + needs.cts.result == 'success' steps: - uses: actions/checkout@v2 with: diff --git a/.github/workflows/codegen-cleanup.yml b/.github/workflows/codegen-cleanup.yml index 02b40f7c00..bd5f198ffb 100644 --- a/.github/workflows/codegen-cleanup.yml +++ b/.github/workflows/codegen-cleanup.yml @@ -4,9 +4,6 @@ on: pull_request: types: [closed] -env: - CACHE_VERSION: '9' - jobs: codegen: runs-on: ubuntu-20.04 @@ -18,7 +15,6 @@ jobs: ref: main - name: Setup - id: setup uses: ./.github/actions/setup - name: Clean previously generated branch diff --git a/.github/workflows/process-release.yml b/.github/workflows/process-release.yml index f1b6a46113..0e2efd57d0 100644 --- a/.github/workflows/process-release.yml +++ b/.github/workflows/process-release.yml @@ -5,9 +5,6 @@ on: types: - closed -env: - CACHE_VERSION: '9' - jobs: build: name: Release