Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): automated release process #108

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 70 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,85 @@ name: Release

on:
push:
branches:
- x_main # CI release temporarily disabled
tags:
- "*-[0-9]+.[0-9]+.[0-9]+*"
workflow_dispatch:
inputs:
package:
description: "Package to release"
required: true
type: choice
options:
- client
- proxy
version:
description: "Version to release (e.g., 1.2.0, 1.3.0-alpha.0)"
required: true
type: string
dry_run:
description: "Dry run (will not publish to npm)"
required: false
type: boolean
default: true

jobs:
release:
name: Release
build-and-publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16.x"
node-version: "20"
registry-url: "https://registry.npmjs.org"
scope: "@fal"

- name: Install dependencies
run: npm ci
- name: Publish to NPM

- name: Extract package info
id: tag-info
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual trigger
PACKAGE_NAME="${{ inputs.package }}"
VERSION="${{ inputs.version }}"
else
# Tag trigger
TAG_NAME=${{ github.ref_name }}
PACKAGE_NAME=$(echo $TAG_NAME | cut -d'-' -f1)
VERSION=$(echo $TAG_NAME | cut -d'-' -f2-)
fi

# Extract npm tag based on version qualifier
if [[ $VERSION =~ .*-([a-zA-Z]+)\.[0-9]+$ ]]; then
NPM_TAG="${BASH_REMATCH[1]}"
else
NPM_TAG="latest"
fi

echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "npm_tag=$NPM_TAG" >> $GITHUB_OUTPUT

- name: Build package
run: npx nx build ${{ steps.tag-info.outputs.package }} --prod

- name: Verify package version
run: |
PACKAGE_JSON_VERSION=$(node -p "require('./dist/libs/${{ steps.tag-info.outputs.package }}/package.json').version")
if [ "$PACKAGE_JSON_VERSION" != "${{ steps.tag-info.outputs.version }}" ]; then
echo "Package version ($PACKAGE_JSON_VERSION) does not match tag version (${{ steps.tag-info.outputs.version }})"
exit 1
fi

- name: Publish package
run: |
echo "Publishing ${{ steps.tag-info.outputs.package }}@${{ steps.tag-info.outputs.version }} with tag ${{ steps.tag-info.outputs.npm_tag }}"
cd dist/libs/${{ steps.tag-info.outputs.package }}
npm publish --access public --tag ${{ steps.tag-info.outputs.npm_tag }} ${{ inputs.dry_run && '--dry-run' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: npx nx release client
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
Loading