diff --git a/.github/workflows/dependabot-pr.yml b/.github/workflows/dependabot-pr.yml index 1b6a720..91a5f55 100644 --- a/.github/workflows/dependabot-pr.yml +++ b/.github/workflows/dependabot-pr.yml @@ -18,4 +18,5 @@ jobs: if: ${{ contains(needs.dependabot-metadata.outputs.dependency-names, 'biome') }} permissions: contents: write + pull-requests: write uses: ./.github/workflows/update.yml diff --git a/.github/workflows/update.js b/.github/workflows/update.js index 4ad9640..5170b23 100644 --- a/.github/workflows/update.js +++ b/.github/workflows/update.js @@ -16,14 +16,14 @@ async function main() { return; } - await setGitConfig(); + await setGitConfig(missingVersions); for (const version of missingVersions) { - console.log(`Updating to ${PACKAGE_NAME} ${version}`); + console.log(getMessage(version)); await updateFiles(version); - await commitAndPushTag(version); + await commitTag(version); } - await git("push", "origin", `HEAD:refs/heads/${DEFAULT_BRANCH}`); + await mergePullRequest(missingVersions); } async function getMissingVersions() { @@ -37,6 +37,12 @@ async function getAllVersions() { return allVersions.filter((v) => !v.includes("nightly")).sort(); } +async function getNodePackageVersions(packageName) { + const { stdout } = await exec(`npm view ${packageName} --json`); + const output = JSON.parse(stdout); + return output.versions; +} + async function getExistingVersions() { const existingTags = await git("tag", "--list"); return existingTags @@ -45,17 +51,21 @@ async function getExistingVersions() { .sort(); } -async function setGitConfig() { +function getMessage(version) { + return `build(deps): bump ${PACKAGE_NAME} to ${version}`; +} + +async function setGitConfig(versions) { const email = `${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com`; + await git("config", "user.name", GITHUB_ACTOR); await git("config", "user.email", email); await git("checkout", DEFAULT_BRANCH); + await git("checkout", "-b", getBranchName(versions.at(-1))); } -async function getNodePackageVersions(packageName) { - const { stdout } = await exec(`npm view ${packageName} --json`); - const output = JSON.parse(stdout); - return output.versions; +function getBranchName(version) { + return `build/bump-${PACKAGE_NAME.replace("/", "-")}-${version}`; } async function updateFiles(version) { @@ -82,12 +92,25 @@ async function updatePackageJson(version) { ); } -async function commitAndPushTag(version) { +async function commitTag(version) { const tag = `v${version}`; + const message = getMessage(version); + await git("add", "README.md", "package.json", "package-lock.json"); - await git("commit", "-m", `"MAINT: upgrade to ${PACKAGE_NAME} ${version}"`); - await git("tag", tag); - await git("push", "origin", tag); + await git("commit", "--message", `"${message}"`); + await git("tag", "--annotate", tag, "--message", `"${message}"`); +} + +async function mergePullRequest(versions) { + await git( + "push", + "--follow-tags", + "--set-upstream", + "origin", + getBranchName(versions.at(-1)) + ); + await exec(`gh pr create --fill --title "${getMessage(versions.at(-1))}"`); + await exec("gh pr merge --auto --merge --delete-branch"); } async function git(...cmd) { diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 27d64c4..a0ab9a0 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + pull-requests: write steps: - uses: actions/checkout@v4 with: @@ -23,3 +24,4 @@ jobs: DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} GITHUB_ACTOR: github-actions[bot] GITHUB_ACTOR_ID: 41898282 + GH_TOKEN: ${{ github.token }} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..506995a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,173 @@ +{ + "name": "@biomejs/pre-commit", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@biomejs/pre-commit", + "version": "0.0.0", + "dependencies": { + "@biomejs/biome": "1.9.4" + }, + "bin": { + "biome": "node_modules/@biomejs/biome/bin/biome" + } + }, + "node_modules/@biomejs/biome": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.9.4.tgz", + "integrity": "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==", + "hasInstallScript": true, + "license": "MIT OR Apache-2.0", + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.9.4", + "@biomejs/cli-darwin-x64": "1.9.4", + "@biomejs/cli-linux-arm64": "1.9.4", + "@biomejs/cli-linux-arm64-musl": "1.9.4", + "@biomejs/cli-linux-x64": "1.9.4", + "@biomejs/cli-linux-x64-musl": "1.9.4", + "@biomejs/cli-win32-arm64": "1.9.4", + "@biomejs/cli-win32-x64": "1.9.4" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.9.4.tgz", + "integrity": "sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==", + "cpu": [ + "arm64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.9.4.tgz", + "integrity": "sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==", + "cpu": [ + "x64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.9.4.tgz", + "integrity": "sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==", + "cpu": [ + "arm64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.9.4.tgz", + "integrity": "sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==", + "cpu": [ + "arm64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.9.4.tgz", + "integrity": "sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==", + "cpu": [ + "x64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.9.4.tgz", + "integrity": "sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==", + "cpu": [ + "x64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.9.4.tgz", + "integrity": "sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==", + "cpu": [ + "arm64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.9.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.9.4.tgz", + "integrity": "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==", + "cpu": [ + "x64" + ], + "license": "MIT OR Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + } + } +} diff --git a/package.json b/package.json index cd12b07..a0f53b8 100644 --- a/package.json +++ b/package.json @@ -8,4 +8,4 @@ "dependencies": { "@biomejs/biome": "1.9.4" } -} +} \ No newline at end of file