Skip to content

Commit

Permalink
chore(tooling): migrate from ESLint/Prettier to Biome (#164)
Browse files Browse the repository at this point in the history
* install biome - remove eslint and prettier

* yarn fix

* ANSI code stripping

* .editorconfig now cjs with tab width=2
  • Loading branch information
gluneau authored Jan 21, 2025
1 parent b2ffc4f commit 8ca080c
Show file tree
Hide file tree
Showing 51 changed files with 604 additions and 1,424 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = true
[*]
indent_style=tab
indent_size=tab
indent_size=2
tab_width=2
end_of_line=lf
charset=utf-8
Expand All @@ -15,6 +15,6 @@ indent_size=2
tab_width=8
end_of_line=lf

[*.{js,ts}]
[*.{js,ts,cjs}]
indent_style=space
tab_width=2
8 changes: 4 additions & 4 deletions .github/command-runner/comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = class Comment {
constructor({ github, context, commentId }) {
this.github = github
this.context = context
this.commentId = commentId || null;
this.commentId = commentId || null
}

async createOrUpdateComment(body) {
Expand All @@ -12,7 +12,7 @@ module.exports = class Comment {
issue_number: this.context.issue.number,
owner: this.context.repo.owner,
repo: this.context.repo.repo,
body: `${body}` + `\n[view details](${actionUrl})`
body: `${body}` + `\n[view details](${actionUrl})`,
})
this.commentId = result.data.id
}
Expand All @@ -21,7 +21,7 @@ module.exports = class Comment {
issue_number: this.context.issue.number,
owner: this.context.repo.owner,
repo: this.context.repo.repo,
body: `${body}` + `\n[view details](${actionUrl})`
body: `${body}` + `\n[view details](${actionUrl})`,
})
}
}
}
84 changes: 48 additions & 36 deletions .github/command-runner/merge.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ module.exports = async ({ github, context, command, core, commentId }) => {
if (command === 'merge') {
console.log('Run merge')

const { repository } = await github.graphql(`
const { repository } = await github.graphql(
`
query($owner: String!, $repo: String!, $pullNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pullNumber) {
id
}
}
}
`, {
...context.repo,
pullNumber: context.issue.number,
})
`,
{
...context.repo,
pullNumber: context.issue.number,
},
)

const pullRequestId = repository.pullRequest.id
const pullRequestId = repository.pullRequest.id

await github.graphql(`
await github.graphql(
`
mutation($pullRequestId: ID!) {
enablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId, mergeMethod: SQUASH }) {
pullRequest {
Expand All @@ -30,21 +34,23 @@ module.exports = async ({ github, context, command, core, commentId }) => {
}
}
}
`, {
pullRequestId: pullRequestId
})
`,
{
pullRequestId: pullRequestId,
},
)

let pendingReview = await github.rest.pulls.createReview({
...context.repo,
pull_number: context.issue.number,
})
const pendingReview = await github.rest.pulls.createReview({
...context.repo,
pull_number: context.issue.number,
})

await github.rest.pulls.submitReview({
...context.repo,
pull_number: context.issue.number,
event: 'APPROVE',
review_id: pendingReview.data.id
})
await github.rest.pulls.submitReview({
...context.repo,
pull_number: context.issue.number,
event: 'APPROVE',
review_id: pendingReview.data.id,
})

await comment.createOrUpdateComment(` Auto-merge enabled`)
core.info('Auto-merge enabled')
Expand All @@ -53,29 +59,33 @@ module.exports = async ({ github, context, command, core, commentId }) => {

if (command === 'cancel-merge') {
console.log('Run cancel-merge')
await github.rest.pulls.submitReview({
...context.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body: 'Dismissed'
})
await github.rest.pulls.submitReview({
...context.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body: 'Dismissed',
})

const { repository } = await github.graphql(`
const { repository } = await github.graphql(
`
query($owner: String!, $repo: String!, $pullNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pullNumber) {
id
}
}
}
`, {
...context.repo,
pullNumber: context.issue.number,
})
`,
{
...context.repo,
pullNumber: context.issue.number,
},
)

const pullRequestId = repository.pullRequest.id
const pullRequestId = repository.pullRequest.id

await github.graphql(`
await github.graphql(
`
mutation($pullRequestId: ID!) {
disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
pullRequest {
Expand All @@ -84,9 +94,11 @@ module.exports = async ({ github, context, command, core, commentId }) => {
}
}
}
`, {
pullRequestId: pullRequestId
})
`,
{
pullRequestId: pullRequestId,
},
)
await comment.createOrUpdateComment(` Auto-merge disabled`)

core.info('Auto-merge disabled')
Expand Down
9 changes: 4 additions & 5 deletions .github/command-runner/postBump.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = async ({ github, context, exec, commentId, core, testResult })
const Comment = require('./comment.cjs')
const comment = new Comment({ github, context, commentId })

if(testResult !== 'success') {
if (testResult !== 'success') {
return comment.createOrUpdateComment(` Test failed`)
}

Expand All @@ -23,11 +23,10 @@ module.exports = async ({ github, context, exec, commentId, core, testResult })
await exec.exec('git', ['rev-parse', 'HEAD'], {
listeners: {
stdout: (data) => {
commitId += data.toString();
}
}
commitId += data.toString()
},
},
})

return comment.createOrUpdateComment(`**KNOWN_GOOD_BLOCK_NUMBERS.env has been updated**<br/>**Commit**: ${commitId}`)
}

