Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix CI matrix, fix job skipping #250

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/.cache_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
4 changes: 4 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 38 additions & 12 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -152,41 +158,61 @@ 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:
description: Whether to build JS client common folders when RUN_JS is false
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' }}
31 changes: 20 additions & 11 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
branches:
- main

env:
CACHE_VERSION: '9'

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
Expand All @@ -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 }}

Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/codegen-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
types: [closed]

env:
CACHE_VERSION: '9'

jobs:
codegen:
runs-on: ubuntu-20.04
Expand All @@ -18,7 +15,6 @@ jobs:
ref: main

- name: Setup
id: setup
uses: ./.github/actions/setup

- name: Clean previously generated branch
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/process-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
types:
- closed

env:
CACHE_VERSION: '9'

jobs:
build:
name: Release
Expand Down