可以根据发布信息记录到readme

This commit is contained in:
liyp 2025-04-10 15:45:41 +08:00
parent 0abac72735
commit 7fed578bd3

View File

@ -1,14 +1,14 @@
name: Create README with Commit History name: AutoGenerateREADME.md
on: on:
push: push:
branches: branches:
- main # 可根据实际情况修改为你的默认分支,如 master - main
jobs: jobs:
create-readme: create-readme:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'Create README with commit history')" if: "!contains(github.event.head_commit.message, 'AutoGenerateREADME.md')"
steps: steps:
- name: Checkout code from Gitea - name: Checkout code from Gitea
@ -17,11 +17,10 @@ jobs:
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }} GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }} CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: | run: |
# 去除多余的 https://
CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}" CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
git clone "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}" . git clone "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}" .
- name: Delete existing README if exists - name: Touch New README.md
run: | run: |
if [ -f README.md ]; then if [ -f README.md ]; then
rm README.md rm README.md
@ -29,14 +28,37 @@ jobs:
- name: Get commit history and write to README - name: Get commit history and write to README
run: | run: |
# 获取仓库名称 echo "# ActionDemo测试文档标题" > README.md
REPO_NAME=$(basename "$GITHUB_REPOSITORY" .git)
# 写入仓库名称到 README # 获取所有提交记录,包含提交哈希、作者、日期和提交信息
echo "# $REPO_NAME" > README.md commits=$(git log --pretty=format:"%ct %h %an %ad %s" --date=short)
# 获取所有提交记录并追加到 README
git log --pretty=format:"- %h %an %ad %s" --date=short >> README.md # 获取所有版本标签及其关联的提交哈希和日期
# 显示 README.md 的内容(可选,用于调试) tags=$(git for-each-ref --sort=creatordate --format='%(creatordate:unix) %(objectname) %(refname:strip=2)' refs/tags)
cat README.md
# 合并提交记录和版本标签信息,并按时间排序
all_entries="$commits
$tags"
sorted_entries=$(echo "$all_entries" | sort -n)
# 遍历排序后的记录并写入 README
for entry in $sorted_entries; do
timestamp=$(echo $entry | cut -d ' ' -f 1)
hash_or_tag=$(echo $entry | cut -d ' ' -f 2)
rest=$(echo $entry | cut -d ' ' -f 3-)
# 检查是否为版本标签
if [[ $hash_or_tag == refs/tags/* ]]; then
tag_name=${hash_or_tag#refs/tags/}
echo "## Version $tag_name" >> README.md
else
commit_hash=$hash_or_tag
author=$(echo $rest | cut -d ' ' -f 1)
date=$(echo $rest | cut -d ' ' -f 2)
message=$(echo $rest | cut -d ' ' -f 3-)
echo "- $commit_hash $author $date $message" >> README.md
fi
done
- name: Commit and push changes - name: Commit and push changes
env: env:
@ -44,7 +66,6 @@ jobs:
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }} GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }} CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: | run: |
# 去除多余的 https://
CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}" CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
git config --local user.email "liyepan@linuxacme.com" git config --local user.email "liyepan@linuxacme.com"
git config --local user.name "iorebuild" git config --local user.name "iorebuild"