feat(ci): automatic changelog (#2005)

* chore(changelog): automatic changelog

* fix(ci): multiple commits causing issues

* fix(ci): spelling

* fix(ci): don't force push
pull/2006/head
nuxen 5 months ago committed by GitHub
parent 18b14faf9f
commit 0dae273c1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,20 @@
#!/bin/bash
log_file="$1"
output_file="docs/updates.txt"
current_time=$(date +"%F %H:%M")
formatted_output="# $current_time"
while IFS= read -r message; do
pr_number=$(echo "$message" | grep -oE '\(#[0-9]+\)$' | tr -d '(#)')
formatted_message=$(echo "$message" | sed -E 's/ \(#[0-9]+\)$//')
formatted_output+="
- [$formatted_message](https://github.com/TRaSH-Guides/Guides/pull/${pr_number})"
done < "$log_file"
formatted_output+="\n"
{
echo -e "$formatted_output"
cat "$output_file"
} > "${output_file}.tmp" && mv "${output_file}.tmp" "$output_file"

@ -0,0 +1,55 @@
name: Update changelog
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
permissions:
contents: write
jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.6
with:
fetch-depth: 0
- name: Get last edit time of docs/updates.txt
run: |
last_edit_time=$(git log -1 --pretty="format:%cI" docs/updates.txt)
echo "Last edit time: $last_edit_time"
echo "LAST_EDIT_TIME=$last_edit_time" >> $GITHUB_ENV
- name: Run git log
run: |
git log --no-merges --perl-regexp --author='^(?!.*(\[bot\]|actions@github\.com)).*$' --grep='^(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert|update)(\(.*?\))?:' --since="${{ env.LAST_EDIT_TIME }}" --pretty="%s" > log_output.txt
- name: Check if there are new commits
run: |
if [ -s log_output.txt ]; then
echo "NEW_COMMITS=true" >> $GITHUB_ENV
else
echo "No new commits since the last update of docs/updates.txt."
echo "NEW_COMMITS=false" >> $GITHUB_ENV
fi
- name: Run update script
if: env.NEW_COMMITS == 'true'
run: |
chmod +x .github/scripts/update-changelog.sh
.github/scripts/update-changelog.sh log_output.txt
- name: Commit and push if it's not up to date
if: env.NEW_COMMITS == 'true'
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git diff
git commit -am "chore(changelog): Update updates.txt" || exit 0
git push https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }}.git HEAD:master
Loading…
Cancel
Save