-
Notifications
You must be signed in to change notification settings - Fork 3
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
Migrate to changesets #565
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
385f7be
Migrate to changesets
AaronMoat 0271c8b
Format .changeset/changelog.js
AaronMoat 2b59c37
Merge branch 'master' into changesets
AaronMoat 5918deb
We don't build
AaronMoat b3afa5e
Revert storybook step for now
AaronMoat 9e5be8d
Add back interface description
AaronMoat ab817f3
Bump to 15
AaronMoat b642ee9
Merge branch 'master' into changesets
AaronMoat 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
There are no files selected for viewing
This file contains 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,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains 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,173 @@ | ||
const { | ||
getInfo, | ||
getInfoFromPullRequest, | ||
} = require('@changesets/get-github-info'); | ||
|
||
/** | ||
* Bold the scope of the changelog entry. | ||
* | ||
* @param {string} firstLine | ||
*/ | ||
const boldScope = (firstLine) => firstLine.replace(/^([^:]+): /, '**$1:** '); | ||
|
||
/** | ||
* Adapted from `@changesets/cli`. | ||
* | ||
* {@link https://github.com/atlassian/changesets/blob/%40changesets/cli%402.17.0/packages/cli/src/changelog/index.ts} | ||
* | ||
* @type import('@changesets/types').ChangelogFunctions | ||
*/ | ||
const defaultChangelogFunctions = { | ||
getDependencyReleaseLine: async (changesets, dependenciesUpdated) => { | ||
if (dependenciesUpdated.length === 0) return ''; | ||
|
||
const changesetLinks = changesets.map( | ||
(changeset) => `- Updated dependencies [${changeset.commit}]`, | ||
); | ||
|
||
const updatedDependenciesList = dependenciesUpdated.map( | ||
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`, | ||
); | ||
|
||
return [...changesetLinks, ...updatedDependenciesList].join('\n'); | ||
}, | ||
getReleaseLine: async (changeset) => { | ||
const [firstLine, ...futureLines] = changeset.summary | ||
.split('\n') | ||
.map((l) => l.trimRight()); | ||
|
||
const formattedFirstLine = boldScope(firstLine); | ||
|
||
const suffix = changeset.commit; | ||
|
||
return `\n\n- ${formattedFirstLine}${ | ||
suffix ? ` (${suffix})` : '' | ||
}\n${futureLines.map((l) => ` ${l}`).join('\n')}`; | ||
}, | ||
}; | ||
|
||
/** | ||
* Adapted from `@changesets/changelog-github`. | ||
* | ||
* {@link https://github.com/atlassian/changesets/blob/%40changesets/changelog-github%400.4.1/packages/changelog-github/src/index.ts} | ||
* | ||
* @type import('@changesets/types').ChangelogFunctions | ||
*/ | ||
const gitHubChangelogFunctions = { | ||
getDependencyReleaseLine: async ( | ||
changesets, | ||
dependenciesUpdated, | ||
options, | ||
) => { | ||
if (!options.repo) { | ||
throw new Error( | ||
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]', | ||
); | ||
} | ||
if (dependenciesUpdated.length === 0) return ''; | ||
|
||
const changesetLink = `- Updated dependencies [${( | ||
await Promise.all( | ||
changesets.map(async (cs) => { | ||
if (cs.commit) { | ||
let { links } = await getInfo({ | ||
repo: options.repo, | ||
commit: cs.commit, | ||
}); | ||
return links.commit; | ||
} | ||
}), | ||
) | ||
) | ||
.filter((_) => _) | ||
.join(', ')}]:`; | ||
|
||
const updatedDependenciesList = dependenciesUpdated.map( | ||
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`, | ||
); | ||
|
||
return [changesetLink, ...updatedDependenciesList].join('\n'); | ||
}, | ||
getReleaseLine: async (changeset, _type, options) => { | ||
if (!options || !options.repo) { | ||
throw new Error( | ||
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]', | ||
); | ||
} | ||
|
||
/** @type number | undefined */ | ||
let prFromSummary; | ||
/** @type string | undefined */ | ||
let commitFromSummary; | ||
|
||
const replacedChangelog = changeset.summary | ||
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => { | ||
let num = Number(pr); | ||
if (!isNaN(num)) prFromSummary = num; | ||
return ''; | ||
}) | ||
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => { | ||
commitFromSummary = commit; | ||
return ''; | ||
}) | ||
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => { | ||
usersFromSummary.push(user); | ||
return ''; | ||
}) | ||
.trim(); | ||
|
||
const [firstLine, ...futureLines] = replacedChangelog | ||
.split('\n') | ||
.map((l) => l.trimRight()); | ||
|
||
const links = await (async () => { | ||
if (prFromSummary !== undefined) { | ||
let { links } = await getInfoFromPullRequest({ | ||
repo: options.repo, | ||
pull: prFromSummary, | ||
}); | ||
if (commitFromSummary) { | ||
links = { | ||
...links, | ||
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`, | ||
}; | ||
} | ||
return links; | ||
} | ||
const commitToFetchFrom = commitFromSummary || changeset.commit; | ||
if (commitToFetchFrom) { | ||
let { links } = await getInfo({ | ||
repo: options.repo, | ||
commit: commitToFetchFrom, | ||
}); | ||
return links; | ||
} | ||
return { | ||
commit: null, | ||
pull: null, | ||
user: null, | ||
}; | ||
})(); | ||
|
||
const formattedFirstLine = boldScope(firstLine); | ||
|
||
const suffix = links.pull ?? links.commit; | ||
|
||
return [ | ||
`\n- ${formattedFirstLine}${suffix ? ` (${suffix})` : ''}`, | ||
...futureLines.map((l) => ` ${l}`), | ||
].join('\n'); | ||
}, | ||
}; | ||
|
||
if (process.env.GITHUB_TOKEN) { | ||
module.exports = gitHubChangelogFunctions; | ||
} else { | ||
console.warn( | ||
`Defaulting to Git-based versioning. | ||
Enable GitHub-based versioning by setting the GITHUB_TOKEN environment variable. | ||
This requires a GitHub personal access token with the \`public_repo\` scope: https://github.com/settings/tokens/new`, | ||
); | ||
|
||
module.exports = defaultChangelogFunctions; | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["./changelog.js", { "repo": "seek-oss/scoobie" }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "master", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains 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 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,34 @@ | ||
name: Snapshot | ||
|
||
on: workflow_dispatch | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
publish: | ||
name: Publish Snapshot | ||
permissions: | ||
id-token: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }} | ||
|
||
- name: Set up Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Publish to npm | ||
uses: seek-oss/changesets-snapshot@v0 | ||
with: | ||
pre-publish: yarn build | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.SEEK_OSS_CI_NPM_TOKEN }} |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we may need to remove/change
github.actor
if we want to make this change, as the org token belongs to https://github.com/orgs/seek-oss/teams/ci.That said, can we check if we can stick to the repo-scoped GITHUB_TOKEN for the Storybook step? (I can't quite remember at this time why it's insufficient for Changesets though!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if it already works with GITHUB_TOKEN it should be fine?