-
Notifications
You must be signed in to change notification settings - Fork 394
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
Update link-check to 0.12 using CLI and comment reporting #3700
Conversation
@@ -12,9 +12,10 @@ jobs: | |||
github.event.deployment.ref != 'main' && | |||
github.event.deployment_status.state == 'success' | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- uses: actions/checkout@v3 |
There was a problem hiding this comment.
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 ping |
Sorry, this has fallen by the wayside a bit, I'll bump it up in my priorities this week! |
86f3938
to
06ee952
Compare
06ee952
to
7af895a
Compare
Link Check ReportThere were no links to check! |
runs-on: ubuntu-latest | ||
continue-on-error: true |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 }} | ||
)" |
There was a problem hiding this comment.
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.
body="${body//'%'/'%25'}" | ||
body="${body//$'\n'/'%0A'}" | ||
body="${body//$'\r'/'%0D'}" | ||
echo "::set-output name=report::$body" | ||
exit 0 |
There was a problem hiding this comment.
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
- 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 }) |
There was a problem hiding this comment.
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.
- 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>" |
There was a problem hiding this comment.
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.
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 | ||
} |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
I took a look at CML, but hit the "Known Issues" portion of the
Beyond that, I'm not sure how well it handles how we're using 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 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.#3700 (comment)
We no longer have three checks for link check!