-
Notifications
You must be signed in to change notification settings - Fork 262
ci: auto upgrade deps and create pr #368
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d8e2dbf
ci: auto upgrade deps and create pr
Brooooooklyn d4e58fd
allow oxc packages conflict
Brooooooklyn 7412d1a
allow tinybench
Brooooooklyn f1fc969
allow tinybench
Brooooooklyn a1c8ea1
fix sync
Brooooooklyn e195587
pr target
Brooooooklyn d5d7a12
sign commit
Brooooooklyn c20458a
sign commit
Brooooooklyn 37dcb4a
fix: add API response validation and pre-release version support
Brooooooklyn 587bf11
update lockfile again after build
Brooooooklyn 0e22868
also dedupe lockfile
Brooooooklyn db22321
Update @vitejs/devtools
Brooooooklyn 793c20b
replace pr token
Brooooooklyn d65f06e
split tokens
Brooooooklyn d19deb7
fix regexp
Brooooooklyn ea6f3f5
delete previous branch
Brooooooklyn 432401a
delete previous branch
Brooooooklyn 3be7d4a
remove dprint
Brooooooklyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
|
|
||
| const ROOT = process.cwd() | ||
|
|
||
| // ============ GitHub API ============ | ||
| async function getLatestTagCommit(owner, repo) { | ||
| const res = await fetch( | ||
| `https://api.github.com/repos/${owner}/${repo}/tags`, | ||
| { | ||
| headers: { | ||
| Authorization: `token ${process.env.GITHUB_TOKEN}`, | ||
| Accept: 'application/vnd.github.v3+json', | ||
| }, | ||
| } | ||
| ) | ||
| if (!res.ok) { | ||
| throw new Error( | ||
| `Failed to fetch tags for ${owner}/${repo}: ${res.status} ${res.statusText}` | ||
| ) | ||
| } | ||
| const tags = await res.json() | ||
| if (!Array.isArray(tags) || !tags.length) { | ||
| throw new Error(`No tags found for ${owner}/${repo}`) | ||
| } | ||
| if (!tags[0]?.commit?.sha) { | ||
| throw new Error( | ||
| `Invalid tag structure for ${owner}/${repo}: missing commit SHA` | ||
| ) | ||
| } | ||
| return tags[0].commit.sha | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| // ============ npm Registry ============ | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| async function getLatestNpmVersion(packageName) { | ||
| const res = await fetch(`https://registry.npmjs.org/${packageName}/latest`) | ||
| if (!res.ok) { | ||
| throw new Error( | ||
| `Failed to fetch npm version for ${packageName}: ${res.status} ${res.statusText}` | ||
| ) | ||
| } | ||
| const data = await res.json() | ||
| if (!data?.version) { | ||
| throw new Error( | ||
| `Invalid npm response for ${packageName}: missing version field` | ||
| ) | ||
| } | ||
| return data.version | ||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| // ============ Update .upstream-versions.json ============ | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| async function updateUpstreamVersions() { | ||
| const filePath = path.join(ROOT, 'packages/tools/.upstream-versions.json') | ||
| const data = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
|
|
||
| // rolldown -> rolldown/rolldown | ||
| data.rolldown.hash = await getLatestTagCommit('rolldown', 'rolldown') | ||
|
|
||
| // rolldown-vite -> vitejs/vite | ||
| data['rolldown-vite'].hash = await getLatestTagCommit('vitejs', 'vite') | ||
|
|
||
| fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n') | ||
| console.log('Updated .upstream-versions.json') | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // ============ Update pnpm-workspace.yaml ============ | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| async function updatePnpmWorkspace(vitestVersion, tsdownVersion) { | ||
| const filePath = path.join(ROOT, 'pnpm-workspace.yaml') | ||
| let content = fs.readFileSync(filePath, 'utf8') | ||
|
|
||
| // Update vitest-dev override (handle pre-release versions like -beta.1, -rc.0) | ||
| content = content.replace( | ||
| /vitest-dev: 'npm:vitest@\^[\d.]+(-[\w.]+)?'/, | ||
| `vitest-dev: 'npm:vitest@^${vitestVersion}'` | ||
| ) | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| // Update tsdown in catalog (handle pre-release versions) | ||
| content = content.replace( | ||
| /tsdown: \^[\d.]+(-[\w.]+)?/, | ||
| `tsdown: ^${tsdownVersion}` | ||
| ) | ||
|
|
||
| fs.writeFileSync(filePath, content) | ||
| console.log('Updated pnpm-workspace.yaml') | ||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| // ============ Update packages/test/package.json ============ | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| async function updateTestPackage(vitestVersion) { | ||
| const filePath = path.join(ROOT, 'packages/test/package.json') | ||
| const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
|
|
||
| // Update all @vitest/* devDependencies | ||
| for (const dep of Object.keys(pkg.devDependencies)) { | ||
| if (dep.startsWith('@vitest/')) { | ||
| pkg.devDependencies[dep] = vitestVersion | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| // Update vitest-dev devDependency | ||
| if (pkg.devDependencies['vitest-dev']) { | ||
| pkg.devDependencies['vitest-dev'] = `^${vitestVersion}` | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Update @vitest/ui peerDependency if present | ||
| if (pkg.peerDependencies?.['@vitest/ui']) { | ||
| pkg.peerDependencies['@vitest/ui'] = vitestVersion | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| } | ||
|
|
||
| fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n') | ||
| console.log('Updated packages/test/package.json') | ||
| } | ||
|
|
||
| // ============ Update packages/core/package.json ============ | ||
| async function updateCorePackage(devtoolsVersion) { | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| const filePath = path.join(ROOT, 'packages/core/package.json') | ||
| const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
|
|
||
| // Update @vitejs/devtools in devDependencies | ||
| if (pkg.devDependencies?.['@vitejs/devtools']) { | ||
| pkg.devDependencies['@vitejs/devtools'] = `^${devtoolsVersion}` | ||
| } | ||
|
|
||
| fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n') | ||
| console.log('Updated packages/core/package.json') | ||
| } | ||
|
|
||
| // ============ Main ============ | ||
| async function main() { | ||
| console.log('Fetching latest versions...') | ||
|
|
||
| const [vitestVersion, tsdownVersion, devtoolsVersion] = await Promise.all([ | ||
| getLatestNpmVersion('vitest'), | ||
| getLatestNpmVersion('tsdown'), | ||
| getLatestNpmVersion('@vitejs/devtools'), | ||
| ]) | ||
|
|
||
| console.log(`vitest: ${vitestVersion}`) | ||
| console.log(`tsdown: ${tsdownVersion}`) | ||
| console.log(`@vitejs/devtools: ${devtoolsVersion}`) | ||
|
|
||
| await updateUpstreamVersions() | ||
| await updatePnpmWorkspace(vitestVersion, tsdownVersion) | ||
| await updateTestPackage(vitestVersion) | ||
| await updateCorePackage(devtoolsVersion) | ||
|
|
||
| console.log('Done!') | ||
| } | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| main().catch((err) => { | ||
| console.error(err) | ||
| process.exit(1) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ on: | |
| push: | ||
| branches: | ||
| - main | ||
| - deps/upstream-update | ||
| paths-ignore: | ||
| - '**/*.md' | ||
| pull_request: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| name: Upgrade Upstream Dependencies | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * *' # Daily at midnight UTC | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| workflow_dispatch: # Manual trigger | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| upgrade: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| - uses: ./.github/actions/clone | ||
|
|
||
| - name: Configure Git for access to vite-task | ||
| run: git config --global url."https://x-access-token:${{ secrets.VITE_TASK_TOKEN }}@github.com/".insteadOf "https://github.com/" | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| - uses: oxc-project/setup-rust@d286d43bc1f606abbd98096666ff8be68c8d5f57 # v1.0.0 | ||
| with: | ||
| save-cache: ${{ github.ref_name == 'main' }} | ||
| cache-key: upgrade-deps | ||
|
|
||
| - uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4 | ||
|
|
||
| - name: Rustup Adds Target | ||
| run: rustup target add x86_64-unknown-linux-gnu | ||
|
|
||
| - name: Rustup Adds Target for rolldown | ||
| working-directory: rolldown | ||
| run: rustup target add x86_64-unknown-linux-gnu | ||
|
|
||
| - name: Upgrade dependencies | ||
| id: upgrade | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: node .github/scripts/upgrade-deps.mjs | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| - name: Sync remote and build | ||
| id: build | ||
| continue-on-error: true # Create PR even if build fails | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
| run: | | ||
| pnpm install --no-frozen-lockfile | ||
| pnpm tool sync-remote | ||
| pnpm install --no-frozen-lockfile | ||
|
|
||
|
Brooooooklyn marked this conversation as resolved.
|
||
| - name: Build | ||
| uses: ./.github/actions/build-upstream | ||
| with: | ||
| target: x86_64-unknown-linux-gnu | ||
| build-rolldown-native: 'true' | ||
|
Brooooooklyn marked this conversation as resolved.
Brooooooklyn marked this conversation as resolved.
|
||
|
|
||
| - name: Update lockfile | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| run: | | ||
| pnpm install --no-frozen-lockfile | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| pnpm dedupe | ||
|
|
||
| - name: Close and delete previous PR | ||
| env: | ||
| GH_TOKEN: ${{ secrets.AUTO_UPDATE_BRANCH_TOKEN }} | ||
| run: | | ||
| # Find PR with the deps/upstream-update branch | ||
| PR_NUMBER=$(gh pr list --head deps/upstream-update --json number --jq '.[0].number') | ||
|
|
||
| if [ -n "$PR_NUMBER" ]; then | ||
| echo "Found existing PR #$PR_NUMBER, closing and deleting branch..." | ||
| gh pr close "$PR_NUMBER" --delete-branch | ||
| else | ||
| echo "No existing PR found with branch deps/upstream-update" | ||
| fi | ||
|
|
||
|
Brooooooklyn marked this conversation as resolved.
|
||
| - name: Create/Update PR | ||
| uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11 | ||
| with: | ||
| base: main | ||
| branch: deps/upstream-update | ||
|
Brooooooklyn marked this conversation as resolved.
|
||
| title: 'feat(deps): upgrade upstream dependencies' | ||
| sign-commits: true | ||
| token: ${{ secrets.AUTO_UPDATE_BRANCH_TOKEN }} | ||
| branch-token: ${{ secrets.GITHUB_TOKEN }} | ||
| body: | | ||
| Automated daily upgrade of upstream dependencies: | ||
| - rolldown (latest tag) | ||
| - rolldown-vite (latest tag) | ||
| - vitest (latest npm version) | ||
| - tsdown (latest npm version) | ||
|
|
||
| Build status: ${{ steps.build.outcome }} | ||
| commit-message: 'feat(deps): upgrade upstream dependencies' | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.