|
35 | 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
36 | 36 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
37 | 37 | 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 | + } |
0 commit comments