Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar committed Mar 17, 2024
1 parent 432fcbd commit 366b6fb
Show file tree
Hide file tree
Showing 11 changed files with 1,928 additions and 311 deletions.
10 changes: 0 additions & 10 deletions .github/actions/check_changesets/action.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/actions/check_changesets/check_changesets.mjs

This file was deleted.

10 changes: 0 additions & 10 deletions .github/actions/check_changesets/package.json

This file was deleted.

237 changes: 0 additions & 237 deletions .github/actions/check_changesets/yarn.lock

This file was deleted.

37 changes: 37 additions & 0 deletions .github/scripts/checkChangesets.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { prHasChangeset, prHasLabel, getPr } from './pr.mjs'

async function checkChangesets() {
const hasChangesetsOkLabel = prHasLabel('changesets-ok')
if (hasChangesetsOkLabel) {
console.log('Skipping check because of the "changesets-ok" label')
return
}

if (await prHasChangeset()) {
// Empty space here and in subsequent console logs for formatting.
console.log(
[
'',
"Added a changeset",
].join('\n')
)
return
}

const pr = getPr()
console.log(
[
'',
'📝 Consider adding a changeset',
'==============================',
'',
'If this is a user-facing PR (a feature or a fix), it should probably have a changeset.',
`Run \`yarn changesets ${pr.number}\` to create a changeset for this PR.`,
"If it doesn't need one (it's a chore), you can add the 'changesets-ok' label.",
].join('\n')
)

process.exitCode = 1
}

await checkChangesets()
12 changes: 12 additions & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "redwood-ci-scripts",
"private": true,
"dependencies": {
"@actions/github": "6.0.0",
"zx": "7.2.3"
},
"packageManager": "yarn@4.1.1",
"devDependencies": {
"tsx": "^4.7.1"
}
}
31 changes: 31 additions & 0 deletions .github/scripts/pr.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { context as ghContext } from '@actions/github'
import { $ } from 'zx'
import { getLines } from './zxHelpers.mjs'

type Label = {
name: string
}

function getPrLabels(): Label[] {
return []
}

export function prHasLabel(label) {
const labels = getPrLabels()
return labels.some((l) => l.name === label)
}

async function getPrChangedFiles() {
await $`git fetch origin main`.quiet()
const changedFiles = getLines(await $`git diff origin/main --name-only`.quiet())
return changedFiles
}

export async function prHasChangeset() {
const changedFiles = await getPrChangedFiles()
return changedFiles.some((file) => file.startsWith('.changesets/'))
}

export function getPr() {
return ghContext.payload.pull_request
}
Loading

0 comments on commit 366b6fb

Please sign in to comment.