diff --git a/.github/workflows/createchangelog.yaml b/.github/workflows/createchangelog.yaml index 52a47d1920..f9726834fb 100644 --- a/.github/workflows/createchangelog.yaml +++ b/.github/workflows/createchangelog.yaml @@ -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 @@ -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