Skip to content

Custom release assets #155

Open

Description

@bennypowers

I'd like to bundle my monorepo into a single file whenever I release and upload that as a release asset

I can do that with github actions and the github rest api, but I'd rather have changesets do that in the changesets action. It would be nice to have a hook to run my own custom build process for releases

Activity

  1. Andarist commented on Mar 2, 2022

    @Andarist
    Member

    I'd like to bundle my monorepo into a single file

    Could you describe this in more detail? I'd like to understand the context behind the feature request better.

    It would be nice to have a hook to run my own custom build process for releases

    Could you roughly describe how this would work? Additional question - can assets be attached after the release is already published?

  2. bennypowers commented on Mar 2, 2022

    @bennypowers
    Author

    Thank you @Andarist for the reply. Allow me to elaborate:

    I am participating in the development of a design system, implemented in an npm monorepo of ~20 web components. Under normal circumstances, users would load whichever components they needed via a module transforming CDN (e.g. unpkg) or with import maps (e.g. jspm), or by npm installing and bundling themselves.

    However, many of our users do not want to have to install a node/npm toolchain in order to fetch and bundle our components, and they are prevented by compliance concerns from using third party CDNs like unpkg or jspm

    Therefore, we'd like to provide a complete single-file bundle of our design system so that users can download a single javascript file and use it however they like.


    Now, from what I gather, I can set up a workflow which bundles the monorepo and uploads it as an asset to an existing release

    name: Bundle
    
    on: 
      release: 
        types:
          - published
    
    jobs:
      bundle:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - uses: actions/setup-node@v2
            with:
              node-version: 16
              cache: npm
    
          - run: npm i --prefer-offline
          - run: npm run build
          # outputs to /releases/$GITHUB_REF/bundle.min.js
          - run: node scripts/bundle-release.js 
          - uses: actions/github-script@v6
            with:
              script: |
                // yadda yadda
                github.rest.repos.uploadReleaseAsset({
                  owner,
                  repo,
                  release_id,
                  name,
                  data,
                });

    I think the downside to this would be the delay in between creating the release and uploading the asset

    Instead, perhaps there could be some assets param to changesets action which looks for assets in a newline-separated string of filenames and attaches them if present

    name: Release
    
    on:
      push:
        branches:
          - main
          - master
    
    jobs:
      release:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - uses: actions/setup-node@v2
            with:
              node-version: 16
              cache: npm
    
          - run: npm i --prefer-offline
          - run: npm run build
    
          - name: Create Release Pull Request or Publish to npm
            uses: changesets/action@v1
            with:
              publish: npx changeset publish
              commit: "chore: version packages"
              # files are uploaded as-is,
              # directories get tarballed then uploaded
              # changesets action could also automatically upload the npm package tarballs
              assets: |
                /releases/${{ env.GITHUB_REF }}/bundle.min.js
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
              NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  3. bennypowers commented on Mar 3, 2022

    @bennypowers
    Author

    An important point I missed in yesterday's comment: the config I proposed there (assets key) would not work as shown, since the build process would need to know about the release's metadata via the env

  4. bennypowers commented on Sep 2, 2022

    @bennypowers
    Author

    Alternatively, if changesets/action would provide the release ID as an output, users could easily modify the release after publish:

          - name: Create Release Pull Request or Publish to npm
            uses: changesets/action@v1
            id: changesets-release
            with:
              publish: npx changeset publish
              commit: "chore: version packages"
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          - name: Upload Release Asset
            id: upload-release-asset 
            uses: actions/upload-release-asset@v1
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
            with:
              upload_url: ${{ steps.changesets-release.outputs.release-url }}/upload
              asset_path: ./releases/${{env.GITHUB_REF }}/bundle.min.zip
              asset_name: bundle.min.zip
              asset_content_type: application/zip
  5. mark-omarov commented on Dec 12, 2022

    @mark-omarov
    Contributor

    Since changesets support monorepo and we can have several different packages released, a singular assets config might not work very well.

    If changesets/action would also include release ID in the outputs.publishedPackages for every published/released item, that would help, or perhaps something similar but solely focused on outputting only for released packages.

    I'm facing this issue with non-npm packages (applications), and as a workaround I'm going to use whatever is available in the outputs.publishedPackages to craft the lookup tag, then retrieve the release, using the upload URL for every release I'd then compile applications and upload to respected assets. Not ideal, but better than nothing.

    It'd be greater if changesets/action could do the heavy lifting though.

  6. irshadahmad21 commented on Jan 18, 2024

    @irshadahmad21

    If #347 is accepted, then we should be able to upload assets to the releases.

  7. zanminkian commented on Jun 23, 2024

    @zanminkian

    I'm facing the same problem and I need this feature too. Any progress?

  8. MrSquaare commented on Oct 15, 2024

    @MrSquaare

    @Andarist could you please take a look at the proposed PR?

  9. cumt-robin commented on Dec 10, 2024

    @cumt-robin

    This is a very meaningful feature to look forward to.

  10. hirasso commented on Jan 18, 2025

    @hirasso

    I also just stumbled upon the need to upload a custom release asset to my gh releases. Turns out, finding the latest release tag and uploading a release asset to it is pretty simple using GitHub CLI, which is available in GitHub actions by default, in combination with a detection if a release was published by changesets/action:

          - name: Create changesets PR or Publish
            id: cs
            uses: changesets/action@v1
            with:
              title: "[CI] Release"
              commit: "[CI] Release"
              version: pnpm run version
              publish: pnpm changeset tag
            env:
              GITHUB_TOKEN: ${{ secrets.HIRASSO_ACTIONS_TOKEN }}
    
          - name: Upload Release Asset
            if: steps.cs.outputs.published == 'true'
            run: |
              set -e
              LATEST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName')
              ASSET="${{ needs.package-infos.outputs.packageName }}.zip"
              gh release upload "$LATEST_TAG" "$ASSET" --clobber
              echo "✅ Uploaded $ASSET to the release $TAG"
            env:
              GH_TOKEN: ${{ github.token }}

    The Upload Release Asset step:

    • detects if a release was published (steps.cs.outputs.published == 'true')
    • if so, uses gh to get the latest tag
    • uses gh to upload my previously generated package-name.zip to my release

    I'm always pre-generating the release asset in a step before the changesets/action step, so that is readily available, should changesets decide it's time to publish a release. That way, the time between a published release and the asset being attached should be minimal.

    This works nicely for me.

  11. added theissue type on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions