Skip to content

Commit f9be7cf

Browse files
authored
Merge pull request #102 from PHPCSStandards/feature/ghactions-new-happy-new-year-workflow
GH Actions: automate yearly update of test file
2 parents 265adff + a586b63 commit f9be7cf

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

.github/workflows/happy-new-year.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# There is one particular test for the Squiz/FileComment sniff which every year requires
2+
# an update to the year used in a `@copyright` tag to allow the tests to keep passing.
3+
# This workflow will automatically create a PR to the repo to handle this update.
4+
5+
name: "Update Squiz/FileComment Test"
6+
7+
on:
8+
# Run every year on Jan 1st at 00:05.
9+
schedule:
10+
- cron: '5 0 1 1 *'
11+
# And whenever this workflow is updated.
12+
push:
13+
paths:
14+
- '.github/workflows/happy-new-year.yml'
15+
pull_request:
16+
paths:
17+
- '.github/workflows/happy-new-year.yml'
18+
# Also allow manually triggering the workflow.
19+
workflow_dispatch:
20+
21+
# Cancels all previous workflow runs for the same branch that have not yet completed.
22+
concurrency:
23+
# The concurrency group contains the workflow name and the branch name.
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
update-year-in-test:
29+
runs-on: ubuntu-latest
30+
# Don't run the cron job on forks.
31+
if: ${{ github.event_name != 'schedule' || github.repository == 'PHPCSStandards/PHP_CodeSniffer' }}
32+
33+
name: "Happy New Year"
34+
steps:
35+
- name: Set branches to use
36+
id: branches
37+
run: |
38+
echo "BASE=master" >> $GITHUB_OUTPUT
39+
echo "PR_BRANCH=feature/squiz-filecomment-update-copyright-year" >> $GITHUB_OUTPUT
40+
41+
# Using "Tomorrow" to prevent accidentally getting last year if the server is not using UTC.
42+
- name: Grab the new year
43+
id: year
44+
run: |
45+
echo "PREVIOUS_YEAR=$(date --date="last month" -u "+%Y")" >> $GITHUB_OUTPUT
46+
echo "NEW_YEAR=$(date --date="tomorrow" -u "+%Y")" >> $GITHUB_OUTPUT
47+
48+
- name: "Debug info: Show years"
49+
run: "echo current year: ${{ steps.year.outputs.NEW_YEAR }} - previous year: ${{ steps.year.outputs.PREVIOUS_YEAR }}"
50+
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
with:
54+
ref: ${{ steps.branches.outputs.BASE }}
55+
56+
- name: Update the year in the copyright tag in the fixed file
57+
id: findreplace
58+
uses: jacobtomlinson/gha-find-replace@v3
59+
with:
60+
find: "* @copyright ${{ steps.year.outputs.PREVIOUS_YEAR }} Squiz Pty Ltd (ABN 77 084 670 600)"
61+
replace: "* @copyright ${{ steps.year.outputs.NEW_YEAR }} Squiz Pty Ltd (ABN 77 084 670 600)"
62+
include: "src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.*.fixed"
63+
regex: false
64+
65+
- name: "Debug info: Show number of modified files"
66+
run: "echo modified files: ${{ steps.findreplace.outputs.modifiedFiles }}"
67+
68+
- name: "Debug info: Show git status"
69+
run: git status -vv --untracked=all
70+
71+
- name: Fail the cron job if no files where modified
72+
if: ${{ github.event_name == 'schedule' && steps.findreplace.outputs.modifiedFiles == 0 }}
73+
run: exit 1
74+
75+
- name: Create pull request
76+
uses: peter-evans/create-pull-request@v5
77+
with:
78+
base: ${{ steps.branches.outputs.BASE }}
79+
branch: ${{ steps.branches.outputs.PR_BRANCH }}
80+
delete-branch: true
81+
commit-message: "Squiz/FileComment: update year in test case fixed file"
82+
title: "Squiz/FileComment: update year in test case fixed file"
83+
# yamllint disable rule:line-length
84+
body: |
85+
The regular annual update to make sure the build still passes ;-)
86+
87+
Happy new year!
88+
89+
This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request) using the [`happy-new-year.yml` workflow](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/.github/workflows/happy-new-year.yml).
90+
# yamllint enable rule:line-length
91+
labels: |
92+
Type: chores/QA
93+
reviewers: |
94+
jrfnl

0 commit comments

Comments
 (0)