-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH Actions: automate yearly update of test file
Every year two of the `fixed` files for the tests for the `Squiz.Commenting.FileComment` sniff need to be updated to ensure they have the correct expected year. So far this was always done manually and all PRs created in the new year would show a failing build until that PR was merged and the other PRs rebased. This commit introduces a new workflow to automate those updates and automatically creates a PR at 5 minutes past midnight on the new year. All that needs to happy then is to merge the PR promptly and all will be good. Obviously, the true test of whether this workflow works will be on January 1st, but I've done some testing by manually reverting the change from January of this year and it all seems to look good.
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# There is one particular test for the Squiz/FileComment sniff which every year requires | ||
# an update to the year used in a `@copyright` tag to allow the tests to keep passing. | ||
# This workflow will automatically create a PR to the repo to handle this update. | ||
|
||
name: "Update Squiz/FileComment Test" | ||
|
||
on: | ||
# Run every year on Jan 1st at 00:05. | ||
schedule: | ||
- cron: '5 0 1 1 *' | ||
# And whenever this workflow is updated. | ||
push: | ||
paths: | ||
- '.github/workflows/happy-new-year.yml' | ||
pull_request: | ||
paths: | ||
- '.github/workflows/happy-new-year.yml' | ||
# Also allow manually triggering the workflow. | ||
workflow_dispatch: | ||
|
||
# Cancels all previous workflow runs for the same branch that have not yet completed. | ||
concurrency: | ||
# The concurrency group contains the workflow name and the branch name. | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
update-year-in-test: | ||
runs-on: ubuntu-latest | ||
# Don't run the cron job on forks. | ||
if: ${{ github.event_name != 'schedule' || github.repository == 'PHPCSStandards/PHP_CodeSniffer' }} | ||
|
||
name: "Happy New Year" | ||
steps: | ||
- name: Set branches to use | ||
id: branches | ||
run: | | ||
echo "BASE=master" >> $GITHUB_OUTPUT | ||
echo "PR_BRANCH=feature/squiz-filecomment-update-copyright-year" >> $GITHUB_OUTPUT | ||
# Using "Tomorrow" to prevent accidentally getting last year if the server is not using UTC. | ||
- name: Grab the new year | ||
id: year | ||
run: | | ||
echo "NEW_YEAR=$(date --date="tomorrow" -u "+%Y")" >> $GITHUB_OUTPUT | ||
- name: Show year | ||
run: "echo current year: ${{ steps.year.outputs.NEW_YEAR }}" | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ steps.branches.outputs.BASE }} | ||
|
||
- name: Update the year in the copyright tag in the fixed file | ||
uses: jacobtomlinson/gha-find-replace@v3 | ||
with: | ||
find: "\* @copyright 20[0-9]{2} Squiz Pty Ltd \(ABN 77 084 670 600\)" | ||
replace: "* @copyright ${{ steps.year.outputs.NEW_YEAR }} Squiz Pty Ltd (ABN 77 084 670 600)" | ||
include: "src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.*.fixed" | ||
regex: true | ||
|
||
- name: "Debug info: Show git status" | ||
run: git status -vv --untracked=all | ||
|
||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
base: ${{ steps.branches.outputs.BASE }} | ||
branch: ${{ steps.branches.outputs.PR_BRANCH }} | ||
delete-branch: true | ||
commit-message: "Squiz/FileComment: update year in test case fixed file" | ||
title: "Squiz/FileComment: update year in test case fixed file" | ||
# yamllint disable rule:line-length | ||
body: | | ||
The regular annual update to make sure the build still passes ;-) | ||
Happy new year! | ||
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). | ||
# yamllint enable rule:line-length | ||
labels: | | ||
Type: chores/QA | ||
reviewers: | | ||
jrfnl |