Skip to content

Commit 2baf0d0

Browse files
committed
chore: upload bundle and tarballs to releases
1 parent a1da042 commit 2baf0d0

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,53 @@ jobs:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3636
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3737
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38+
39+
- name: Bundle
40+
id: bundle
41+
if: ${{ steps.changesets.outputs.published }}
42+
uses: actions/github-script@v5
43+
with:
44+
github-token: ${{secrets.GITHUB_TOKEN}}
45+
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+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ project.conf.json
1818
## except files which we want to commit,
1919
## like demo js and config files
2020

21+
pfe.min.js
22+
2123
**/*.LEGAL.txt
2224
*.tsbuildinfo
2325
test-results

0 commit comments

Comments
 (0)