Skip to content

GH Actions: automate yearly update of test file #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/happy-new-year.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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 "PREVIOUS_YEAR=$(date --date="last month" -u "+%Y")" >> $GITHUB_OUTPUT
echo "NEW_YEAR=$(date --date="tomorrow" -u "+%Y")" >> $GITHUB_OUTPUT

- name: "Debug info: Show years"
run: "echo current year: ${{ steps.year.outputs.NEW_YEAR }} - previous year: ${{ steps.year.outputs.PREVIOUS_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
id: findreplace
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "* @copyright ${{ steps.year.outputs.PREVIOUS_YEAR }} 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: false

- name: "Debug info: Show number of modified files"
run: "echo modified files: ${{ steps.findreplace.outputs.modifiedFiles }}"

- name: "Debug info: Show git status"
run: git status -vv --untracked=all

- name: Fail the cron job if no files where modified
if: ${{ github.event_name == 'schedule' && steps.findreplace.outputs.modifiedFiles == 0 }}
run: exit 1

- 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