Update License Year #5
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
name: Update License Year | |
on: | |
schedule: | |
- cron: '0 0 1 1 *' # 每年1月1日运行 | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
update-license-year: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Update year in LICENSE | |
run: | | |
CURRENT_YEAR=$(date +%Y) | |
echo "CURRENT_YEAR=$CURRENT_YEAR" >> $GITHUB_ENV | |
# 调试输出 | |
echo "Current content of LICENSE file:" | |
cat LICENSE | |
echo "Current year: $CURRENT_YEAR" | |
# 更新年份 - 支持多种格式 | |
if [ -f LICENSE ]; then | |
# 更新 "Copyright (c) YYYY" 格式 | |
sed -i -E "s/Copyright \(c\) [0-9]{4}/Copyright (c) ${CURRENT_YEAR}/" LICENSE | |
# 更新 "Copyright (c) YYYY-YYYY" 格式 | |
sed -i -E "s/Copyright \(c\) [0-9]{4}-[0-9]{4}/Copyright (c) ${CURRENT_YEAR}/" LICENSE | |
# 更新 "Copyright YYYY" 格式 | |
sed -i -E "s/Copyright [0-9]{4}/Copyright ${CURRENT_YEAR}/" LICENSE | |
echo "Updated content of LICENSE file:" | |
cat LICENSE | |
else | |
echo "LICENSE file not found!" | |
fi | |
- name: Check for changes | |
id: changes | |
run: | | |
if git diff --quiet; then | |
echo "No changes detected" | |
echo "changed=false" >> $GITHUB_OUTPUT | |
else | |
echo "Changes detected" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
git diff | |
fi | |
- name: Create Pull Request | |
if: steps.changes.outputs.changed == 'true' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "chore: update license year to ${{ env.CURRENT_YEAR }}" | |
title: "chore: update license year to ${{ env.CURRENT_YEAR }}" | |
body: | | |
Automated changes: | |
- Updated copyright year in LICENSE file to current year (${{ env.CURRENT_YEAR }}) | |
Please review the changes and merge if appropriate. | |
branch: update-license-year | |
base: main | |
delete-branch: true |