Skip to content

Commit 91ed0f9

Browse files
committed
Enhance README update workflow with environment variables and error handling
1 parent 2eb4593 commit 91ed0f9

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed
Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
name: Update README and Create PR
22

3+
# 環境変数の定義
4+
env:
5+
README_PATH: WAIC-TEST/HTML/README.md
6+
PYTHON_VERSION: '3.11'
7+
SCRIPT_PATH: .github/workflows/makeindex.py
8+
BOT_NAME: "GitHub Actions Bot"
9+
BRANCH_PREFIX: update-readme
10+
311
on:
412
push:
513
branches:
@@ -9,6 +17,10 @@ on:
917
branches:
1018
- master
1119

20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
1224
jobs:
1325
update-readme:
1426
# ジョブを実行する条件:
@@ -27,38 +39,44 @@ jobs:
2739
- name: Set up Python
2840
uses: actions/setup-python@v5
2941
with:
30-
python-version: '3.x'
42+
python-version: ${{ env.PYTHON_VERSION }}
3143

44+
# makeindex.py 実行とエラーハンドリング
3245
- name: Run makeindex.py
33-
run: python3 .github/workflows/makeindex.py
46+
run: |
47+
if ! python3 ${{ env.SCRIPT_PATH }}; then
48+
echo "Error: makeindex.py failed"
49+
exit 1
50+
fi
3451
52+
# README.md の変更のみを確認
3553
- name: Check for changes
3654
id: check_changes
3755
run: |
38-
if git diff --quiet; then
39-
echo "No changes detected"
56+
if git diff --quiet ${{ env.README_PATH }}; then
57+
echo "No changes detected in README.md"
4058
echo "changes_detected=false" >> $GITHUB_OUTPUT
4159
else
42-
echo "Changes detected"
60+
echo "Changes detected in README.md"
4361
echo "changes_detected=true" >> $GITHUB_OUTPUT
4462
fi
4563
46-
- name: Commit README.md updates
47-
if: steps.check_changes.outputs.changes_detected == 'true'
48-
run: |
49-
git config --global user.email "action@github.com"
50-
git config --global user.name "GitHub Action"
51-
git checkout -b update-readme-${{ github.run_number }}
52-
git add WAIC-TEST/HTML/README.md
53-
git commit -m "Update README.md automatically"
54-
git push origin update-readme-${{ github.run_number }}
55-
64+
# PRの作成
5665
- name: Create Pull Request
5766
if: steps.check_changes.outputs.changes_detected == 'true'
5867
uses: peter-evans/create-pull-request@v7
5968
with:
60-
branch: update-readme-${{ github.run_number }}
61-
commit-message: "Update README.md automatically"
62-
title: "Automatically update README.md"
63-
body: "This is an auto-generated PR to update README.md file"
69+
commit-message: "Update README.md automatically [skip ci]"
70+
title: "🤖 README.md の自動更新"
71+
body: |
72+
### 自動更新の内容
73+
- ${{ env.README_PATH }} ファイルの内容を最新の状態に更新
74+
75+
> このPRは GitHub Actions により自動生成されています。
76+
> 生成日時: ${{ github.event.head_commit.timestamp }}
77+
branch: ${{ env.BRANCH_PREFIX }}-${{ github.run_number }}
6478
base: master
79+
add-paths: |
80+
${{ env.README_PATH }}
81+
delete-branch: true
82+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)