Skip to content

Commit cf9bfcf

Browse files
authored
Try to wire up Changesets (#7)
1 parent 6e250a7 commit cf9bfcf

File tree

15 files changed

+989
-1
lines changed

15 files changed

+989
-1
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/changelog.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
const {
2+
getInfo,
3+
getInfoFromPullRequest,
4+
} = require('@changesets/get-github-info');
5+
6+
/**
7+
* Bold the scope of the changelog entry.
8+
*
9+
* @param {string} firstLine
10+
*/
11+
const boldScope = (firstLine) => firstLine.replace(/^([^:]+): /, '**$1:** ');
12+
13+
/**
14+
* Adapted from `@changesets/cli`.
15+
*
16+
* {@link https://github.com/atlassian/changesets/blob/%40changesets/cli%402.17.0/packages/cli/src/changelog/index.ts}
17+
*
18+
* @type import('@changesets/types').ChangelogFunctions
19+
*/
20+
const defaultChangelogFunctions = {
21+
getDependencyReleaseLine: async (changesets, dependenciesUpdated) => {
22+
if (dependenciesUpdated.length === 0) return '';
23+
24+
const changesetLinks = changesets.map(
25+
(changeset) => `- Updated dependencies [${changeset.commit}]`,
26+
);
27+
28+
const updatedDependenciesList = dependenciesUpdated.map(
29+
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
30+
);
31+
32+
return [...changesetLinks, ...updatedDependenciesList].join('\n');
33+
},
34+
getReleaseLine: async (changeset) => {
35+
const [firstLine, ...futureLines] = changeset.summary
36+
.split('\n')
37+
.map((l) => l.trimRight());
38+
39+
const formattedFirstLine = boldScope(firstLine);
40+
41+
const suffix = changeset.commit;
42+
43+
return `\n\n- ${formattedFirstLine}${
44+
suffix ? ` (${suffix})` : ''
45+
}\n${futureLines.map((l) => ` ${l}`).join('\n')}`;
46+
},
47+
};
48+
49+
/**
50+
* Adapted from `@changesets/changelog-github`.
51+
*
52+
* {@link https://github.com/atlassian/changesets/blob/%40changesets/changelog-github%400.4.1/packages/changelog-github/src/index.ts}
53+
*
54+
* @type import('@changesets/types').ChangelogFunctions
55+
*/
56+
const gitHubChangelogFunctions = {
57+
getDependencyReleaseLine: async (
58+
changesets,
59+
dependenciesUpdated,
60+
options,
61+
) => {
62+
if (!options.repo) {
63+
throw new Error(
64+
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
65+
);
66+
}
67+
if (dependenciesUpdated.length === 0) return '';
68+
69+
const changesetLink = `- Updated dependencies [${(
70+
await Promise.all(
71+
changesets.map(async (cs) => {
72+
if (cs.commit) {
73+
let { links } = await getInfo({
74+
repo: options.repo,
75+
commit: cs.commit,
76+
});
77+
return links.commit;
78+
}
79+
}),
80+
)
81+
)
82+
.filter((_) => _)
83+
.join(', ')}]:`;
84+
85+
const updatedDependenciesList = dependenciesUpdated.map(
86+
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
87+
);
88+
89+
return [changesetLink, ...updatedDependenciesList].join('\n');
90+
},
91+
getReleaseLine: async (changeset, _type, options) => {
92+
if (!options || !options.repo) {
93+
throw new Error(
94+
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
95+
);
96+
}
97+
98+
/** @type number | undefined */
99+
let prFromSummary;
100+
/** @type string | undefined */
101+
let commitFromSummary;
102+
103+
const replacedChangelog = changeset.summary
104+
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
105+
let num = Number(pr);
106+
if (!isNaN(num)) prFromSummary = num;
107+
return '';
108+
})
109+
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
110+
commitFromSummary = commit;
111+
return '';
112+
})
113+
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
114+
usersFromSummary.push(user);
115+
return '';
116+
})
117+
.trim();
118+
119+
const [firstLine, ...futureLines] = replacedChangelog
120+
.split('\n')
121+
.map((l) => l.trimRight());
122+
123+
const links = await (async () => {
124+
if (prFromSummary !== undefined) {
125+
let { links } = await getInfoFromPullRequest({
126+
repo: options.repo,
127+
pull: prFromSummary,
128+
});
129+
if (commitFromSummary) {
130+
links = {
131+
...links,
132+
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
133+
};
134+
}
135+
return links;
136+
}
137+
const commitToFetchFrom = commitFromSummary || changeset.commit;
138+
if (commitToFetchFrom) {
139+
let { links } = await getInfo({
140+
repo: options.repo,
141+
commit: commitToFetchFrom,
142+
});
143+
return links;
144+
}
145+
return {
146+
commit: null,
147+
pull: null,
148+
user: null,
149+
};
150+
})();
151+
152+
const formattedFirstLine = boldScope(firstLine);
153+
154+
const suffix = links.pull ?? links.commit;
155+
156+
return [
157+
`\n- ${formattedFirstLine}${suffix ? ` (${suffix})` : ''}`,
158+
...futureLines.map((l) => ` ${l}`),
159+
].join('\n');
160+
},
161+
};
162+
163+
if (process.env.GITHUB_TOKEN) {
164+
module.exports = gitHubChangelogFunctions;
165+
} else {
166+
console.warn(
167+
`Defaulting to Git-based versioning.
168+
Enable GitHub-based versioning by setting the GITHUB_TOKEN environment variable.
169+
This requires a GitHub personal access token with the \`public_repo\` scope: https://github.com/settings/tokens/new`,
170+
);
171+
172+
module.exports = defaultChangelogFunctions;
173+
}

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": ["./changelog.js", { "repo": "seek-oss/aws-codedeploy-hooks" }],
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/silent-dolphins-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-hooks': major
3+
---
4+
5+
isHttpHook: Add function

