Skip to content

Commit 15dc4ee

Browse files
Merge pull request SimpleMachines#8401 from live627/3.0/update-year
[3.0] GitHub Action to Update Year in Files
2 parents 117ace4 + 618af5f commit 15dc4ee

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/update-year.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Update Year
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-year:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Set current year environment variable
15+
run: echo "CURRENT_YEAR=$(date +'%Y')" >> $GITHUB_ENV
16+
17+
- name: Check if version tag matches any pre-release
18+
run: |
19+
str=$(grep -oP "define\('SMF_VERSION', '[^']+" index.php)
20+
re='[0-9]+\.[0-9]+ ?[A-Za-z]+';
21+
tag=`echo $str | grep -oP "[0-9]+\.[0-9]+"`
22+
if [[ $str =~ $re ]]; then
23+
echo "PRE_RELEASE=true" >> $GITHUB_ENV
24+
else
25+
echo "PRE_RELEASE=false" >> $GITHUB_ENV
26+
fi
27+
echo "TAG=$tag" >> $GITHUB_ENV
28+
29+
- name: Update year in Sources/
30+
if: env.PRE_RELEASE == 'true'
31+
run: |
32+
shopt -s globstar
33+
for file in Sources/**/*.php Themes/default/*.php; do
34+
sed -i "s/@copyright [0-9]\{4\}/@copyright ${{ env.CURRENT_YEAR }}/" $file
35+
done
36+
37+
- name: Update year in PHP files
38+
run: |
39+
for file in SSI.php proxy.php cron.php index.php other/*.php; do
40+
sed -i "s/@copyright [0-9]\{4\}/@copyright ${{ env.CURRENT_YEAR }}/" $file
41+
sed -i "s/define('SMF_SOFTWARE_YEAR', '[0-9]\{4\}');/define('SMF_SOFTWARE_YEAR', '${{ env.CURRENT_YEAR }}');/" $file
42+
done
43+
44+
- name: Create Pull Request
45+
uses: peter-evans/create-pull-request@v7
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
commit-message: Update year to ${{ env.CURRENT_YEAR }}
49+
branch: ${{ env.TAG }}/update-year-${{ env.CURRENT_YEAR }}
50+
title: "[${{ env.TAG }}] Update year to ${{ env.CURRENT_YEAR }}"
51+
body: This commit updates `SMF_SOFTWARE_YEAR` to ${{ env.CURRENT_YEAR }}. This action was performed by a bot.

0 commit comments

Comments
 (0)