refactor how base and head commit are set

- avoid `github.event.after` as it isn't available during initial CI run of the PR
This commit is contained in:
MicroDev 2023-01-07 21:03:16 +05:30
parent 70273316f8
commit f0e7e3115a
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730

View File

@ -135,27 +135,23 @@ jobs:
GITHUB_TOKEN: ${{ github.token }} GITHUB_TOKEN: ${{ github.token }}
EXCLUDE_COMMIT: ${{ github.event.after }} EXCLUDE_COMMIT: ${{ github.event.after }}
run: python3 -u ci_changes_per_commit.py run: python3 -u ci_changes_per_commit.py
- name: Deepen and convert depth to sha - name: Set base sha
id: deepen-and-convert-depth-to-sha
run: | run: |
DEEPEN=$((DEPTH - $(git rev-list HEAD --count))) && if((DEEPEN > 0)); then git fetch --no-tags --recurse-submodules=no --deepen=$DEEPEN; fi DEEPEN=$((DEPTH - $(git rev-list HEAD --count))) && if((DEEPEN > 0)); then git fetch --no-tags --recurse-submodules=no --deepen=$DEEPEN; fi
echo "commit=$(git rev-list $GITHUB_SHA --skip=$((DEPTH + 1)) --max-count=1)" >> $GITHUB_OUTPUT echo "BASE_SHA=$(git rev-list $GITHUB_SHA --skip=$((DEPTH + 1)) --max-count=1)" >> $GITHUB_ENV
env: env:
DEPTH: ${{ steps.get-last-commit-with-checks.outputs.commit_depth || github.event.pull_request.commits }} DEPTH: ${{ steps.get-last-commit-with-checks.outputs.commit_depth || github.event.pull_request.commits }}
- name: Set head sha
run: echo "HEAD_SHA=$(git rev-list $GITHUB_SHA --skip=1 --max-count=1)" >> $GITHUB_ENV
- name: Get changes - name: Get changes
id: get-changes id: get-changes
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT
env:
BASE_SHA: ${{ steps.deepen-and-convert-depth-to-sha.outputs.commit }}
HEAD_SHA: ${{ github.event.after }}
- name: Set matrix - name: Set matrix
id: set-matrix id: set-matrix
working-directory: tools working-directory: tools
run: python3 -u ci_set_matrix.py run: python3 -u ci_set_matrix.py
env: env:
BASE_SHA: ${{ steps.deepen-and-convert-depth-to-sha.outputs.commit }}
HEAD_SHA: ${{ github.event.after }}
CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }} CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }}
LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }} LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }}