From 86938b7e84f8dca403305db56fa014553b022820 Mon Sep 17 00:00:00 2001 From: skywalker Date: Mon, 22 Jul 2024 12:22:09 +0300 Subject: [PATCH] fix(ci): `check-changes` job works incorrectly --- .github/workflows/cicd.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 0fc35a97..39e113cd 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -23,12 +23,33 @@ jobs: - name: Check for changes in source files id: check_changes run: | - if git diff --quiet HEAD^ HEAD -- '**/*.kt'; then - echo "No changes in Kotlin files." - echo "changed=false" >> $GITHUB_ENV + git log + + # Check if there's at least one commit in the repository + if git rev-parse --verify HEAD >/dev/null 2>&1; then + # Check if there's more than one commit + if [ $(git rev-list --count HEAD) -gt 1 ]; then + # Perform the diff check for Kotlin files + if git diff --quiet HEAD^ HEAD -- '**/*.kt'; then + echo "No changes in Kotlin files." + echo "changed=false" >> $GITHUB_ENV + else + echo "Changes detected in Kotlin files." + echo "changed=true" >> $GITHUB_ENV + fi + else + # Only one commit exists, perform diff check from an empty tree + if git diff --quiet $(git hash-object -t tree /dev/null) HEAD -- '**/*.kt'; then + echo "No changes in Kotlin files." + echo "changed=false" >> $GITHUB_ENV + else + echo "Changes detected in Kotlin files." + echo "changed=true" >> $GITHUB_ENV + fi + fi else - echo "Changes detected in Kotlin files." - echo "changed=true" >> $GITHUB_ENV + echo "No commits in the repository." + echo "changed=false" >> $GITHUB_ENV fi linter: