Skip to content

Merge pull request #201 from badaitech/rel/v0.2.7 #10

Merge pull request #201 from badaitech/rel/v0.2.7

Merge pull request #201 from badaitech/rel/v0.2.7 #10

Workflow file for this run

name: Release
on:
push:
branches:
- main
- release
release:
types: [created]
# Prevent concurrent releases
concurrency: ${{ github.workflow }}-${{ github.ref }}
permissions:
contents: write
packages: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_VERSION: 22.14.0
PNPM_VERSION: 10.5.2
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://npm.pkg.github.com'
scope: '@badaitech'
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# run: |
# echo "STORE_PATH=$(pnpm store path)" | tee -a $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lint check
run: pnpm run lint
- name: Run tests
run: pnpm run test
- name: Build packages
run: pnpm run build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: --max-old-space-size=8192
# Create .npmrc file for GitHub Packages
- name: Setup .npmrc
run: |
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
echo "@badaitech:registry=https://npm.pkg.github.com" >> .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# For GitHub releases, publish directly with version from tag
- name: Publish packages from release
if: github.ref == 'refs/heads/release'
run: |
TAG_VERSION="${{ github.event.release.tag_name }}"
# Remove 'v' prefix if present
VERSION="${TAG_VERSION#v}"
echo "Setting version to $VERSION for all packages"
pnpm -r exec -- npm version $VERSION --no-git-tag-version
echo "Publishing release packages..."
pnpm -r publish --access restricted --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Use changesets action for main branch pushes
- name: Create Release PR or Publish
if: github.event_name == 'push'
uses: changesets/action@v1
with:
version: pnpm run changeset:version
publish: pnpm run changeset:publish
commit: 'chore: update package versions'
title: 'chore: update package versions'
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract backend version from package.json
if: github.ref == 'refs/heads/release'
id: backend-package-version
run: |
BACK_VERSION=$(node -p "require('./apps/chaingraph-backend/package.json').version")
echo "BACK_VERSION=$BACK_VERSION" >> $GITHUB_ENV
echo "Extracted backend version: $BACK_VERSION"
- name: Extract frontend version from package.json
if: github.ref == 'refs/heads/release'
id: frontend-package-version
run: |
FRONT_VERSION=$(node -p "require('./apps/chaingraph-frontend/package.json').version")
echo "FRONT_VERSION=$FRONT_VERSION" >> $GITHUB_ENV
echo "Extracted frontend version: $FRONT_VERSION"
- name: Set up Docker Buildx
if: github.ref == 'refs/heads/release'
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: github.ref == 'refs/heads/release'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push Backend Docker image
- name: Build and push Backend Docker image
if: github.ref == 'refs/heads/release'
uses: docker/build-push-action@v5
with:
context: .
file: apps/chaingraph-backend/Dockerfile
push: ${{ github.ref == 'refs/heads/release' }}
tags: |
ghcr.io/${{ github.repository_owner }}/chaingraph-backend:latest
ghcr.io/${{ github.repository_owner }}/chaingraph-backend:${{ env.BACK_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Build and push Frontend Docker image
- name: Build and push Frontend Docker image
if: github.ref == 'refs/heads/release'
uses: docker/build-push-action@v5
with:
context: .
file: apps/chaingraph-frontend/Dockerfile
push: ${{ github.ref == 'refs/heads/release' }}
tags: |
ghcr.io/${{ github.repository_owner }}/chaingraph-frontend:latest
ghcr.io/${{ github.repository_owner }}/chaingraph-frontend:${{ env.FRONT_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Build and push images (Push to main/develop/tags)
# if: github.ref == 'refs/heads/release'
# uses: docker/bake-action@v6
# with:
# files: docker-bake.hcl
# targets: backend,frontend
# push: true
# env:
# REGISTRY: ghcr.io/${{ github.repository_owner }}
# BACK_VERSION: ${{ env.BACK_VERSION }}
# FRONT_VERSION: ${{ env.FRONT_VERSION }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}