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

Document permissions and add example workflow / integration job #401

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

stackptr
Copy link
Member

Documents minimum permissions required for the action to run in repos with restricted default permissions for workflows or for PRs created by Dependabot. These were established by a bit of trial and error in https://github.com/freckle/megarepo/pull/30954 (private repository).

@stackptr stackptr self-assigned this Oct 30, 2023
@stackptr stackptr requested a review from a team as a code owner October 30, 2023 17:40
@stackptr stackptr requested review from pbrisbin and removed request for a team October 30, 2023 17:40
Copy link
Member

@pbrisbin pbrisbin left a comment

Choose a reason for hiding this comment

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

Great idea! Maybe we should add this to any of our -actions template repositories?

Curious about the id-token though. Not sure why that'd be necessary.

README.md Outdated Show resolved Hide resolved
@stackptr
Copy link
Member Author

Great idea! Maybe we should add this to any of our -actions template repositories?

Yeah, this seems good to require as part of minimal documentation for new actions. Is there a repository besides freckle/typescript-action-template?

I think it would be a good rule of thumb for each action repo's CI workflow to specify the minimal required permissions, to flag changes that require more permissive workflow runs.

@pbrisbin
Copy link
Member

pbrisbin commented Oct 30, 2023

Is there a repository besides freckle/typescript-action-template?

I trust your ability to search as well as mine, so probably not?

good rule of thumb for each action repo's CI workflow

By that you mean the action's "example" workflow? The permissions needed to CI an action vs use it would differ, so if this is meant to document usage that would be in the example, I think.

@stackptr
Copy link
Member Author

stackptr commented Oct 30, 2023

Yeah, I was thinking of example.yml workflows (i.e., something that uses: ./. However, I think example.yml should show a representative/common use of the action in a workflow, which is different (in this case) to a test run that exercises the action as a form of CI. Particularly for this action, it's inconvenient to have on.pull_request.types: [opened] since it only runs a single time. Also, exercising the action requires a repo checkout, which is unnecessary for regular use.

I think two workflows are appropriate to add to this repo:

  • example.yml complements or removes the existing section on Usage and wouldn't be expected to run in development PRs
  • test.yml exercises the action with minimal permissions

@pbrisbin
Copy link
Member

pbrisbin commented Oct 30, 2023

Oh yeah, this is interesting.

I think example.yml should show a representative/common use of the action in a workflow, which is different (in this case) to a test run that exercises the action as a form of CI

In my experience they are more often basically the same than they are different in meaningful ways, but I guess that doesn't need to stop us from making them distinct always. As an alternative to your suggestion, how about:

  • example.yml as you describe, but it does run on PRs
  • ci.yml as it is today, typically with unit test jobs, lint etc, but also with integration* Job(s) that exercise the action as necessary (i.e. with different arguments, happy/sad paths) and includes minimal permissions.

I prefer this because:

  1. You really do need to exercise example on PRs IMO, otherwise it'll become broken without us knowing and be bad docs
  2. We're talking about adding a form of CI, so I'd prefer extending the existing "CI" over creating a similarly-named "test"

@stackptr stackptr requested a review from pbrisbin October 30, 2023 18:36
@stackptr stackptr changed the title Document permissions Document permissions and add example workflow / integration job Oct 30, 2023
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/commenter@v1
Copy link
Member

@pbrisbin pbrisbin Oct 30, 2023

Choose a reason for hiding this comment

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

Oh.

I didn't realize this is what you meant, and it feels a bit weird. I see why you suggested not running this workflow on PRs -- it's not exercising the changed code. If I take back my suggestion to run this on PRs (there's no reason to if it's not running with uses: ./) then what is the benefit of this vs just leaving it to the README?

Copy link
Member Author

Choose a reason for hiding this comment

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

The README could remove some of the YAML and refer to the example.yml instead. The workflow is validated and the configuration is parsed by those runs, so it provides slightly more assurance than YAML code blocks in the README, but I don't feel strongly it's a huge improvement.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah, same here about not feeling strongly.

@stackptr stackptr merged commit 03bbcf9 into main Oct 30, 2023
2 checks passed
@stackptr stackptr deleted the corey/permissions branch October 30, 2023 19:21
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.

2 participants