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: fix ecosystem ci trigger #18927

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions .github/workflows/ecosystem-ci-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,45 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'vitejs/vite' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
steps:
- name: Check User Permissions
uses: actions/github-script@v7
id: check-permissions
with:
script: |
const user = context.payload.sender.login
console.log(`Validate user: ${user}`)

let hasTriagePermission = false
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user,
});
hasTriagePermission = data.user.permissions.triage
} catch (e) {
console.warn(e)
}

if (hasTriagePermission) {
console.log('User is allowed. Adding +1 reaction.')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '+1',
})
} else {
console.log('User is not allowed. Adding -1 reaction.')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '-1',
})
throw new Error('User does not have the necessary permissions.')
}

- name: Get PR Data
uses: actions/github-script@v7
id: get-pr-data
Expand Down Expand Up @@ -51,45 +90,6 @@ jobs:

return { exists: true, reaction: null }

- name: Check User Permissions
uses: actions/github-script@v7
id: check-permissions
with:
script: |
const user = context.payload.sender.login
console.log(`Validate user: ${user}`)

let hasTriagePermission = false
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user,
});
hasTriagePermission = data.user.permissions.triage
} catch (e) {
console.warn(e)
}

if (hasTriagePermission) {
console.log('User is allowed. Adding +1 reaction.')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '+1',
})
} else {
console.log('User is not allowed. Adding -1 reaction.')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '-1',
})
throw new Error('User does not have the necessary permissions.')
}

- name: Generate Token
id: generate-token
uses: tibdex/github-app-token@v2
Expand All @@ -99,7 +99,7 @@ jobs:
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}

- name: Trigger Preview Release (if Package Not Found)
if: steps.check-package.outputs.exists == false
if: fromJSON(steps.check-package.outputs.result).exists == false
uses: actions/github-script@v7
id: trigger-preview-release
with:
Expand All @@ -118,13 +118,13 @@ jobs:
console.log('Added "trigger: preview" label.')

- name: Wait for Preview Release Completion (if Package Not Found)
if: steps.check-package.outputs.exists == false
if: fromJSON(steps.check-package.outputs.result).exists == false
uses: actions/github-script@v7
id: wait-preview-release
with:
script: |
const prData = ${{ steps.get-pr-data.outputs.result }}
const reaction = ${{ steps.check-package.outputs.reaction }}
const reaction = ${{ fromJSON(steps.check-package.outputs.result).reaction }}
const workflowFileName = 'preview-release.yml'
const workflow = await github.rest.actions.getWorkflow({
owner: context.repo.owner,
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
- name: Check Commit Hash Ambiguity
id: check_ambiguity
run: |
HEAD_SHA=${{ steps.get-pr-data.outputs.head_sha }}
HEAD_SHA=${{ fromJSON(steps.get-pr-data.outputs.result).head_sha }}
COMMIT_SHORT=${HEAD_SHA:0:7}

if git show "$COMMIT_SHORT"; then
Expand Down
Loading