Skip to content

🚀 GitHub Actionsのライセンス年更新ワークフローで、リファレンス構文に関するアドバイスを無効にする設定を追加 #34

🚀 GitHub Actionsのライセンス年更新ワークフローで、リファレンス構文に関するアドバイスを無効にする設定を追加

🚀 GitHub Actionsのライセンス年更新ワークフローで、リファレンス構文に関するアドバイスを無効にする設定を追加 #34

---
name: Update License Year
on:
schedule:
- cron: "0 0 1 1 *" # 毎年1月1日に実行
workflow_dispatch:
push:
branches:
- "feature/refactor**"
jobs:
commit-changes:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write # required to commit changes
pull-requests: write # uses peter-evans/create-pull-request
steps:
- uses: actions/checkout@v4
- name: Generate GitHub App Token
id: app_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GHA_APP_ID }}
private-key: ${{ secrets.GHA_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Make changes (e.g., update LICENSE year)
run: |
current_year=$(date +"%Y")
echo "current_year=$current_year" >> $GITHUB_ENV
sed -i "s/[0-9]\{4\}/$current_year/g" LICENSE
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config advice.refSyntax false
git config --global --add --bool push.autoSetupRemote true
- name: Create new branch
run: |
branch_name="update-license-year-$current_year"
git checkout -b "$branch_name"
- name: Commit changes
id: commit_changes
run: |
if [ -n "$(git status --porcelain)" ]; then
git add LICENSE
git commit -m "Update License year to $current_year"
echo "changes_made=true" >> "$GITHUB_ENV"
else
echo "No changes to commit"
echo "changes_made=false" >> "$GITHUB_ENV"
fi
- name: Push changes
if: env.changes_made == 'true'
run: git push --set-upstream --force origin ${{ env.branch_name }}
- name: Create Pull Request
if: env.changes_made == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update License year to $current_year"
title: "Update License year to $current_year"
body: "This PR updates the LICENSE year to $current_year."
branch: ${{ env.branch_name }}
base: main
labels: "auto-merge"
reviewers: "octocat"
assignees: "octocat"
draft: false
branch-suffix: timestamp