chore: fix release workflow (#142) #54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- "main" | |
workflow_dispatch: | |
env: | |
# The release + deployment will be done on "prod" stage if on main branch, on "dev" stage otherwise | |
STAGE: ${{ github.ref_name == 'main' && 'prod' || 'dev' }} | |
jobs: | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ssh-key: ${{ secrets.GH_PUSH_PROTECTED_KEY }} | |
- uses: pnpm/action-setup@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: pnpm | |
registry-url: "https://registry.npmjs.org/" | |
scope: sit-onyx | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: 📦 Install dependencies | |
run: pnpm install | |
- name: 🛠️ Build packages | |
run: pnpm build:all | |
- name: Upload Storybook artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: storybook-static | |
path: packages/sit-onyx/storybook-static | |
- name: Upload documentation artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: documentation | |
path: apps/docs/src/.vitepress/dist | |
- name: 🤖 Configure Git Bot | |
run: | | |
git config user.name "Release Bot[bot]" | |
git config user.email "[email protected]" | |
- name: ⛴️ Version and Publish | |
if: ${{ env.STAGE == 'prod' }} | |
run: | | |
npx changeset version | |
npx changeset publish | |
git add --all | |
if [[ `git status --porcelain` ]]; then | |
git commit --amend --no-edit | |
git push --follow-tags | |
else | |
echo "No new version. Nothing to commit." | |
fi | |
- name: 📸 Snapshot and Publish | |
if: ${{ env.STAGE != 'prod' }} | |
run: | | |
# [Snapshot release fails if repository is in pre-release mode](https://github.com/changesets/changesets/issues/1195) | |
rm -f .changeset/pre.json | |
# Add empty changeset so we always have a new snapshot release for each new run | |
npx changeset add --empty | |
npx changeset version --snapshot | |
npx changeset publish --tag snapshot | |
deploy_storybook: | |
name: Deploy Storybook | |
runs-on: ubuntu-latest | |
needs: release | |
environment: ${{ github.ref_name == 'main' && 'prod' || 'dev' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Storybook artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: storybook-static | |
path: packages/sit-onyx/.cloud-foundry/storybook-static | |
- name: Deploy to Cloud Foundry | |
uses: ./.github/templates/cf-push | |
with: | |
endpoint: ${{ vars.CF_ENDPOINT }} | |
org: ${{ vars.CF_ORG }} | |
username: ${{ vars.CF_USERNAME }} | |
password: ${{ secrets.CF_PASSWORD }} | |
# we need to define a fallback value here because the default for the input | |
# is only assigned when the workflow is triggered manually. When triggered e.g. on push | |
# the input will be unset so a fallback is needed here | |
space: ${{ env.STAGE }} | |
working-directory: packages/sit-onyx/.cloud-foundry | |
deploy_documentation: | |
name: Deploy documentation | |
runs-on: ubuntu-latest | |
needs: release | |
environment: ${{ github.ref_name == 'main' && 'prod' || 'dev' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Storybook artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: documentation | |
path: apps/docs/.cloud-foundry/dist | |
- name: Deploy to Cloud Foundry | |
uses: ./.github/templates/cf-push | |
with: | |
endpoint: ${{ vars.CF_ENDPOINT }} | |
org: ${{ vars.CF_ORG }} | |
username: ${{ vars.CF_USERNAME }} | |
password: ${{ secrets.CF_PASSWORD }} | |
# we need to define a fallback value here because the default for the input | |
# is only assigned when the workflow is triggered manually. When triggered e.g. on push | |
# the input will be unset so a fallback is needed here | |
space: ${{ env.STAGE }} | |
working-directory: apps/docs/.cloud-foundry |