Skip to content

Update link-check to 0.12 using CLI and comment reporting - #3700

Merged
rogermparent merged 25 commits into
mainfrom
link-check-0.12
Jul 19, 2022
Merged

rogermparent merged 25 commits into
mainfrom
link-check-0.12

Conversation

@rogermparent

@rogermparent rogermparent commented Jun 28, 2022 •

Copy link
Copy Markdown
Contributor

This PR upgrades link-check to 0.12, which should squash the "diffs are too big" problem/bug.

In order to squash an issue where node:buffer couldn't be imported in the GH Action, this PR now just uses link check through the CLI and its stdout to make a special review comment which gets edited after each check.

screenshot of a failing version of this PR's content

#3700 (comment)

screenshot of checks list

We no longer have three checks for link check!

@shcheklein
shcheklein temporarily deployed to dvc-org-link-check-0-12-0qb8is June 28, 2022 19:06 Inactive
@rogermparent rogermparent self-assigned this Jun 28, 2022
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is June 28, 2022 20:45 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is June 28, 2022 20:48 Inactive
github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll follow up with a change to update actions/checkout in all our other actions as well, from what I've seen it's a no-downsides performance upgrade.

@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is June 28, 2022 21:15 Inactive
@shcheklein

Copy link
Copy Markdown
Contributor

@rogermparent ping

@rogermparent

Copy link
Copy Markdown
Contributor Author

Sorry, this has fallen by the wayside a bit, I'll bump it up in my priorities this week!

@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 17:17 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 17:30 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 17:41 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 18:16 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 18:32 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 19:11 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 13, 2022 20:02 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 14, 2022 01:56 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 14, 2022 02:03 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 18, 2022 23:24 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 18, 2022 23:33 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 18, 2022 23:59 Inactive
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 19, 2022 00:06 Inactive
@rogermparent rogermparent changed the title Update link-check to 0.12 Update link-check to 0.12 using CLI and comment reporting Jul 19, 2022
@rogermparent
rogermparent temporarily deployed to dvc-org-link-check-0-12-0qb8is July 19, 2022 01:29 Inactive
@github-actions

github-actions Bot commented Jul 19, 2022 •

Copy link
Copy Markdown
Contributor

Link Check Report

There were no links to check!

name: Initialize
name: Run
runs-on: ubuntu-latest
continue-on-error: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets us continue even if an existing report comment isn't found

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also skip any other error occurrence without reporting the error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it does, I'll need to improve that next. If an error occurs, the script will just write the "Link Check Report" h1 with no content. I'm pretty sure that can be fixed by getting stderr output into the content body in the bash script part of the action.

Comment on lines +21 to +28
set +e
body="<h1 id=\"link-check\">Link Check Report</h1>

$(
npx repo-link-check \
-d -c config/link-check/config.yml \
-r ${{ github.event.deployment.payload.web_url }}
)"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set +e prevents the script from exiting when repo-link-check exits with code 2. +e is a normal default for interactive terminals, but -e is used in some CI like GitHub Actions.

Comment on lines +29 to +33
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=report::$body"
exit 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From create-or-update-comment docs, escapes the command result for GH Action output

Comment on lines +35 to +43
- name: Find PR associated with deployment
uses: actions/github-script@v6
id: pr-number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
diff: main
configFile: config/link-check/config.yml
rootURL: '${{ github.event.deployment.payload.web_url }}'
output: checksAction
- uses: LouisBrunner/[email protected]
if: ${{ success() }}
script: |
const findPR = require('./.github/workflows/deployment-report.js')
return await findPR({ github, context, core })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action is really handy for rapidly prototyping weird stuff with the GitHub API. You can import modules so most of the code can be properly linted instead of being stuck in a YAML block.

Comment on lines +45 to +51
- name: Find Existing Link Check Report Comment
uses: peter-evans/find-comment@v2
id: fc
with:
token: ${{ secrets.GITHUB_TOKEN }}
check_id: ${{ steps.build_check.outputs.check_id }}
status: completed
conclusion: ${{ steps.check.outputs.conclusion }}
output: ${{ steps.check.outputs.output }}
- uses: LouisBrunner/[email protected]
if: ${{ failure() }}
issue-number: ${{ steps.pr-number.outputs.result }}
comment-author: 'github-actions[bot]'
body-includes: "<h1 id=\"link-check\">Link Check Report</h1>"

@rogermparent rogermparent Jul 19, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a way to navigate to the report comment with the anchor #user-content-link-check, and also helps further prevent false positives on which comment we find to edit.

Comment on lines +1 to +12
module.exports = async ({ github, context }) => {
const sha = context.sha
const owner = context.payload.repository.owner.login
const repo = context.payload.repository.name
const { data: pulls } = await github.rest.pulls.list({
state: 'open',
owner,
repo
})
const actionPull = pulls.find(pull => pull.head.sha === sha)
return actionPull.number
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deployment_status event we use from Heroku doesn't actually include info about the pull request, so we have to duck into the GitHub API to get that PR via the current commit's sha.

@yathomasi yathomasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking alright to me. Great work @rogermparent.
I can see the report generated and updated fine.

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger, have you tried to use CML for this? Could you share your experience?

@rogermparent

rogermparent commented Jul 19, 2022 •

Copy link
Copy Markdown
Contributor Author

I took a look at CML, but hit the "Known Issues" portion of the send-comment docs that states the following:

commit_id has been locked.

This error is caused by using the default GitHub token with cml send-comment --update. Use a personal access token (PAT) instead.

Beyond that, I'm not sure how well it handles how we're using deployment_status, but maybe that's not an issue.

It seemed as if CML may not be capable of the few niche requirements of this action, so I just finished the last parts of the implementation I already had mostly done to take the path of least resistance for getting this update in. I'd be happy to make a follow-up PR trying out CML, and then report back on the experience.

This branch was previously deployed

1 inactive deployment
dvc-org-link-check-0-12-0qb8is — 61be6939 Deployed Jul 19, 2022 by rogermparent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants