diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 1e155cd1ac..32432b407e 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -28,33 +28,39 @@ runs: id: diff shell: bash run: | - echo "::set-output name=GITHUB_ACTIONS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- .github/actions .github/workflows | wc -l)" + previousCommit=${{ github.event.before }} + baseRef=${{ steps.diff.outputs.ORIGIN_BRANCH }} + origin=$( [[ -z $baseRef ]] && echo $previousCommit || echo "origin/$baseRef" ) - echo "::set-output name=SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs | wc -l)" - echo "::set-output name=COMMON_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/common | wc -l)" + echo "::set-output name=GITHUB_ACTIONS_CHANGED::$(git diff --shortstat $origin..HEAD -- .github/actions .github/workflows | wc -l)" - echo "::set-output name=TESTS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- tests | wc -l)" + echo "::set-output name=SPECS_CHANGED::$(git diff --shortstat $origin..HEAD -- specs | wc -l)" + echo "::set-output name=COMMON_SPECS_CHANGED::$(git diff --shortstat $origin..HEAD -- specs/common | wc -l)" - echo "::set-output name=SCRIPTS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- scripts | wc -l)" + echo "::set-output name=TESTS_CHANGED::$(git diff --shortstat $origin..HEAD -- tests | wc -l)" - echo "::set-output name=JS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript | wc -l)" - echo "::set-output name=JS_ALGOLIASEARCH_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/packages/algoliasearch clients/algoliasearch-client-javascript/packages/client-search clients/algoliasearch-client-javascript/packages/client-analytics clients/algoliasearch-client-javascript/packages/client-personalization | wc -l)" - echo "::set-output name=JS_COMMON_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/packages/client-common clients/algoliasearch-client-javascript/packages/requester-browser-xhr clients/algoliasearch-client-javascript/packages/requester-node-http | wc -l)" - echo "::set-output name=JS_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/javascript | wc -l)" + echo "::set-output name=SCRIPTS_CHANGED::$(git diff --shortstat $origin..HEAD -- scripts | wc -l)" - echo "::set-output name=JAVA_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-java-2 | wc -l)" - echo "::set-output name=JAVA_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/java | wc -l)" + echo "::set-output name=JS_CLIENT_CHANGED::$(git diff --shortstat $origin..HEAD -- clients/algoliasearch-client-javascript | wc -l)" + echo "::set-output name=JS_ALGOLIASEARCH_CHANGED::$(git diff --shortstat $origin..HEAD -- clients/algoliasearch-client-javascript/packages/algoliasearch clients/algoliasearch-client-javascript/packages/client-search clients/algoliasearch-client-javascript/packages/client-analytics clients/algoliasearch-client-javascript/packages/client-personalization | wc -l)" + echo "::set-output name=JS_COMMON_CHANGED::$(git diff --shortstat $origin..HEAD -- clients/algoliasearch-client-javascript/packages/client-common clients/algoliasearch-client-javascript/packages/requester-browser-xhr clients/algoliasearch-client-javascript/packages/requester-node-http | wc -l)" + echo "::set-output name=JS_TEMPLATE_CHANGED::$(git diff --shortstat $origin..HEAD -- templates/javascript | wc -l)" - echo "::set-output name=PHP_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-php | wc -l)" - echo "::set-output name=PHP_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/php | wc -l)" + echo "::set-output name=JAVA_CLIENT_CHANGED::$(git diff --shortstat $origin..HEAD -- clients/algoliasearch-client-java-2 | wc -l)" + echo "::set-output name=JAVA_TEMPLATE_CHANGED::$(git diff --shortstat $origin..HEAD -- templates/java | wc -l)" + + echo "::set-output name=PHP_CLIENT_CHANGED::$(git diff --shortstat $origin..HEAD -- clients/algoliasearch-client-php | wc -l)" + echo "::set-output name=PHP_TEMPLATE_CHANGED::$(git diff --shortstat $origin..HEAD -- templates/php | wc -l)" + + echo "::set-output name=ORIGIN_BRANCH::$origin" - name: Compute specs matrix id: spec-matrix shell: bash run: | - base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 }} + base_changed=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 }} - matrix=$(./scripts/ci/create-spec-matrix.sh $base_changed ${{ github.base_ref }}) + matrix=$(./scripts/ci/create-spec-matrix.sh $base_changed ${{ steps.diff.outputs.ORIGIN_BRANCH }}) if [[ $matrix == '{"client":["no-run"]}' ]]; then run="false" @@ -72,10 +78,10 @@ runs: id: js-matrix shell: bash run: | - base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }} + base_changed=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }} algoliasearch_changed=${{ steps.diff.outputs.JS_ALGOLIASEARCH_CHANGED > 0 }} - matrix=$(./scripts/ci/create-client-matrix.sh javascript $base_changed ${{ github.base_ref }}) + matrix=$(./scripts/ci/create-client-matrix.sh javascript $base_changed ${{ steps.diff.outputs.ORIGIN_BRANCH }}) if [[ $algoliasearch_changed == 'true' || $base_changed == 'true' ]]; then algoliasearch_client='{"name": "algoliasearch","folder": "clients/algoliasearch-client-javascript/packages/algoliasearch"}' @@ -108,9 +114,9 @@ runs: id: java-matrix shell: bash run: | - base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }} + base_changed=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }} - matrix=$(./scripts/ci/create-client-matrix.sh java $base_changed ${{ github.base_ref }}) + matrix=$(./scripts/ci/create-client-matrix.sh java $base_changed ${{ steps.diff.outputs.ORIGIN_BRANCH }}) if [[ $matrix == '{"client":["no-run"]}' ]]; then run="false" @@ -128,9 +134,9 @@ runs: id: php-matrix shell: bash run: | - base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }} + base_changed=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }} - matrix=$(./scripts/ci/create-client-matrix.sh php $base_changed ${{ github.base_ref }}) + matrix=$(./scripts/ci/create-client-matrix.sh php $base_changed ${{ steps.diff.outputs.ORIGIN_BRANCH }}) if [[ $matrix == '{"client":["no-run"]}' ]]; then run="false" diff --git a/scripts/ci/create-client-matrix.sh b/scripts/ci/create-client-matrix.sh index 0d7e292157..67a9319d17 100755 --- a/scripts/ci/create-client-matrix.sh +++ b/scripts/ci/create-client-matrix.sh @@ -23,8 +23,8 @@ to_test='{"client": []}' for pair in $CLIENTS; do name=$(echo $pair | jq -r '.name') folder=$(echo $pair | jq -r '.folder') - spec_changed=$(git diff --shortstat origin/$BASE_BRANCH..HEAD -- specs/$name | wc -l | tr -d ' ') - client_changed=$(git diff --stat origin/$BASE_BRANCH..HEAD -- $folder | wc -l | tr -d ' ') + spec_changed=$(git diff --shortstat $BASE_BRANCH..HEAD -- specs/$name | wc -l | tr -d ' ') + client_changed=$(git diff --stat $BASE_BRANCH..HEAD -- $folder | wc -l | tr -d ' ') if [[ $BASE_CHANGED == "true" || $spec_changed != "0" || $client_changed != "0" ]]; then to_test=$(echo $to_test | jq --argjson pair $pair '.client |= .+ [$pair]') fi diff --git a/scripts/ci/create-spec-matrix.sh b/scripts/ci/create-spec-matrix.sh index 749ea7dbbc..96e46f1e1e 100755 --- a/scripts/ci/create-spec-matrix.sh +++ b/scripts/ci/create-spec-matrix.sh @@ -10,7 +10,7 @@ to_check='{"client":[]}' for generator in "${GENERATORS[@]}"; do client=${generator#*-} if [[ ! ${SPECS[*]} =~ $client ]]; then - changed=$(git diff --shortstat origin/$BASE_BRANCH..HEAD -- specs/$client | wc -l) + changed=$(git diff --shortstat $BASE_BRANCH..HEAD -- specs/$client | wc -l) SPECS+=($client) if [[ $BASE_CHANGED == "true" || $changed > 0 ]]; then to_check=$(echo $to_check | jq --arg client $client '.client |= .+ [$client]')