Skip to content

Commit

Permalink
ci: fix bad revision on main branch (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Mar 14, 2022
1 parent 853dd99 commit ef01e47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
48 changes: 27 additions & 21 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"}'
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/create-client-matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/create-spec-matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
Expand Down

0 comments on commit ef01e47

Please sign in to comment.