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

chore(release): try changesets instead of changelog #10138

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 0 additions & 10 deletions .github/actions/check_changelog/action.yml

This file was deleted.

68 changes: 0 additions & 68 deletions .github/actions/check_changelog/check_changelog.mjs

This file was deleted.

10 changes: 10 additions & 0 deletions .github/actions/check_changesets/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Check changesets
description: Checks if changeset was added to the PR

runs:
using: node20
main: check_changesets.mjs

inputs:
labels:
required: true
47 changes: 47 additions & 0 deletions .github/actions/check_changesets/check_changesets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getInput } from '@actions/core'
import { exec, getExecOutput } from '@actions/exec'
import github from '@actions/github'

async function main() {
// If the PR has the "changesets-ok" label, just pass.
const { labels } = JSON.parse(getInput('labels'))
const hasChangesetsOkLabel = labels.some((label) => label.name === 'changesets-ok')
if (hasChangesetsOkLabel) {
console.log('Skipping check because of the "changesets-ok" label')
return
}

// Check if the PR adds a changeset.
await exec('git fetch origin main', [], { silent: true })
const { stdout } = await getExecOutput('git diff origin/main --name-only', [], { silent: true })
const changedFiles = stdout.toString().trim().split('\n').filter(Boolean)
const addedChangeset = changedFiles.some((file) => file.startsWith('.changesets/'))
if (addedChangeset) {
// Empty space here (and in subsequent `console.log`s) for formatting in the action.
console.log(
[
'',
"Added a changeset",
].join('\n')
)

return
}

const pr = github.context.payload.pull_request
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
}

main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "check_changelog",
"name": "check_changesets",
"private": true,
"dependencies": {
"@actions/core": "1.10.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ __metadata:
languageName: node
linkType: hard

"check_changelog@workspace:.":
"check_changesets@workspace:.":
version: 0.0.0-use.local
resolution: "check_changelog@workspace:."
resolution: "check_changesets@workspace:."
dependencies:
"@actions/core": "npm:1.10.1"
"@actions/exec": "npm:1.1.1"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 📝 Check CHANGELOG.md
name: 📝 Check changesets

on:
pull_request:
Expand All @@ -11,8 +11,8 @@ concurrency:
cancel-in-progress: true

jobs:
check-changelog:
name: 📝 Check CHANGELOG.md
check-changesets:
name: 📝 Check changesets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -25,9 +25,9 @@ jobs:
node-version: 20

- run: yarn install
working-directory: ./.github/actions/check_changelog
working-directory: ./.github/actions/check_changesets

- name: Check CHANGELOG.md
uses: ./.github/actions/check_changelog
- name: Check changesets
uses: ./.github/actions/check_changesets
with:
labels: '{ "labels": ${{ toJSON(github.event.pull_request.labels) }} }'
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build:pack": "nx run-many -t build:pack",
"build:test-project": "node ./tasks/test-project/test-project",
"build:watch": "lerna run build:watch --parallel; tsc --build",
"changesets": "tsx ./tasks/changesets/changesets.mts",
"check": "node ./tasks/check/check.mjs",
"clean:prisma": "rimraf node_modules/.prisma/client && node node_modules/@prisma/client/scripts/postinstall.js",
"e2e": "node ./tasks/run-e2e",
Expand Down Expand Up @@ -89,6 +90,7 @@
"execa": "5.1.1",
"fast-glob": "3.3.2",
"fs-extra": "11.2.0",
"human-id": "^4.1.1",
"jest": "29.7.0",
"jscodeshift": "0.15.0",
"lerna": "8.0.2",
Expand Down
50 changes: 50 additions & 0 deletions tasks/changesets/changesets.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { chalk, fs } from 'zx'

import {
getChangesetFilePath,
getPlaceholder,
resolveArgv,
shouldShowHelp,
showHelp,
} from './changesetsHelpers.mjs'

async function main() {
if (shouldShowHelp()) {
showHelp()
return
}

const { prNumber } = resolveArgv()

const changesetFilePath = getChangesetFilePath(prNumber)
const placeholder = await getPlaceholder(prNumber)
await fs.outputFile(changesetFilePath, placeholder)
console.log(
[
`📝 Created a changeset at ${chalk.magenta(changesetFilePath)}`,
" Commit it when you're done and push your branch up to GitHub. Thank you! 🙏",
].join('\n')
)
}

try {
await main()
} catch (error) {
console.error(`${error.message}\n`)
showHelp()
process.exitCode = 1
}

// Test suite
//
// - should be the placeholder at ./placeholder.md
// - yarn changesets
//
// - should be the title and body of PR 10075
// - yarn changesets 10075
// - yarn changesets '#10075'
//
// - should throw and show help
// - yarn changesets abcd
// - yarn changesets 10075000
// - yarn changesets https://github.com/redwoodjs/redwood/pull/10075
Loading
Loading