.changeset/wise-phones-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-hooks': major
3+
---
4+
5+
isLambdaHook: Add function

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ node_modules*/
1212
/lib*/
1313
/tmp*/
1414
# end managed by skuba
15+
16+
/packages/**/lib*/

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions: {}
9+
10+
jobs:
11+
release:
12+
name: Publish
13+
permissions:
14+
id-token: write
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out repo
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
token: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }}
22+
23+
- name: Set up Node.js 20.x
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20.x
27+
28+
- uses: pnpm/action-setup@v2
29+
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Publish to npm
34+
uses: changesets/action@v1
35+
with:
36+
publish: pnpm run release
37+
version: pnpm run stage
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }}
40+
NPM_TOKEN: ${{ secrets.SEEK_OSS_CI_NPM_TOKEN }}

.github/workflows/snapshot.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Snapshot
2+
3+
on: workflow_dispatch
4+
5+
permissions: {}
6+
7+
jobs:
8+
publish:
9+
name: Publish Snapshot
10+
permissions:
11+
id-token: write
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
token: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }}
19+
20+
- name: Set up Node.js 20.x
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20.x
24+
25+
- uses: pnpm/action-setup@v2
26+
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
30+
- name: Publish to npm
31+
uses: seek-oss/changesets-snapshot@v0
32+
with:
33+
pre-publish: pnpm run build
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.SEEK_OSS_CI_GITHUB_TOKEN }}
36+
NPM_TOKEN: ${{ secrets.SEEK_OSS_CI_NPM_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ package-lock.json
2222
yarn-error.log
2323
# end managed by skuba
2424

25+
/packages/**/lib*/
26+
2527
!.npmrc

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11
# AWS CodeDeploy Hooks
2+
3+
[AWS CodeDeploy] is a deployment mechanism for ECS services, Lambda functions, and more.
4+
5+
The service includes a feature called [lifecycle event hooks],
6+
which lets you invoke user-defined code to perform checks at different phases of the deployment.
7+
For example, you could check that the new version of your application is responding successfully on its health check endpoint before allowing traffic to shift in a [blue-green deployment].
8+
9+
This repository houses TypeScript packages that help you integrate CodeDeploy hooks into your deployments:
10+
11+
- [@seek/aws-codedeploy-hooks](packages/hooks)
12+
13+
Runtime helpers to identify requests originating from a hook.
14+
This enables you to customise application logic accordingly.
15+
16+
- [@seek/aws-codedeploy-infra](packages/infra)
17+
18+
CDK helpers to deploy lifecycle event hooks and configure CodeDeploy for your Lambda functions.
19+
20+
[AWS CodeDeploy]: https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html
21+
[blue-green deployment]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html
22+
[lifecycle event hooks]: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html

0 commit comments

Comments
 (0)