-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance README update workflow with environment variables and error h…
…andling
- Loading branch information
Showing
1 changed file
with
37 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
name: Update README and Create PR | ||
|
||
# 環境変数の定義 | ||
env: | ||
README_PATH: WAIC-TEST/HTML/README.md | ||
PYTHON_VERSION: '3.11' | ||
SCRIPT_PATH: .github/workflows/makeindex.py | ||
BOT_NAME: "GitHub Actions Bot" | ||
BRANCH_PREFIX: update-readme | ||
|
||
on: | ||
push: | ||
branches: | ||
|
@@ -9,6 +17,10 @@ on: | |
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
update-readme: | ||
# ジョブを実行する条件: | ||
|
@@ -27,38 +39,44 @@ jobs: | |
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
python-version: ${{ env.PYTHON_VERSION }} | ||
|
||
# makeindex.py 実行とエラーハンドリング | ||
- name: Run makeindex.py | ||
run: python3 .github/workflows/makeindex.py | ||
run: | | ||
if ! python3 ${{ env.SCRIPT_PATH }}; then | ||
echo "Error: makeindex.py failed" | ||
exit 1 | ||
fi | ||
# README.md の変更のみを確認 | ||
- name: Check for changes | ||
id: check_changes | ||
run: | | ||
if git diff --quiet; then | ||
echo "No changes detected" | ||
if git diff --quiet ${{ env.README_PATH }}; then | ||
echo "No changes detected in README.md" | ||
echo "changes_detected=false" >> $GITHUB_OUTPUT | ||
else | ||
echo "Changes detected" | ||
echo "Changes detected in README.md" | ||
echo "changes_detected=true" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Commit README.md updates | ||
if: steps.check_changes.outputs.changes_detected == 'true' | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Action" | ||
git checkout -b update-readme-${{ github.run_number }} | ||
git add WAIC-TEST/HTML/README.md | ||
git commit -m "Update README.md automatically" | ||
git push origin update-readme-${{ github.run_number }} | ||
# PRの作成 | ||
- name: Create Pull Request | ||
if: steps.check_changes.outputs.changes_detected == 'true' | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
branch: update-readme-${{ github.run_number }} | ||
commit-message: "Update README.md automatically" | ||
title: "Automatically update README.md" | ||
body: "This is an auto-generated PR to update README.md file" | ||
commit-message: "Update README.md automatically [skip ci]" | ||
title: "🤖 README.md の自動更新" | ||
body: | | ||
### 自動更新の内容 | ||
- ${{ env.README_PATH }} ファイルの内容を最新の状態に更新 | ||
> このPRは GitHub Actions により自動生成されています。 | ||
> 生成日時: ${{ github.event.head_commit.timestamp }} | ||
branch: ${{ env.BRANCH_PREFIX }}-${{ github.run_number }} | ||
base: master | ||
add-paths: | | ||
${{ env.README_PATH }} | ||
delete-branch: true | ||
token: ${{ secrets.GITHUB_TOKEN }} |