76 lines
2.6 KiB
YAML
76 lines
2.6 KiB
YAML
name: 自动生成README.md文件
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
create-readme:
|
|
runs-on: ubuntu-latest
|
|
|
|
if: "!contains(github.event.head_commit.message, 'AutoGenerateREADME.md')"
|
|
|
|
steps:
|
|
- name: 删除本地仓库副本
|
|
env:
|
|
REPO_NAME: ${{ github.event.repository.name }}
|
|
run: |
|
|
if [ -d "$REPO_NAME" ]; then
|
|
rm -rf "$REPO_NAME"
|
|
fi
|
|
|
|
- name: 检出仓库
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.AUTOGENERATE }}
|
|
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
|
|
CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
|
|
run: |
|
|
CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
|
|
git clone "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}" .
|
|
|
|
- name: 创建README.md
|
|
run: |
|
|
if [ -f README.md ]; then
|
|
rm README.md
|
|
fi
|
|
|
|
- name: 生成提交历史记录
|
|
id: commit-history
|
|
run: |
|
|
COMMIT_HISTORY=$(git log --pretty=format:"- %cd %h %an: %s" --date=short)
|
|
echo "::set-output name=commit_history::$COMMIT_HISTORY"
|
|
|
|
- name: 生成Release历史记录
|
|
id: release-history
|
|
run: |
|
|
RELEASE_HISTORY=$(gh release list --limit 100 --json tagName,publishedAt,body --template '{{range .}}- {{.publishedAt}} {{.tagName}}: {{.body}}{{"\n"}}{{end}}')
|
|
echo "::set-output name=release_history::$RELEASE_HISTORY"
|
|
|
|
- name: 将提交和Release记录添加到README.md
|
|
run: |
|
|
{
|
|
echo
|
|
echo "# 提交历史记录"
|
|
echo "${{ steps.commit-history.outputs.commit_history }}"
|
|
echo
|
|
echo "# Release历史记录"
|
|
echo "${{ steps.release-history.outputs.release_history }}"
|
|
} >> README.md
|
|
|
|
- name: 重新提交仓库
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.AUTOGENERATE }}
|
|
GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
|
|
CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
|
|
run: |
|
|
CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
|
|
git config --local user.email "liyepan@linuxacme.com"
|
|
git config --local user.name "iorebuild"
|
|
git add README.md
|
|
if git diff --staged --quiet; then
|
|
echo "No changes to commit."
|
|
else
|
|
git commit -m "AutoGenerateREADME.md"
|
|
git push "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}"
|
|
fi |