Skip to content

Release workspace

Release workspace #5

name: Release workspace
on:
workflow_dispatch:
inputs:
workspace:
description: "Name of the Workspace"
required: true
type: string
force_release:
description: "Force release even if no changesets are present"
required: false
type: boolean
branch:
description: "Branch to run the workflow on"
required: false
default: "main"
type: string
workflow_call:
inputs:
force_release:
description: "Force release even if no changesets are present"
required: false
type: boolean
workspace:
description: "Name of the Workspace"
required: true
type: string
branch:
description: "Branch to run the workflow on"
required: false
default: "main"
type: string
concurrency:
group: ${{ github.workflow }}-${{ inputs.workspace }}
jobs:
changesets-pr:
name: Update Version Packages PR for ${{ inputs.workspace }} on branch ${{ inputs.branch }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./workspaces/${{ inputs.workspace }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
outputs:
needs_release: ${{ steps.release_check.outputs.needs_release }}
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', inputs.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Fetch previous commit for release check
run: git fetch origin '${{ github.event.before }}'
- name: Fetch the commit that triggered the workflow (used by backstage/changesets-action)
run: git fetch origin ${{ github.sha }}
continue-on-error: true
- name: Check if release
id: release_check
if: inputs.force_release != true
run: node ../../scripts/ci/check-if-release.js
env:
WORKSPACE_NAME: ${{ inputs.workspace }}
COMMIT_SHA_BEFORE: '${{ github.event.before }}'
TARGET_BRANCH: ${{inputs.branch}}
- name: Update Version Packages (${{ inputs.workspace }}) PR
id: changesets-pr
if: steps.release_check.outputs.needs_release != 'true' || inputs.force_release != true
uses: backstage/changesets-action@291bfc1f76d1dcfbf967f5810dc0423592eae09a # v2.3.1
with:
title: Version Packages (${{ inputs.workspace }})
cwd: workspaces/${{ inputs.workspace }}
version: yarn changeset version
versionBranch: changesets-release/${{ inputs.workspace }}
skipRootChangelogUpdate: true
env:
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
release:
name: Release workspace ${{ inputs.workspace }} on branch ${{ inputs.branch }}
runs-on: ubuntu-latest
needs: changesets-pr
if: needs.changesets-pr.outputs.needs_release == 'true' || inputs.force_release == true
defaults:
run:
working-directory: ./workspaces/${{ inputs.workspace }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
ref: ${{ inputs.branch }}
- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Install root dependencies
run: yarn install --immutable
working-directory: ${{ github.workspace }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', inputs.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Compile TypeScript
run: yarn tsc:full
- name: Build all packages
run: yarn build:all
- name: publish
run: |
yarn config set -H 'npmAuthToken' "${{ secrets.RHDH_NPM_TOKEN }}"
yarn workspaces foreach -v --no-private npm publish --access public --tolerate-republish
env:
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
- name: Create tag
working-directory: ${{ github.workspace }}/scripts/ci
run: node create-tag.js
env:
WORKSPACE_NAME: ${{ inputs.workspace }}
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN}}