Skip to content

Commit abde7c0

Browse files
committed
WIP test new flow for changeset with gh release
1 parent caa1c92 commit abde7c0

File tree

4 files changed

+173
-132
lines changed

4 files changed

+173
-132
lines changed

.changeset/silent-weeks-tap.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@gipo355/angular-test-app': patch
3+
'@gipo355/tomcat-angular-boilerplate': patch
4+
'@gipo355/tomcat-api-boilerplate': patch
5+
'@gipo355/angular-lib': patch
6+
'@gipo355/angular-lib-publish': patch
7+
'@gipo355/jakarta-base-rest': patch
8+
'@gipo355/smispi': patch
9+
---
10+
11+
test new flow for changeset, need releases

.github/workflows/changeset-dev.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ jobs:
6363
# publish: npx nx release publish
6464
# publish: pnpm ci:publish
6565
# publish: pnpm changeset-publish
66+
#
67+
# If it has a publish command, it will create a github release when no
68+
# changesets are present
69+
publish:
70+
npx changeset tag && git push --follow-tags && npx nx release
71+
publish
72+
#
73+
#
6674
# env:
6775
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6876
# # npm token to publish nodejs libs
@@ -71,19 +79,21 @@ jobs:
7179
# ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSWORD }}
7280
# ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
7381
# ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }}
74-
# print environment info
75-
# - name: Print Environment Info step
76-
# run: npx nx report
77-
# shell: bash
78-
# publish release
79-
# example 1
80-
- name: Create tags, Publish packages
81-
if: steps.changesets.outputs.hasChangesets == 'false'
82-
run: |
83-
npx changeset tag
84-
git push --follow-tags
85-
npx nx release publish
86-
shell: bash
82+
# print environment info
83+
# - name: Print Environment Info step
84+
# run: npx nx report
85+
# shell: bash
86+
# publish release
87+
# example 1
88+
# this is a customization needed to use nx while using changesets to
89+
# create tags
90+
# - name: Create tags, Publish packages
91+
# if: steps.changesets.outputs.hasChangesets == 'false'
92+
# run: |
93+
# npx changeset tag
94+
# git push --follow-tags
95+
# npx nx release publish
96+
# shell: bash
8797
# env:
8898
# # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8999
# NPM_CONFIG_PROVENANCE: true # works only if repo is public
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// 🔨 WIP: copied from changesets action
2+
import fs from 'node:fs/promises';
3+
// import { throttling } from '@octokit/plugin-throttling';
4+
// import * as semver from 'semver';
5+
import path from 'node:path';
6+
// import { getPackages, type Package } from '@manypkg/get-packages';
7+
// import { GitHub, getOctokitOptions } from '@actions/github/lib/utils';
8+
import { Octokit } from 'octokit';
9+
10+
// this code is adapted from `@changesets/action` and `nx release` to be able to create a release
11+
// even without using `changesets publish` command
12+
//
13+
// It will create a release on GitHub with the changelog entry every package
14+
// tagged with a new version and will allow adding assets to the release.
15+
//
16+
// it must be used run in action after the build step to have the packages
17+
// built.
18+
//
19+
// e.g. .war files for java apps, .jar for java libs, angular dist .zip files
20+
//
21+
// requires GITHUB_TOKEN to be set as an environment variable to be able to create the release
22+
23+
// GitHub Issues/PRs messages have a max size limit on the
24+
// message body payload.
25+
// `body is too long (maximum is 65536 characters)`.
26+
// To avoid that, we ensure to cap the message to 60k chars.
27+
const MAX_CHARACTERS_PER_MESSAGE = 60000;
28+
29+
// const setupOctokit = (githubToken: string) => {
30+
// return new (GitHub.plugin(throttling))(
31+
// getOctokitOptions(githubToken, {
32+
// throttle: {
33+
// onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
34+
// core.warning(
35+
// `Request quota exhausted for request ${options.method} ${options.url}`,
36+
// );
37+
//
38+
// if (retryCount <= 2) {
39+
// core.info(`Retrying after ${retryAfter} seconds!`);
40+
// return true;
41+
// }
42+
// },
43+
// onSecondaryRateLimit: (
44+
// retryAfter,
45+
// options: any,
46+
// octokit,
47+
// retryCount,
48+
// ) => {
49+
// core.warning(
50+
// `SecondaryRateLimit detected for request ${options.method} ${options.url}`,
51+
// );
52+
//
53+
// if (retryCount <= 2) {
54+
// core.info(`Retrying after ${retryAfter} seconds!`);
55+
// return true;
56+
// }
57+
// },
58+
// },
59+
// }),
60+
// );
61+
// };
62+
const setupOctokit = (githubToken: string) => {
63+
return new Octokit({
64+
auth: githubToken,
65+
// throttle: {
66+
// onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
67+
// console.warn(
68+
// `Request quota exhausted for request ${options.method} ${options.url}`,
69+
// );
70+
//
71+
// if (retryCount <= 2) {
72+
// console.info(`Retrying after ${retryAfter} seconds!`);
73+
// return true;
74+
// }
75+
// },
76+
// onAbuseLimit: (retryAfter, options: any, octokit) => {
77+
// console.warn(
78+
// `Abuse detected for request ${options.method} ${options.url}`,
79+
// );
80+
// },
81+
// },
82+
});
83+
};
84+
85+
const createRelease = async (
86+
octokit: ReturnType<typeof setupOctokit>,
87+
{ pkg, tagName }: { pkg: Package; tagName: string },
88+
) => {
89+
try {
90+
const changelogFileName = path.join(pkg.dir, 'CHANGELOG.md');
91+
92+
const changelog = await fs.readFile(changelogFileName, 'utf8');
93+
94+
const changelogEntry = getChangelogEntry(
95+
changelog,
96+
pkg.packageJson.version,
97+
);
98+
if (!changelogEntry) {
99+
// we can find a changelog but not the entry for this version
100+
// if this is true, something has probably gone wrong
101+
throw new Error(
102+
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`,
103+
);
104+
}
105+
106+
await octokit.rest.repos.createRelease({
107+
name: tagName,
108+
tag_name: tagName,
109+
body: changelogEntry.content,
110+
prerelease: pkg.packageJson.version.includes('-'),
111+
...github.context.repo,
112+
});
113+
} catch (err) {
114+
// if we can't find a changelog, the user has probably disabled changelogs
115+
if (
116+
err &&
117+
typeof err === 'object' &&
118+
'code' in err &&
119+
err.code !== 'ENOENT'
120+
) {
121+
throw err;
122+
}
123+
}
124+
};
Lines changed: 15 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,20 @@
1-
// 🔨 WIP: copied from changesets action
2-
import fs from 'node:fs/promises';
3-
// import { throttling } from '@octokit/plugin-throttling';
4-
// import * as semver from 'semver';
5-
import path from 'node:path';
6-
// import { getPackages, type Package } from '@manypkg/get-packages';
7-
// import { GitHub, getOctokitOptions } from '@actions/github/lib/utils';
8-
import { Octokit } from 'octokit';
9-
10-
// this code is adapted from `@changesets/action` and `nx release` to be able to create a release
11-
// even without using `changesets publish` command
12-
//
13-
// It will create a release on GitHub with the changelog entry every package
14-
// tagged with a new version and will allow adding assets to the release.
15-
//
16-
// it must be used run in action after the build step to have the packages
17-
// built.
18-
//
19-
// e.g. .war files for java apps, .jar for java libs, angular dist .zip files
1+
// steps
202
//
21-
// requires GITHUB_TOKEN to be set as an environment variable to be able to create the release
22-
23-
// GitHub Issues/PRs messages have a max size limit on the
24-
// message body payload.
25-
// `body is too long (maximum is 65536 characters)`.
26-
// To avoid that, we ensure to cap the message to 60k chars.
27-
const MAX_CHARACTERS_PER_MESSAGE = 60000;
28-
29-
// const setupOctokit = (githubToken: string) => {
30-
// return new (GitHub.plugin(throttling))(
31-
// getOctokitOptions(githubToken, {
32-
// throttle: {
33-
// onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
34-
// core.warning(
35-
// `Request quota exhausted for request ${options.method} ${options.url}`,
36-
// );
3+
// setup octokit
374
//
38-
// if (retryCount <= 2) {
39-
// core.info(`Retrying after ${retryAfter} seconds!`);
40-
// return true;
41-
// }
42-
// },
43-
// onSecondaryRateLimit: (
44-
// retryAfter,
45-
// options: any,
46-
// octokit,
47-
// retryCount,
48-
// ) => {
49-
// core.warning(
50-
// `SecondaryRateLimit detected for request ${options.method} ${options.url}`,
51-
// );
52-
//
53-
// if (retryCount <= 2) {
54-
// core.info(`Retrying after ${retryAfter} seconds!`);
55-
// return true;
56-
// }
57-
// },
58-
// },
59-
// }),
60-
// );
61-
// };
62-
const setupOctokit = (githubToken: string) => {
63-
return new Octokit({
64-
auth: githubToken,
65-
// throttle: {
66-
// onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
67-
// console.warn(
68-
// `Request quota exhausted for request ${options.method} ${options.url}`,
69-
// );
70-
//
71-
// if (retryCount <= 2) {
72-
// console.info(`Retrying after ${retryAfter} seconds!`);
73-
// return true;
74-
// }
75-
// },
76-
// onAbuseLimit: (retryAfter, options: any, octokit) => {
77-
// console.warn(
78-
// `Abuse detected for request ${options.method} ${options.url}`,
79-
// );
80-
// },
81-
// },
82-
});
83-
};
84-
85-
const createRelease = async (
86-
octokit: ReturnType<typeof setupOctokit>,
87-
{ pkg, tagName }: { pkg: Package; tagName: string },
88-
) => {
89-
try {
90-
const changelogFileName = path.join(pkg.dir, 'CHANGELOG.md');
5+
// changesets raises versions and changelog
6+
// i need a list of bumped packages
7+
// for each bumped package, i need to create a github release
8+
// with the changelog, name, version for tag
919

92-
const changelog = await fs.readFile(changelogFileName, 'utf8');
10+
// const setupOctokit = async () => {}
9311

94-
const changelogEntry = getChangelogEntry(
95-
changelog,
96-
pkg.packageJson.version,
97-
);
98-
if (!changelogEntry) {
99-
// we can find a changelog but not the entry for this version
100-
// if this is true, something has probably gone wrong
101-
throw new Error(
102-
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`,
103-
);
104-
}
12+
// const createRelease = async (
13+
// octokit: ReturnType<typeof setupOctokit>,
14+
// { pkg, tagName }: { pkg: Package; tagName: string }
15+
// ) => {
16+
// read changelog
17+
// parse changelog
18+
// create release
19+
// }
10520

106-
await octokit.rest.repos.createRelease({
107-
name: tagName,
108-
tag_name: tagName,
109-
body: changelogEntry.content,
110-
prerelease: pkg.packageJson.version.includes('-'),
111-
...github.context.repo,
112-
});
113-
} catch (err) {
114-
// if we can't find a changelog, the user has probably disabled changelogs
115-
if (
116-
err &&
117-
typeof err === 'object' &&
118-
'code' in err &&
119-
err.code !== 'ENOENT'
120-
) {
121-
throw err;
122-
}
123-
}
124-
};

0 commit comments

Comments
 (0)