forked from Passer1072/RookieAI_yolov8
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,52 @@ | ||
name: Update Changelog | ||
name: Generate Changelog | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
- dev # 根据需要修改分支 | ||
|
||
permissions: | ||
contents: write | ||
contents: write # 允许写入内容 | ||
|
||
jobs: | ||
update-changelog: | ||
generate-changelog: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
- name: Get commits | ||
id: get_commits | ||
run: | | ||
if [ -f CHANGELOG.md ]; then | ||
LAST_UPDATE=$(grep -m 1 "## " CHANGELOG.md | awk '{print $2}' | tr -d '[]') | ||
git log --since="$LAST_UPDATE" --pretty=format:"- %s" > commits.txt || echo "No new commits" | ||
else | ||
# 直接获取所有提交,并确保格式正确 | ||
git log --pretty=format:"- %s" --reverse > commits.txt || echo "No commits found" | ||
fi | ||
if [[ -s commits.txt ]]; then | ||
echo "Commits=$(cat commits.txt)" >> $GITHUB_ENV | ||
else | ||
echo "Commits=No new commits" >> $GITHUB_ENV | ||
fi | ||
- name: Update or create CHANGELOG.md | ||
run: | | ||
if [[ "$(echo ${{ env.Commits }})" != "No new commits" ]]; then | ||
if [ ! -f CHANGELOG.md ]; then | ||
echo "# Changelog" > CHANGELOG.md | ||
fi | ||
# 分组提交,并按时间降序排列 | ||
echo "${{ env.Commits }}" | awk -F ' - ' ' | ||
{ | ||
date=$1; | ||
commit=$2; | ||
commits[date] = (commits[date] ? commits[date] ORS : "") "- " commit; | ||
} | ||
END { | ||
n = asorti(commits, dates); | ||
for (i = n; i > 0; i--) { | ||
print "## [" dates[i] "] - Update"; | ||
print commits[dates[i]]; | ||
print ""; | ||
} | ||
}' >> CHANGELOG.md # 直接追加到 CHANGELOG.md | ||
fi | ||
- name: Commit and Push Changes | ||
run: | | ||
git add CHANGELOG.md | ||
git commit -m "Update CHANGELOG.md with latest commits $(git rev-parse --short HEAD) (PR #${{ github.event.pull_request.number }})" || echo "No changes to commit" | ||
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/Passer1072/RookieAI_yolov8 HEAD:dev | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Check for existing CHANGELOG.md | ||
id: check_changelog | ||
run: | | ||
if [ ! -f CHANGELOG.md ]; then | ||
echo "CHANGELOG.md does not exist." | ||
echo "create=true" >> $GITHUB_ENV | ||
else | ||
echo "CHANGELOG.md exists." | ||
echo "create=false" >> $GITHUB_ENV | ||
fi | ||
- name: Generate or Update CHANGELOG.md | ||
run: | | ||
if [ "${{ env.create }}" == "true" ]; then | ||
echo "# Changelog" > CHANGELOG.md | ||
# 获取所有提交信息并倒序写入 | ||
git log --reverse --date=short --pretty=format:"* %ad - %h - %s (%an)" >> CHANGELOG.md | ||
else | ||
echo "Updating existing CHANGELOG.md" | ||
echo "" >> CHANGELOG.md | ||
echo "## Latest Changes" >> CHANGELOG.md | ||
# 获取最新提交信息并写入 | ||
git log -1 --date=short --pretty=format:"* %ad - %h - %s (%an)" >> CHANGELOG.md | ||
fi | ||
- name: Commit and push changes | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
git add CHANGELOG.md | ||
git commit -m "Update CHANGELOG.md with new entries (hash: $(git rev-parse --short HEAD))" | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |