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: buildless ecosystem ci #18525

Merged
merged 60 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b3cdb39
init
Aslemammad Oct 30, 2024
f6a0bc7
debug
Aslemammad Oct 30, 2024
8098da8
debug
Aslemammad Oct 30, 2024
88bc6ec
debug
Aslemammad Oct 30, 2024
a5055fe
debug
Aslemammad Oct 30, 2024
5b26c08
debug
Aslemammad Oct 30, 2024
86b1e80
debug
Aslemammad Oct 30, 2024
998fccc
debug
Aslemammad Oct 31, 2024
3620493
trigger ci
sapphi-red Oct 31, 2024
1422117
debug
Aslemammad Oct 31, 2024
c10930c
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Oct 31, 2024
c205752
debug
Aslemammad Oct 31, 2024
4e1fa89
debug
Aslemammad Oct 31, 2024
3d97e6d
debug
Aslemammad Oct 31, 2024
c23bbc2
debug
Aslemammad Oct 31, 2024
ab8ecf2
debug
Aslemammad Oct 31, 2024
4ca10a1
trigger ci
sapphi-red Nov 1, 2024
a2b8e63
debug
Aslemammad Nov 1, 2024
1158de7
debug
Aslemammad Nov 1, 2024
fe0ad4c
debug
Aslemammad Nov 1, 2024
8a973f9
debug
Aslemammad Nov 1, 2024
004c437
debug
Aslemammad Nov 1, 2024
5bb1a1c
debug
Aslemammad Nov 1, 2024
ba7f2ca
debug
Aslemammad Nov 1, 2024
2a85013
debug
Aslemammad Nov 1, 2024
304e1dd
debug
Aslemammad Nov 1, 2024
32c9aac
debug
Aslemammad Nov 1, 2024
b29e52d
debug
Aslemammad Nov 1, 2024
18508c7
debug
Aslemammad Nov 5, 2024
011a808
debug
Aslemammad Nov 5, 2024
39e2fc8
separation
Aslemammad Nov 5, 2024
19d79df
separation
Aslemammad Nov 5, 2024
1bee76b
separation
Aslemammad Nov 5, 2024
5c70ae1
back to basics
Aslemammad Nov 5, 2024
0e156d6
finalize
Aslemammad Nov 5, 2024
c0093cd
better way to remove reactions
Aslemammad Nov 5, 2024
4de80ca
revert preview-release.yml
Aslemammad Nov 5, 2024
e03be0e
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
c76264c
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
67878e0
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
0eba61a
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
7e13fa0
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
43a1668
Update .github/workflows/ecosystem-ci-trigger.yml
Aslemammad Nov 6, 2024
2dabbab
move permissions check to the top
Aslemammad Nov 6, 2024
9841567
debug git show
Aslemammad Nov 9, 2024
03108e3
debug git show
Aslemammad Nov 9, 2024
9f8ed06
debug git show
Aslemammad Nov 9, 2024
67cb48e
debug git show
Aslemammad Nov 9, 2024
d76f695
debug git show
Aslemammad Nov 9, 2024
9a08d4a
debug git show
Aslemammad Nov 9, 2024
926392e
debug git show
Aslemammad Nov 9, 2024
0206c65
debug git show
Aslemammad Nov 9, 2024
f547431
debug git show
Aslemammad Nov 9, 2024
75afd3b
debug git show
Aslemammad Nov 9, 2024
5cb7224
debug git show
Aslemammad Nov 9, 2024
53fe902
debug git show
Aslemammad Nov 9, 2024
a1dbe40
find collisions properly
Aslemammad Nov 9, 2024
ad35943
remove triage diff
Aslemammad Nov 26, 2024
724fc9e
a comment to note removing the hash ambiguity check
Aslemammad Nov 26, 2024
d6961c2
format
Aslemammad Nov 26, 2024
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
180 changes: 157 additions & 23 deletions .github/workflows/ecosystem-ci-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,51 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'vitejs/vite' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
steps:
- uses: actions/github-script@v7
- name: Get PR Data
uses: actions/github-script@v7
id: get-pr-data
with:
script: |
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
core.setOutput('head_sha', pr.head.sha)
return {
num: context.issue.number,
branchName: pr.head.ref,
commit: pr.head.sha,
repo: pr.head.repo.full_name
}

- name: Check Package Existence
uses: actions/github-script@v7
id: check-package
with:
script: |
const prData = ${{ steps.get-pr-data.outputs.result }}
const url = `https://pkg.pr.new/vite@${prData.commit}`
const response = await fetch(url)
Copy link
Contributor Author

@Aslemammad Aslemammad Nov 5, 2024

Choose a reason for hiding this comment

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

We do not yet implement the HEAD for pkg.pr.new! So here instead of consuming the request body and waiting for it, we just check the status and then the step would be done.

So if it was fetching, it'd be aborted I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@dominikg dominikg Nov 5, 2024

Choose a reason for hiding this comment

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

if you await fetch(), the full file has been downloaded already, its just not been parsed yet. of course if pkg.pr.new does not implement head we have to go with full, but should be considered as an optimization. or do you implement the endpoints about package information that the public registry has?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you await fetch(), the full file has been downloaded already

I did not know that, does not that defeat the purpose of streams (e.g. .body)?

As far as I know the await on .body would wait until finishing the fetch and meanwhile give us the result buffer by buffer while fetching.

but should be considered as an optimization

💯

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, maybe need to get more coffee and you are right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, thanks, let me get my own coffee too now 😅

Copy link

Choose a reason for hiding this comment

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

We do not yet implement the HEAD for pkg.pr.new!

Any plan to support it? It sounds interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any plan to support it? It sounds interesting.

I'll create an issue for it then!

console.log(`Package check URL: ${url}, Status: ${response.status}`)

// Add 'rocket' reaction to the issue comment
if (response.status === 404) {
const reaction = await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket',
})
return { exists: false, reaction: reaction.id }
}

return { exists: true, reaction: null }
Aslemammad marked this conversation as resolved.
Show resolved Hide resolved

- name: Check User Permissions
uses: actions/github-script@v7
id: check-permissions
with:
script: |
const user = context.payload.sender.login
Expand All @@ -27,53 +71,143 @@ jobs:
console.warn(e)
}

if (hasTriagePermission) {
console.log('Allowed')
if (allowed) {
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('Not allowed')
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('not allowed')
throw new Error('User does not have the necessary permissions.')
}
- uses: actions/github-script@v7
id: get-pr-data

- name: Generate Token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
installation_retrieval_payload: "${{ github.repository_owner }}/vite-ecosystem-ci"
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}

- name: Trigger Preview Release (if Package Not Found)
if: steps.check-package.outputs.exists == false
uses: actions/github-script@v7
id: trigger-preview-release
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
const { data: pr } = await github.rest.pulls.get({
const prData = ${{ steps.get-pr-data.outputs.result }}
console.log('Package not found, triggering preview release...')

// Add label "trigger: preview" to the PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
issue_number: prData.num,
labels: ['trigger: preview']
})
return {
num: context.issue.number,
branchName: pr.head.ref,
repo: pr.head.repo.full_name,
commit: pr.head.sha
console.log('Added "trigger: preview" label.')

- name: Wait for Preview Release Completion (if Package Not Found)
if: steps.check-package.outputs.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 workflowFileName = 'preview-release.yml'
const workflow = await github.rest.actions.getWorkflow({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflowFileName,
})
const workflowId = workflow.data.id
console.log(`Waiting for workflow ID ${workflowId} to complete...`)

const maxRetries = 60 // Wait up to 10 minutes
const delay = 10000 // 10 seconds
let completed = false

for (let i = 0; i < maxRetries; i++) {
const runsData = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflowId,
head_sha: prData.commit,
per_page: 100,
page: 1,
})

const runs = runsData.data.workflow_runs

if (runs.length > 0) {
const latestRun = runs[0]
console.log(`Latest run status: ${latestRun.status}, conclusion: ${latestRun.conclusion}`)
if (latestRun.status === 'completed') {
if (latestRun.conclusion === 'success') {
console.log('Preview release workflow completed successfully.')
completed = true
break
} else {
throw new Error('Preview Release workflow failed.')
}
}
}

console.log(`Retrying... (${i + 1}/${maxRetries})`)
await new Promise(resolve => setTimeout(resolve, delay))
}
- id: generate-token
uses: tibdex/github-app-token@v2

if (!completed) {
throw new Error('Preview Release workflow did not complete in time.')
}

// Remove the 'rocket' reaction
if (reaction) {
await github.rest.reactions.deleteForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
reaction_id: reaction,
})
console.log('Removed "rocket" reaction.')
}

- name: Checkout
uses: actions/checkout@v4
with:
app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
installation_retrieval_payload: "${{ github.repository_owner }}/vite-ecosystem-ci"
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/github-script@v7
fetch-depth: 0

# This step can be removed on May 26 2025
- name: Check Commit Hash Ambiguity
id: check_ambiguity
run: |
HEAD_SHA=${{ steps.get-pr-data.outputs.head_sha }}
COMMIT_SHORT=${HEAD_SHA:0:7}

if git show "$COMMIT_SHORT"; then
echo "COLLISION=false" >> $GITHUB_ENV
else
echo "COLLISION=true" >> $GITHUB_ENV
fi

- name: Trigger Downstream Workflow
uses: actions/github-script@v7
id: trigger
env:
COMMENT: ${{ github.event.comment.body }}
with:
github-token: ${{ steps.generate-token.outputs.token }}
result-encoding: string
script: |
const comment = process.env.COMMENT.trim()
const prData = ${{ steps.get-pr-data.outputs.result }}
Expand All @@ -89,7 +223,7 @@ jobs:
prNumber: '' + prData.num,
branchName: prData.branchName,
repo: prData.repo,
commit: prData.commit,
commit: process.env.COLLISION === 'false' ? prData.commit : '',
Copy link
Member

@sapphi-red sapphi-red Nov 28, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, let me do so!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

merged that, thanks!

suite: suite === '' ? '-' : suite
}
})
Loading