-
Notifications
You must be signed in to change notification settings - Fork 15
fix: Replace reusable workflow with standalone canary release #1189
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
Changes from all commits
2a48ffc
3216eb2
c242c72
e172653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,230 @@ on: | |||||
| - created | ||||||
|
|
||||||
| jobs: | ||||||
| trigger-deploy: | ||||||
| name: Canary Deploy | ||||||
| uses: jupiterone/github-internal/.github/workflows/monorepo-canary-release.yaml@v1 | ||||||
| secrets: inherit | ||||||
| # Gate job to check authorization before running the main workflow | ||||||
| check-authorization: | ||||||
| name: Check Authorization | ||||||
| runs-on: ubuntu-latest | ||||||
| if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/canary-release') }} | ||||||
| outputs: | ||||||
| is-authorized: ${{ steps.check.outputs.authorized }} | ||||||
| steps: | ||||||
| - name: Check if user is authorized | ||||||
| id: check | ||||||
| uses: actions/github-script@v7 | ||||||
| with: | ||||||
| script: | | ||||||
| const authorAssociation = context.payload.comment.author_association; | ||||||
| const authorizedRoles = ['OWNER', 'MEMBER', 'COLLABORATOR']; | ||||||
| const isAuthorized = authorizedRoles.includes(authorAssociation); | ||||||
|
|
||||||
| console.log(`Author: ${context.payload.comment.user.login}`); | ||||||
| console.log(`Association: ${authorAssociation}`); | ||||||
| console.log(`Authorized: ${isAuthorized}`); | ||||||
|
|
||||||
| core.setOutput('authorized', isAuthorized ? 'true' : 'false'); | ||||||
|
|
||||||
| if (!isAuthorized) { | ||||||
| await github.rest.reactions.createForIssueComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| comment_id: context.payload.comment.id, | ||||||
| content: '-1', | ||||||
| }); | ||||||
|
|
||||||
| await github.rest.issues.createComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| issue_number: context.issue.number, | ||||||
| body: `⛔ **Unauthorized**: Only organization members can trigger canary releases.\n\n` + | ||||||
| `User \`${context.payload.comment.user.login}\` has association: \`${authorAssociation}\`` | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| canary-release: | ||||||
| name: Canary Release | ||||||
| runs-on: ubuntu-latest | ||||||
| needs: check-authorization | ||||||
| if: ${{ needs.check-authorization.outputs.is-authorized == 'true' }} | ||||||
| # Environment with protection rules - configure in GitHub Settings > Environments | ||||||
| environment: canary-publish | ||||||
| permissions: | ||||||
| contents: write | ||||||
| pull-requests: write | ||||||
| id-token: write | ||||||
| steps: | ||||||
| - name: Add reaction to comment | ||||||
| uses: actions/github-script@v7 | ||||||
| with: | ||||||
| script: | | ||||||
| await github.rest.reactions.createForIssueComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| comment_id: context.payload.comment.id, | ||||||
| content: 'eyes', | ||||||
| }); | ||||||
|
|
||||||
| - name: Post starting comment | ||||||
| id: start-comment | ||||||
| uses: actions/github-script@v7 | ||||||
| with: | ||||||
| script: | | ||||||
| const comment = await github.rest.issues.createComment({ | ||||||
| owner: context.repo.owner, | ||||||
| repo: context.repo.repo, | ||||||
| issue_number: context.issue.number, | ||||||
| body: `🚀 Canary release workflow has been triggered.\n\nYou can follow the progress [here](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}).` | ||||||
| }); | ||||||
| return comment.data.id; | ||||||
| result-encoding: string | ||||||
|
|
||||||
| - name: Checkout PR | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| ref: refs/pull/${{ github.event.issue.number }}/head | ||||||
| fetch-depth: 0 | ||||||
| token: ${{ secrets.AUTO_GITHUB_PAT_TOKEN }} | ||||||
|
|
||||||
| - name: Setup Node.js | ||||||
| uses: actions/setup-node@v4 | ||||||
| with: | ||||||
| node-version: '20' | ||||||
| registry-url: 'https://registry.npmjs.org' | ||||||
|
|
||||||
| - name: Configure npm for JupiterOne packages | ||||||
| run: | | ||||||
| echo "@jupiterone:registry=https://npm.pkg.github.com" >> .npmrc | ||||||
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" >> .npmrc | ||||||
|
||||||
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" >> .npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_PACKAGES_NPM_TOKEN }}" >> .npmrc |
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 same NPM_AUTH_TOKEN is being used for both GitHub Packages and the public npm registry. This could be a security concern if the token has broader permissions than needed. Consider using separate tokens (NPM_AUTH_TOKEN for npm and GITHUB_TOKEN or a dedicated token for GitHub Packages) to follow the principle of least privilege.