Skip to content

Release Packages

Release Packages #42

# Publishes packages to NPM and makes a Sentry release.
# Refer to the "changesets/action" documentation for more information: https://github.com/changesets/action
name: Release Packages
on:
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
# Do not cancel ✖︎ in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: false
env:
RELEASE_BRANCH: "main"
jobs:
npm-publish:
name: Publish to NPM
runs-on: ubuntu-latest
permissions:
contents: write
environment: production
steps:
- name: Validate Release Branch
run: |
if [ "${{ github.ref_name }}" == "$RELEASE_BRANCH" ]; then
echo "✔︎ Branch '${{ github.ref_name }}' is a release branch '$RELEASE_BRANCH'. Continuing..."
else
echo "✖︎ Branch '${{ github.ref_name }}' is not a release branch '$RELEASE_BRANCH'. Exiting..." >&2
exit 1
fi
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate Changeset Config
run: .changeset/validate-changesets-base-branch.sh ${{ github.ref_name }}
- name: Setup Monorepo
uses: team-monite/setup-yarn-project-action@c098d54db6f34eb2103eb9cceda484984e8b9bbe
with:
# Do not use the cache if merged PR source branch starts with `changeset-release/`
cache: ${{ !startsWith(github.event.pull_request.head.ref, 'changeset-release/') }}
- name: Build
run: yarn build
- name: Inject Sentry Debug IDs
run: yarn sentry-cli sourcemaps inject packages/sdk-react/dist
- name: Create a dummy ".npmrc"
# Prevents creation of ".npmrc" by "changesets/action" with the 'NPM_TOKEN' content
# We use ".yarnrc.yml" with the Environment Variable 'NPM_TOKEN' set
run: touch ".npmrc"
- name: Patch ".yarnrc.yml" Monite NPM scopes
run: |
yarn config set 'npmScopes["monite"]' --home --json '{"npmAlwaysAuth":true,"npmAuthToken":"${NPM_TOKEN}"}'
yarn config set 'npmScopes["team-monite"]' --home --json '{"npmAlwaysAuth":true,"npmAuthToken":"${NPM_TOKEN}"}'
env:
# The 'NPM_TOKEN' must be set to at least empty, as it is used in the ".yarnrc.yml" file
NPM_TOKEN: ""
- name: Publish to NPM
id: changesets
uses: changesets/[email protected]
with:
publish: yarn exec .changeset/publish.sh --create-git-tags
version: sh -c 'echo "Versioning is prohibited in the release workflow" >&2 && exit 1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Upload to Sentry
if: steps.changesets.outputs.published == 'true'
run: yarn sentry-cli sourcemaps upload --release="$(node -p 'require("@monite/sdk-api/package.json").version')" packages/sdk-react/dist
env:
# The 'NPM_TOKEN' must be set to at least empty, as it is used in the ".yarnrc.yml" file
NPM_TOKEN: ""
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}