Skip to content

Commit 592f0ab

Browse files
authored
chore: add Bump License Year workflows (#21)
1 parent 06f2fe4 commit 592f0ab

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Bump License Year
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 1 1 *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
bump-year:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set the current year
21+
run: |
22+
echo "CURRENT_YEAR=$(date +'%Y')" >> $GITHUB_ENV
23+
echo "BRANCH_NAME=bump-license-year-${CURRENT_YEAR}" >> $GITHUB_ENV
24+
25+
- name: Configure Git
26+
run: |
27+
git config --global user.name "github-actions[bot]"
28+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
30+
- name: Update license year
31+
run: |
32+
OLD_YEAR=$(grep -oP '\d{4}' LICENSE | tail -n 1)
33+
if [ "$OLD_YEAR" != "${CURRENT_YEAR}" ]; then
34+
sed -i "s/$OLD_YEAR/${CURRENT_YEAR}/g" LICENSE
35+
fi
36+
37+
- name: Check for changes
38+
id: changes_check
39+
run: |
40+
if git diff --quiet; then
41+
echo "No changes detected."
42+
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
43+
else
44+
echo "Changes detected."
45+
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
46+
47+
- name: Create new branch
48+
if: env.CHANGES_DETECTED == 'true'
49+
run: |
50+
git checkout -b ${BRANCH_NAME}
51+
52+
- name: Commit changes
53+
if: env.CHANGES_DETECTED == 'true'
54+
run: |
55+
git add LICENSE
56+
git commit -m "chore: bump license year to ${CURRENT_YEAR}"
57+
58+
- name: Push changes
59+
if: env.CHANGES_DETECTED == 'true'
60+
run: git push --set-upstream origin ${BRANCH_NAME}
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Create Pull Request
65+
if: env.CHANGES_DETECTED == 'true'
66+
uses: actions/create-pull-request@v7
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
branch: ${BRANCH_NAME}
70+
title: 'chore: bump license year to ${CURRENT_YEAR}'
71+
base: main

0 commit comments

Comments
 (0)