|
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 |
20 | 2 | // |
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 |
37 | 4 | // |
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 |
91 | 9 |
|
92 | | - const changelog = await fs.readFile(changelogFileName, 'utf8'); |
| 10 | +// const setupOctokit = async () => {} |
93 | 11 |
|
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 | +// } |
105 | 20 |
|
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