From 90af7b4d28ab62de1bf476d276a9197fd67201f7 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:40:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/update-changelog.yml | 50 +++++++++++++++++--------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 0986d14..4717984 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -10,29 +10,47 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Checkout repository uses: actions/checkout@v2 - - name: Update Changelog + - name: Set up Git run: | - CHANGELOG_FILE="CHANGELOG.md" + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" - COMMITS=$(git log --pretty=format:'- %s (%h)' --date=format:'%Y-%m-%d' -1) + - name: Get current date + id: current_date + run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - if [ ! -f $CHANGELOG_FILE ]; then - echo "# Changelog" > $CHANGELOG_FILE + - 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" > commits.txt || echo "No commits found" fi - TODAY=$(date +'%Y-%m-%d') + if [[ -s commits.txt ]]; then + echo "Commits=$(cat commits.txt)" >> $GITHUB_ENV + else + echo "Commits=No new commits" >> $GITHUB_ENV + fi - echo -e "\n## $TODAY\n$COMMITS" >> $CHANGELOG_FILE + - 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.DATE }}] - Update" >> CHANGELOG.md + echo "${{ env.Commits }}" >> CHANGELOG.md + echo "" >> CHANGELOG.md + fi - - name: Commit and push changes - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Commit and Push Changes run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add $CHANGELOG_FILE - git commit -m "Update CHANGELOG.md with latest commit" || echo "No changes to commit" - git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} HEAD:${{ github.ref }} + git add CHANGELOG.md + git commit -m "Update CHANGELOG.md with latest commits" || echo "No changes to commit" + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/Passer1072/RookieAI_yolov8 HEAD:dev