diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e4977dc04..4ceb99b984 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,8 @@ jobs: fetch-depth: 0 - name: Check changelog run: bash .github/workflows/scripts/check-changelog.sh + env: + SHA: ${{ github.sha }} lints: container: diff --git a/.github/workflows/scripts/check-changelog.sh b/.github/workflows/scripts/check-changelog.sh index 870267160e..f4d73c30f0 100755 --- a/.github/workflows/scripts/check-changelog.sh +++ b/.github/workflows/scripts/check-changelog.sh @@ -1,21 +1,28 @@ #!/bin/bash check_changelog_added_in_subfolders() { - current_branch=$(git rev-parse --abbrev-ref HEAD) + if [[ -z "${SHA}" ]]; then + head_commit=$(git rev-parse HEAD) + else + head_commit="${SHA}" + fi + echo "Using sha: $head_commit" subfolders=("ci" "bug-fixes" "improvements" "miscellaneous" "features" "testing" "docs") subfolder_pattern=$(printf "|%s" "${subfolders[@]}") subfolder_pattern=${subfolder_pattern:1} # Remove the leading '|' - added_files=$(git diff --diff-filter=A --name-only "main..$current_branch" | grep "\.changelog/") + added_files=$(git diff --diff-filter=A --name-only "main..$head_commit" | grep "\.changelog/") relevant_files=$(echo "$added_files" | grep -E "\.changelog/unreleased/($subfolder_pattern)/") if [ -n "$relevant_files" ]; then echo "Changelog found: $relevant_files" + exit 0 else echo "No files were added in the .changelog directory in the specified subfolders." + exit 1 fi }