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

chore(ci): add repository dispatch workflow #2442

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

Sec-ant
Copy link
Contributor

@Sec-ant Sec-ant commented Apr 14, 2024

Summary

Add repository dispatch workflow. This workflow is meant to trigger the Pin submodule and run codegen workflow in biomejs/website whenever a push event is issued from the main branch.

To trigger the workflow in another repository, this workflow needs a PAT (Personal Access Token) and stores it as a repository secret. I used the secrete name BIOME_REPOSITORY_DISPATCH in this workflow. Further details about the token permissions can be found here: https://github.com/peter-evans/repository-dispatch?tab=readme-ov-file#token

I suggest that we create a dedicated account under the organization (maybe with the name biomecookie or something like that) for token management. So personal access tokens won't be associated with any personal accounts. We should also only grant the minimal permissions for the tokens we need.

A dedicated account for tokens will also let us to use it instead of github-actions[bot] to trigger other workflows:

When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN, with the exception of workflow_dispatch and repository_dispatch, will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

Commits pushed by a GitHub Actions workflow that uses the GITHUB_TOKEN do not trigger a GitHub Pages build.

A bit of info on creating a machine user:

Test Plan

Copy link

netlify bot commented Apr 14, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit ff8fea6
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/661b686357fd8600088b69f3
😎 Deploy Preview https://deploy-preview-2442--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (no change from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

if: ${{ github.event_name == 'push' }}
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.BIOME_REPOSITORY_DISPATCH }}
Copy link
Contributor Author

@Sec-ant Sec-ant Apr 14, 2024

Choose a reason for hiding this comment

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

This is the PAT token we use and it should be stored as a repository secret and the name should match (I used the name BIOME_REPOSITORY_DISPATCH, we can change the name but they should be kept the same).

@Sec-ant Sec-ant mentioned this pull request Apr 16, 2024
21 tasks
@ematipico
Copy link
Member

The bot should up and running now. The only thing that I changed was the name of the secret: BIOME_COOKIE_BOT

In the future, we can use it instead of the github bot if we want.

@Sec-ant
Copy link
Contributor Author

Sec-ant commented Apr 16, 2024

The only thing that I changed was the name of the secret: BIOME_COOKIE_BOT

I maybe wrong because I have no experience managing tokens for an organization. But shouldn't we have different dedicated tokens with the least permissions granted for each kind of tasks we run? A single token with many permissions may have some security risks, and BIOME_COOKIE_BOT seems a multi-purpose token with many permissions granted to me.

@ematipico
Copy link
Member

For now, BIOME_COOKIE_BOT has only the permissions required by this kind of workflow.

If we require different permissions, we can create a different PAT with fine-grained permissions; then, using the values of said PAT, we can create one more secret in the repository where we need said permissions.

Although, you actually have a good point, and it makes sense to name the secret based on what is meant for. I will update the name of the secret.

@ematipico
Copy link
Member

Done!

@Sec-ant
Copy link
Contributor Author

Sec-ant commented Apr 16, 2024

Done!

Thanks, just to be sure, is the new secret name BIOME_REPOSITORY_DISPATCH?

@ematipico
Copy link
Member

Yes, that's the name

@Sec-ant Sec-ant merged commit 8b2ef89 into biomejs:main Apr 16, 2024
5 checks passed
@Sec-ant Sec-ant deleted the ci/add-repository-dispatch branch April 16, 2024 11:56
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.

None yet

2 participants