131 changes: 69 additions & 62 deletions .github/command-runner/runOrBump.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,73 @@ module.exports = async ({ github, core, context, commentId, exec, env, command,

if (result.exitCode) {
core.setFailed('Failed to update known good blocks')
await comment.createOrUpdateComment(createResult({
context,
command: execCommand,
result: result.errorOutput + '\n' + result.output,
extra: `**Test Result**: \`Failed to update known good blocks\``
}))
await comment.createOrUpdateComment(
createResult({
context,
command: execCommand,
result: `${result.errorOutput}\n${result.output}`,
extra: `**Test Result**: \`Failed to update known good blocks\``,
}),
)

process.exit(1)
}


return result
}

const excuteTest = async ({ update, env }) => {
const execCommand = update ?
`yarn test --reporter default ${update ? '-u' : ''}` :
`yarn test --reporter default ${args.trim()}`
const execCommand = update
? `yarn test --reporter default ${update ? '-u' : ''}`
: `yarn test --reporter default ${args.trim()}`

const result = await runCommand({ cmd: execCommand, comment, exec })

if (result.exitCode) {
core.setFailed('Tests failed')
await comment.createOrUpdateComment(createResult({
context,
command: execCommand,
result: (env ? `${env}\n` : '') + (result.errorOutput + '\n' + result.output),
extra: `**Test Result**: \`Failed\``
}))
await comment.createOrUpdateComment(
createResult({
context,
command: execCommand,
result: `${env ? `${env}\n` : ''}${result.errorOutput}\n${result.output}`,
extra: `**Test Result**: \`Failed\``,
}),
)
process.exit(1)
}

return result
}

if (command === 'run') {
const updateKnownGoodResult = await excuteUpdateKnownGood();
const updateKnownGoodResult = await excuteUpdateKnownGood()

let newEnv = updateKnownGoodResult.output

if (env) {
newEnv = writeNewEnv({ env })
}

const testResult = await excuteTest({ update: false, env: newEnv });
const testResult = await excuteTest({ update: false, env: newEnv })
core.info('Tests Passed')
const output = newEnv + `\n${testResult.output}`
return comment.createOrUpdateComment(createResult({
context,
command: testResult.cmd,
result: output,
extra: `**Test Result**: \`Passed\``
}))
const output = `${newEnv}\n${testResult.output}`
return comment.createOrUpdateComment(
createResult({
context,
command: testResult.cmd,
result: output,
extra: `**Test Result**: \`Passed\``,
}),
)
}

if (command === 'bump') {
if (env.trim().length) {
core.setFailed('env is not supported in bump command')
return comment.createOrUpdateComment(` ENV is not supported in bump command`)
}
if (env.trim().length) {
core.setFailed('env is not supported in bump command')
return comment.createOrUpdateComment(` ENV is not supported in bump command`)
}

const updateKnownGoodResult = await excuteUpdateKnownGood();
const updateKnownGoodResult = await excuteUpdateKnownGood()

await exec.exec(`git config --global user.name 'github-actions[bot]'`)
await exec.exec(`git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'`)
Expand All @@ -83,50 +88,52 @@ module.exports = async ({ github, core, context, commentId, exec, env, command,
process.exit(1)
}

const testResult = await excuteTest({ update: true, env: updateKnownGoodResult.output });
const output = updateKnownGoodResult.output + `\n${testResult.output}`
const testResult = await excuteTest({ update: true, env: updateKnownGoodResult.output })
const output = `${updateKnownGoodResult.output}\n${testResult.output}`

const diffResult = await exec.exec('git diff --exit-code', null, { ignoreReturnCode: true })

if (!diffResult) {
core.info('snapshot not updated')
// dispatch update-known-good workflow to having it to update the snapshot
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'update-known-good.yml',
ref: 'master',
})

return comment.createOrUpdateComment(createResult({
context,
command: testResult.cmd,
result: output,
extra: `<br/>Triggered update-known-good workflow to update the snapshot`
}))
} else {
const branchName = `Update-SnapShot-${commentId}`
await exec.exec(`git checkout -b ${branchName}`)
await exec.exec(`git`, ['commit', '-am', '[ci skip] Update snapshots'])


const commentUrl = `/~https://github.com/${context.payload.repository.full_name}/issues/${context.issue.number}#issuecomment-${commentId}`
await exec.exec(`git push origin HEAD:${branchName}`)
const result = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: branchName,
head: branchName,
base: 'master',
body: `Update Snapshots (${commentUrl})`,
workflow_id: 'update-known-good.yml',
ref: 'master',
})
core.info(`The Pull request #${result.data.number} has been created to update the snapshot`)
return comment.createOrUpdateComment(createResult({

return comment.createOrUpdateComment(
createResult({
context,
command: testResult.cmd,
result: output,
extra: `<br/>Triggered update-known-good workflow to update the snapshot`,
}),
)
}
const branchName = `Update-SnapShot-${commentId}`
await exec.exec(`git checkout -b ${branchName}`)
await exec.exec(`git`, ['commit', '-am', '[ci skip] Update snapshots'])

const commentUrl = `/~https://github.com/${context.payload.repository.full_name}/issues/${context.issue.number}#issuecomment-${commentId}`
await exec.exec(`git push origin HEAD:${branchName}`)
const result = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: branchName,
head: branchName,
base: 'master',
body: `Update Snapshots (${commentUrl})`,
})
core.info(`The Pull request #${result.data.number} has been created to update the snapshot`)
return comment.createOrUpdateComment(
createResult({
context,
command: testResult.cmd,
result: output,
extra: `<br/>**The Pull request #${result.data.number} has been created to update the snapshot**`
}))
}
extra: `<br/>**The Pull request #${result.data.number} has been created to update the snapshot**`,
}),
)
}
}
Loading

0 comments on commit 8ca080c

Please sign in to comment.