From dfa2bc05629714b6575e9507ea917d4cec6b1799 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Fri, 4 Jun 2021 14:50:26 +0100 Subject: [PATCH 1/2] Fix diff changes to dist GitHub Action Description of the issue ------------------------ When raising a release PR, we have a GitHub Action that is meant to add a diff of the changes to dist (what a mouthful!) as a comment on the PR. This failed when we were trying to release v3.12.0 with `Error: Argument list too long`. See https://github.com/alphagov/govuk-frontend/pull/2224/checks?check_run_id=2575562845 Fix --- Following a suggestion from another person who had the same issue [[1]], this commit saves the diff text to a file in the GITHUB_WORKSPACE folder instead. The GitHub Actions states actions can modify this directory and have subsequent actions access those changes [[2]]. This also has the advantage of removing the need to percent-encode the diff text, so the script to generate the diff can now be simpler. [1]: https://github.uint.cloudmunity/t/maximum-length-for-the-comment-body-in-issues-and-pr/148867/5 [2]: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#file-systems --- .github/workflows/diff-change-to-dist.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/diff-change-to-dist.yaml b/.github/workflows/diff-change-to-dist.yaml index c12735be9f..9413617617 100644 --- a/.github/workflows/diff-change-to-dist.yaml +++ b/.github/workflows/diff-change-to-dist.yaml @@ -23,22 +23,21 @@ jobs: - name: Generate diff id: diff run: | - diff=$(git diff -M1 origin/$GITHUB_BASE_REF -- dist) - # Escape new lines - diff="${diff//'%'/'%25'}" - diff="${diff//$'\n'/'%0A'}" - diff="${diff//$'\r'/'%0D'}" - echo "::set-output name=diff::$diff" + git diff -M1 origin/$GITHUB_BASE_REF -- dist \ + > $GITHUB_WORKSPACE/dist.diff - name: Add comment to PR uses: actions/github-script@v3 - env: - DIFF: ${{ steps.diff.outputs.diff }} with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - const commentText = '## Changes to dist\n' + + const fs = require('fs').promises + const diff = await fs.readFile( + process.env.GITHUB_WORKSPACE + '/dist.diff', 'utf8' + ) + + const commentText = '## Changes to dist\n' + '```diff\n' + - process.env.DIFF + + diff + '\n```' github.issues.createComment({ From 8f26b79cabe4c2722774965f5abb31694fc4d9b5 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Fri, 4 Jun 2021 15:21:55 +0100 Subject: [PATCH 2/2] Increase `git diff` similarity index threshold Changes the similarity index threshold for detecting renames to 5% (see man page for git diff for more details on the `--find-renames` option). For release 3.12.0 the similarity index for the minified CSS was lower than 10%, so the diff output presented the changes to the CSS as a deletion and a creation, which isn't very useful. Using `-M05` to set the threshold made output more readable, so we should keep that change. --- .github/workflows/diff-change-to-dist.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/diff-change-to-dist.yaml b/.github/workflows/diff-change-to-dist.yaml index 9413617617..d34a745760 100644 --- a/.github/workflows/diff-change-to-dist.yaml +++ b/.github/workflows/diff-change-to-dist.yaml @@ -23,7 +23,7 @@ jobs: - name: Generate diff id: diff run: | - git diff -M1 origin/$GITHUB_BASE_REF -- dist \ + git diff -M05 origin/$GITHUB_BASE_REF -- dist \ > $GITHUB_WORKSPACE/dist.diff - name: Add comment to PR uses: actions/github-script@v3