Skip to content

Commit 0e28f9a

Browse files
committed
chore: update release bundle workflow
1 parent cbf0c49 commit 0e28f9a

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,5 @@ jobs:
4343
with:
4444
github-token: ${{secrets.GITHUB_TOKEN}}
4545
script: |
46-
const { URL, fileURLToPath } = require('url');
47-
const { readFile } = require('fs').promises;
48-
const { pfeBuild } = await import('${{ github.workspace }}/tools/pfe-tools/esbuild.js');
49-
const { execaCommand } = await import('execa');
50-
51-
// https://github.com/patternfly/patternfly-elements
52-
const owner = 'patternfly';
53-
const repo = 'patternfly-elements';
54-
55-
// repo root
56-
const cwd = '${{ github.workspace }}';
57-
const outfile = `${cwd}/pfe.min.js`;
58-
const mode = 'production';
59-
60-
const result = await pfeBuild({ cwd, mode, outfile });
61-
62-
// list of published packages from changesets
63-
const publishedPackages = JSON.parse('${{ steps.changesets.outputs.publishedPackages }}');
64-
65-
for (const { name: packageName, version } of publishedPackages) {
66-
// get the tag for the release for this package
67-
const tag = `${packageName}@${version}`;
68-
const { id } = await github.rest.repos.getReleaseByTag({ owner, repo, tag });
69-
70-
// make a tarball for the package
71-
// this was already published to npm in the changesets action
72-
const { stdout } = await execaCommand(`npm run pack -w ${name}`);
73-
const [name] = stdout.match(/^[\w-\.]+\.tgz$/g);
74-
75-
const params = { name, owner, release_id: id, repo };
76-
77-
// upload the bundle to each release
78-
await github.rest.repos.uploadReleaseAsset({ ...params, data: await readFile(outfile) });
79-
80-
// upload the package tarball to the release
81-
if (name) {
82-
await github.rest.repos.uploadReleaseAsset({
83-
...params,
84-
data: await readFile(`${cwd}/${name}`)
85-
});
86-
}
87-
}
46+
const bundle = require('./scripts/bundle-release.cjs');
47+
await bundle({ github, workspace: '${{ github.workspace }}' });

scripts/bundle-release.cjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = async function({ github, workspace }) {
2+
const { readFile } = require('fs').promises;
3+
const { pfeBuild } = await import(`${workspace}/tools/pfe-tools/esbuild.js`);
4+
const { execaCommand } = await import('execa');
5+
6+
// https://github.com/patternfly/patternfly-elements
7+
const owner = 'patternfly';
8+
const repo = 'patternfly-elements';
9+
10+
// repo root
11+
const cwd = `${workspace}`;
12+
const outfile = `${cwd}/pfe.min.js`;
13+
const mode = 'production';
14+
15+
await pfeBuild({ cwd, mode, outfile });
16+
17+
// list of published packages from changesets
18+
const publishedPackages = JSON.parse('${{ steps.changesets.outputs.publishedPackages }}');
19+
20+
for (const { name: packageName, version } of publishedPackages) {
21+
// get the tag for the release for this package
22+
const tag = `${packageName}@${version}`;
23+
const { id } = await github.rest.repos.getReleaseByTag({ owner, repo, tag });
24+
25+
// make a tarball for the package
26+
// this was already published to npm in the changesets action
27+
const { stdout } = await execaCommand(`npm run pack -w ${name}`);
28+
const [name] = stdout.match(/^[\w-.]+\.tgz$/g);
29+
30+
const params = { name, owner, release_id: id, repo };
31+
32+
// upload the bundle to each release
33+
await github.rest.repos.uploadReleaseAsset({ ...params, data: await readFile(outfile) });
34+
35+
// upload the package tarball to the release
36+
if (name) {
37+
await github.rest.repos.uploadReleaseAsset({
38+
...params,
39+
data: await readFile(`${cwd}/${name}`)
40+
});
41+
}
42+
}
43+
};

0 commit comments

Comments
 (0)