From d365f8f27f8b965c70643ef7c3fb3c6bb9def16c Mon Sep 17 00:00:00 2001 From: liyp Date: Thu, 10 Apr 2025 14:48:30 +0800 Subject: [PATCH] =?UTF-8?q?deepseek=E9=87=8D=E5=86=99toml=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/AutoGenerateREADME.yaml | 59 +++++++++--------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/.gitea/workflows/AutoGenerateREADME.yaml b/.gitea/workflows/AutoGenerateREADME.yaml index 8a285c2..9993336 100644 --- a/.gitea/workflows/AutoGenerateREADME.yaml +++ b/.gitea/workflows/AutoGenerateREADME.yaml @@ -1,52 +1,37 @@ -name: Generate README based on repo name and commits +name: Auto Update README with Repo Name on: push: branches: - - main # 可根据实际情况修改为你的默认分支 + - main jobs: - generate-readme: + update-readme: runs-on: ubuntu-latest - steps: - - name: ActionDemo - run: | - git clone https://git.linuxacme.com/iorebuild/ActionDemo.git . + - name: Checkout code (Gitea version) + uses: https://gitea.com/actions/checkout.git + with: + fetch-depth: 0 - - name: Get repository name - id: repo-name - run: | - REPO_NAME=$(echo ${{ github.repository }} | cut -d '/' -f 2) - echo "::set-output name=name::$REPO_NAME" + - name: Extract repository name + run: echo "REPO_NAME=ActionDemo" >> $GITHUB_ENV - - name: Get recent commits - id: recent-commits + - name: Create or update README run: | - COMMITS=$(git log --pretty=format:"- %s (%an, %ad)" --date=short -n 5) - echo "::set-output name=commits::$COMMITS" - - - name: Generate README - run: | - cat << EOF > README.md - # ${{ steps.repo-name.outputs.name }} - - ## Recent Commits - ${{ steps.recent-commits.outputs.commits }} - EOF + if [ ! -f README.md ]; then + echo "# $REPO_NAME" > README.md + echo -e "\nThis repository is automatically maintained by Gitea Actions." >> README.md + else + if ! grep -q "^# $REPO_NAME" README.md; then + sed -i "1i# $REPO_NAME" README.md + fi + fi - name: Commit and push changes - env: - GIT_REPO_TOKEN: ${{ secrets.AUTOGENERATEREADME }} # 假设你已经将令牌存储为 GITHUB_TOKEN 机密 run: | - git config --local user.email "liyepan@linuxacme.com" - git config --local user.name "iorebuild" - git config --global credential.helper store - echo "https://${GIT_REPO_TOKEN}@git.linuxacme.com" > ~/.git-credentials + git config --global user.name "iorebuild" + git config --global user.email "liyepan@linuxacme.com" git add README.md - if git diff --staged --quiet; then - echo "No changes to README.md. Skipping commit." - else - git commit -m "Update README with recent commits" - git push https://${GIT_REPO_TOKEN}@git.linuxacme.com/iorebuild/ActionDemo.git - fi \ No newline at end of file + git diff --quiet && git diff --staged --quiet || git commit -m "Auto-update: Add repository name to README" + git push \ No newline at end of file