Skip to content

Commit

Permalink
Enhance README update workflow with environment variables and error h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
nishimotz committed Nov 13, 2024
1 parent 2eb4593 commit 91ed0f9
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions .github/workflows/update-readme.yml
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:
Expand All @@ -9,6 +17,10 @@ on:
branches:
- master

permissions:
contents: write
pull-requests: write

jobs:
update-readme:
# ジョブを実行する条件:
Expand All @@ -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 }}

0 comments on commit 91ed0f9

Please sign in to comment.