Skip to content

Commit

Permalink
Adjusting changelog automation to leverage GH api
Browse files Browse the repository at this point in the history
  • Loading branch information
henrykie committed Sep 13, 2024
1 parent f81893d commit ad693d0
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,25 @@ jobs:
with:
fetch-depth: 0
- name: Update Changelog
run: |
git fetch --tags origin
docker run --rm -v $(pwd):/workdir quay.io/git-chglog/git-chglog -o CHANGELOG.md
# - name: Create Pull Request
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# run: |
# git config user.name github-actions[bot]
# git config user.email 41898282+github-actions[bot]@users.noreply.github.com
# git config user.signingkey
# git config commit.gpgsign true
# git checkout -b changelog-update-${{ github.run_id }}
# git add .
# git commit -m "Update Changelog"
# git push origin changelog-update-${{ github.run_id }}
# gh version
# gh pr create --title "chore: update changelog" --body "This is an auto-generated PR to update the changelog." --base main --head changelog-update-${{ github.run_id }}
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_TO_COMMIT: CHANGELOG.md
DESTINATION_BRANCH: changelog
DESTINATION_BRANCH: changelog-${{ github.run_id }}
run: |
git fetch --tags origin
docker run --rm -v $(pwd):/workdir quay.io/git-chglog/git-chglog -o CHANGELOG.md
export TODAY=$( date -u '+%Y-%m-%d' )
export MESSAGE="chore: regenerate $FILE_TO_COMMIT for $TODAY"
export SHA=$( git rev-parse $DESTINATION_BRANCH:$FILE_TO_COMMIT )
export CONTENT=$( base64 -i $FILE_TO_COMMIT )
export BRANCH_SHA=$( gh api /repos/:owner/:repo/git/ref/heads/main | jq .sha | tr -d '"')
gh api --method POST /repos/:owner/:repo/git/refs \
--field "ref=refs/heads/$DESTINATION_BRANCH" \
--field "sha=$BRANCH_SHA"
export SHA=$( gh api -XGET /repos/:owner/:repo/contents/$FILE_TO_COMMIT -F ref=refs/heads/$DESTINATION_BRANCH | jq .sha | tr -d '"')
gh api --method PUT /repos/:owner/:repo/contents/$FILE_TO_COMMIT \
--field message="$MESSAGE" \
--field content="$CONTENT" \
--field encoding="base64" \
--field branch="$DESTINATION_BRANCH" \
--field sha="$SHA"
--field sha=$SHA
gh pr create --title "chore: update changelog" --body "This is an auto-generated PR to update the changelog." --base main --head $DESTINATION_BRANCH

0 comments on commit ad693d0

Please sign in to comment.