From 27b6f3f4732c5063e38e839251efd7da92f13dc6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 28 Aug 2022 00:40:44 +0200 Subject: [PATCH] GH Actions: add new workflow to automate repeated task The `GetVersionTest` test class contains a constant which should be set to the PHPCS version number of the latest release. Until now, this version number would be updated manually on an ad-hoc basis. This workflow automates these updates and will automatically create a PR to update the version number whenever PHPCS has had a new release. The workflow will run: * Every night via a cronjob. Note: this does mean the workflow will be automatically disabled if there would be no activity in the repo for more than two months. * On pull requests which update the workflow. * And can be manually triggered if needed. Includes removing the update reminder from the release checklist. See 259, 286, 324. --- .github/release-checklist.md | 1 - .github/workflows/update-phpcs-versionnr.yml | 85 ++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update-phpcs-versionnr.yml diff --git a/.github/release-checklist.md b/.github/release-checklist.md index 49cc8b15..0336a288 100644 --- a/.github/release-checklist.md +++ b/.github/release-checklist.md @@ -19,7 +19,6 @@ PR for tracking changes for the x.x.x release. Target release date: **DOW MONTH ### General -- [ ] Update the `DEVMASTER` version nr constant in the `Tests/BackCompat/Helper/GetVersionTest.php` file. - PR #xxx - [ ] Verify, and if necessary, update the version constraints for dependencies in the `composer.json` - PR #xxx - [ ] Verify that any new functions have type declarations whenever possible. - [ ] Add changelog for the release - PR #xxx diff --git a/.github/workflows/update-phpcs-versionnr.yml b/.github/workflows/update-phpcs-versionnr.yml new file mode 100644 index 00000000..8e2234f7 --- /dev/null +++ b/.github/workflows/update-phpcs-versionnr.yml @@ -0,0 +1,85 @@ +name: Update PHPCS version + +on: + # Run every day at 3:40. + schedule: + - cron: '40 3 * * *' + # And whenever this workflow is updated. + pull_request: + paths: + - '.github/workflows/update-phpcs-versionnr.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: + phpcs-version-check: + name: "Check latest PHPCS version" + # Don't run the cron job on forks. + if: ${{ github.event_name != 'schedule' || github.repository == 'PHPCSStandards/PHPCSUtils' }} + + runs-on: ubuntu-latest + steps: + - name: Retrieve latest PHPCS release info + uses: octokit/request-action@v2.x + id: get_latest_release + with: + route: GET /repos/squizlabs/PHP_CodeSniffer/releases/latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: "Debug info: Show API request failure status" + if: ${{ failure() }} + run: "echo No release found. Request failed with status ${{ steps.get_latest_release.outputs.status }}" + + - name: Grab latest tag name from API response + id: version + run: | + echo "::set-output name=TAG::${{ fromJson(steps.get_latest_release.outputs.data).tag_name }}" + + - name: Show tag name found in API response + run: "echo latest release: ${{ steps.version.outputs.TAG }}" + + - name: Set branches to use + id: branches + run: | + echo "::set-output name=BASE::develop" + echo "::set-output name=PR_BRANCH::feature/getversiontest-update-phpcs-version" + + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ steps.branches.outputs.BASE }} + + - name: Update the version constant in the test file + uses: jacobtomlinson/gha-find-replace@v2 + with: + find: "const DEVMASTER = '[^']+';" + replace: "const DEVMASTER = '${{ steps.version.outputs.TAG }}';" + include: "Tests/BackCompat/Helper/GetVersionTest.php" + regex: true + + - name: "Debug info: Show git status" + run: git status -vv --untracked=all + + - name: Create pull request + uses: peter-evans/create-pull-request@v4 + with: + base: ${{ steps.branches.outputs.BASE }} + branch: ${{ steps.branches.outputs.PR_BRANCH }} + delete-branch: true + commit-message: "GetVersionTest: update for release of PHPCS ${{ steps.version.outputs.TAG }}" + title: "GetVersionTest: update for release of PHPCS ${{ steps.version.outputs.TAG }}" + # yamllint disable rule:line-length + body: | + This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request) using the [`update-phpcs-versionnr.yml` workflow](https://github.com/PHPCSStandards/PHPCSUtils/blob/develop/.github/workflows/update-phpcs-versionnr.yml). + # yamllint enable rule:line-length + labels: | + Type: chores/QA + reviewers: | + jrfnl