Skip to content
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

ci(workflow): post build result as comment #10618

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

SethFalco
Copy link
Sponsor Member

@SethFalco SethFalco commented Oct 21, 2023

What does this PR do?

Improve repo

For resources

Description

This builds on #6914 by LuigiImVector, which was itself built on #5564 by me. I have preserved LuigiImVector's authorship, as the majority of the work is theirs, but they haven't been active on GitHub lately, so I thought it'd be best to open a new PR.

This takes that PR and makes the following changes:

  • Simplify the workflows, and favors Bash over JavaScript.
  • Remove redundant line breaks when multiple files have problems.
  • Instead of posting a review, post a comment. This is to avoid confusing contributors when other workflows may be failing. (Context)
  • Remove push from linter workflow, we only need it on pull-request, there's no need for push. This also avoids the comment action firing twice.

You can see more context on my changes in my review:

I can see that PR actually got the greenlight to merge, but everyone was too busy. If this gets approved, I'd be happy to test this right away on merge and monitor incoming PRs actively for a while. (Reference)

Checklist:

Follow-up

  • Check the status of GitHub Actions and resolve any reported warnings!

Demo

You can see here, first, the lint action failed, so the comment was posted and a label added. Then later the lint action passed, so the label was removed.

Related

@Thenlie
Copy link
Contributor

Thenlie commented Oct 23, 2023

This does the same thing I was attempting to do in #10562 so that can likely be closed in favor of this as I had not got a complete solution yet.


- name: 'Comment on PR'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is GITHUB_TOKEN available to forked PR's? From the GitHub docs:

Anyone can fork a public repository, and then submit a pull request that proposes changes to the repository's GitHub Actions workflows. Although workflows from forks do not have access to sensitive data such as secrets, they can be an annoyance for maintainers if they are modified for abusive purposes.
Reference

Copy link
Contributor

Choose a reason for hiding this comment

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

I think since this does not run on: pull_request but on another workflow completed, secrets might be available.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Yup! Secrets should be available in comment-pr.yml flow because that's internal for the repo and does not trigger through the fork. (It's triggered indirectly.)

Or at least, this is to the best of my knowledge. If you're up for it, you could try to do a faulty PR to my fork on purpose, and we'll see if the action works. 🤔 No problem if you don't have time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I can do this tonight (US time). Will post the results here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have created a PR on your branch. It is "awaiting workflow approvals". Let me know if I can do anything else here to test this, happy to help!

Copy link
Sponsor Member Author

@SethFalco SethFalco Oct 24, 2023

Choose a reason for hiding this comment

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

Thanks for testing it for me. I approved the workflows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, LGTM!

Copy link
Contributor

@Thenlie Thenlie left a comment

Choose a reason for hiding this comment

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

From what I can tell this seems like a cleaner approach than what I had in #10562. I like the approach of using the GitHub CLI here.

@SethFalco
Copy link
Sponsor Member Author

SethFalco commented Oct 23, 2023

@Thenlie

This does the same thing I was attempting to do in #10562

Ahh, sorry, I didn't notice your PR. Yours is actually susceptible to the same vulnerability that was in my first attempt at this. If I understand it correctly, having a workflow with a write-access token while doing an explicit checkout can open up problems.

I'd recommend you read the following resource, it'll help explain why LuigiImVector and I opted for this two-step process:

You can see the issue here in your PR already:
https://github.com/EbookFoundation/free-programming-books/actions/runs/6595092231/job/17919711537?pr=10562

Despite your branch not being merged yet, the proposed CI pipeline is already being used. If it were given the permission to do what it wanted, other PRs could then go to make malicious changes later. So instead on pull_request we do everything we can without permissions, then in an internal workflow we do the privileged stuff.

@Thenlie
Copy link
Contributor

Thenlie commented Oct 23, 2023

I'd recommend you read the following resource, it'll also help explain LuigiImVector and I opted for this two-step process:

You can see the issue here in your PR already: https://github.com/EbookFoundation/free-programming-books/actions/runs/6595092231/job/17919711537?pr=10562

Despite your branch not being merged yet, the proposed CI pipeline is already being used. If it were given the permission to do what it wanted, other PRs could then go to make malicious changes later. So instead on pull_request we do everything we can without permissions, then in an internal workflow we do the privileged stuff.

Really appreciate this explanation. I ran into the same issue on another project recently as well. This approach definitely seems like the proper one.

@eshellman
Copy link
Collaborator

here goes!

@eshellman eshellman merged commit ae612cf into EbookFoundation:main Oct 25, 2023
6 checks passed
@Thenlie
Copy link
Contributor

Thenlie commented Oct 26, 2023

Seems to be working well 💪

@eshellman
Copy link
Collaborator

Has been very helpful already

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.

Linting Errors as PR Comments
4 participants