Skip to content

Commit

Permalink
Fix issue with 'createchangelog' workflow always switching to Git Det…
Browse files Browse the repository at this point in the history
…ached Head Mode
  • Loading branch information
og-mrk committed Jul 29, 2024
1 parent c63c9aa commit 0d12b0c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/createchangelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ jobs:
submodules: 'recursive'
ref: ${{ github.ref }}

- name: Get correct branch to use for committing changes
id: get_correct_branch
run: |
# NOTE/TODO:
# Because there's a chance where this'll get triggered by a Release Creation, Edit, Deletion..
# the value of 'github.ref' will be 'refs/tags/TAG-NAME', and this tag can not be handled easily by
# the 'actions/checkout' action.. we need to handle this case by always changing to main branch.
declare -rA number_of_refname_instances=$(git branch -a | grep -Po '${{ github.ref_name }}' | wc --lines)
if [[ $number_of_refname_instances = 0 ]] ; then
echo "branch_name=main" >> $GITHUB_OUTPUT
else
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Get all releases and update changelog.md file
run: |
# Initialize some values
Expand Down Expand Up @@ -112,17 +126,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ['${{ github.event_name }}' = 'release']; then
git branch --contains ${{ github.ref }} | grep -Po '\*\s*.*' | sed 's/\* //g' > branch_name.txt
fi
cat branch_name.txt
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git switch ${{ steps.get_correct_branch.outputs.branch_name }}
git pull
git add docs/changelog.md
git commit -m "Update changelog.md with all releases"
echo "Event name: ${{ github.event_name }}"
if ['${{ github.event_name }}' = 'release']; then
git push --force
else
git push
fi
git push

0 comments on commit 0d12b0c

Please sign in to comment.