Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
80 changes: 67 additions & 13 deletions .github/workflows/frontend-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
permissions:
contents: read

concurrency:
group: frontend-production
cancel-in-progress: false

jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -54,21 +58,23 @@ jobs:
set -euo pipefail
PACKAGE_VERSION="$(node -p "require('./package.json').version")"

echo "Release version: $RELEASE_VERSION"
echo "package.json version: $PACKAGE_VERSION"

if [ "$RELEASE_VERSION" != "$PACKAGE_VERSION" ]; then
echo "::error::Version mismatch: frontend release '$RELEASE_VERSION' does not match package.json version '$PACKAGE_VERSION'."
exit 1
fi

- name: Set up environment file
run: |
echo "VITE_API_URL=${{ secrets.VITE_API_URL }}" > .env.production
- name: Set up production environment
run: cp .env.production.example .env.production

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check formatting
run: pnpm run format:check

- name: Lint app
run: pnpm run lint

- name: Build app
run: pnpm run build

Expand All @@ -92,15 +98,29 @@ jobs:
fs.writeFileSync("dist/version.json", `${JSON.stringify(version, null, 2)}\n`);
NODE

- name: Package immutable release
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: tar -czf "$PWD/bitfinance-frontend-$RELEASE_VERSION.tar.gz" -C dist .

- name: Retain rollback artifact
uses: actions/upload-artifact@v7
with:
name: bitfinance-frontend-${{ steps.version.outputs.version }}
path: apps/frontend/bitfinance-frontend-${{ steps.version.outputs.version }}.tar.gz
retention-days: 90
if-no-files-found: error

- name: Connect to Tailscale
uses: tailscale/github-action@v4
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci

- name: Deploy files
- name: Deploy immutable release
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST_IP: ${{ secrets.SSH_HOST }}
TAILSCALE_HOST: ${{ secrets.TAILSCALE_HOST }}
Expand All @@ -110,6 +130,8 @@ jobs:
set -euo pipefail

TARGET_HOST="${TAILSCALE_HOST:-$SSH_HOST_IP}"
ARCHIVE_NAME="bitfinance-frontend-$RELEASE_VERSION.tar.gz"
REMOTE_ARCHIVE="/tmp/$ARCHIVE_NAME-$GITHUB_RUN_ID"

mkdir -p ~/.ssh
chmod 700 ~/.ssh
Expand All @@ -121,16 +143,48 @@ jobs:
printf '%s' "$SSH_PRIVATE_KEY" > "$KEY_FILE"
chmod 600 "$KEY_FILE"

ssh -i "$KEY_FILE" \
-p "$SSH_PORT" \
scp -i "$KEY_FILE" \
-P "$SSH_PORT" \
-o BatchMode=yes \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=yes \
"$SSH_USERNAME@$TARGET_HOST" 'echo "SSH auth OK"'
"$ARCHIVE_NAME" "$SSH_USERNAME@$TARGET_HOST:$REMOTE_ARCHIVE"

scp -i "$KEY_FILE" \
-P "$SSH_PORT" \
ssh -i "$KEY_FILE" \
-p "$SSH_PORT" \
-o BatchMode=yes \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=yes \
-r dist/* "$SSH_USERNAME@$TARGET_HOST:/var/www/bitfinance/"
"$SSH_USERNAME@$TARGET_HOST" \
"RELEASE_VERSION='$RELEASE_VERSION' REMOTE_ARCHIVE='$REMOTE_ARCHIVE' bash -s" <<'REMOTE'
set -euo pipefail

DEPLOY_ROOT=/var/www/bitfinance
RELEASE_PATH="$DEPLOY_ROOT/releases/$RELEASE_VERSION"
STAGING_PATH="$DEPLOY_ROOT/releases/.$RELEASE_VERSION-$RANDOM"

cleanup() {
rm -f "$REMOTE_ARCHIVE"
rm -rf "$STAGING_PATH"
}
trap cleanup EXIT

mkdir -p "$DEPLOY_ROOT/releases"
if [ -e "$RELEASE_PATH" ]; then
echo "Release already exists and is immutable: $RELEASE_PATH" >&2
exit 1
fi

mkdir "$STAGING_PATH"
tar -xzf "$REMOTE_ARCHIVE" -C "$STAGING_PATH"
test -f "$STAGING_PATH/index.html"
grep -F "\"version\": \"$RELEASE_VERSION\"" "$STAGING_PATH/version.json"
mv "$STAGING_PATH" "$RELEASE_PATH"

rm -f "$DEPLOY_ROOT/current.next"
ln -s "releases/$RELEASE_VERSION" "$DEPLOY_ROOT/current.next"
mv -Tf "$DEPLOY_ROOT/current.next" "$DEPLOY_ROOT/current"

test "$(readlink "$DEPLOY_ROOT/current")" = "releases/$RELEASE_VERSION"
test -f "$DEPLOY_ROOT/current/sw.js"
REMOTE
155 changes: 0 additions & 155 deletions .github/workflows/frontend-v2-deploy.yml

This file was deleted.

39 changes: 4 additions & 35 deletions .github/workflows/main-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
frontend_v2: ${{ steps.filter.outputs.frontend_v2 }}
backend: ${{ steps.filter.outputs.backend }}
mcp: ${{ steps.filter.outputs.mcp }}
steps:
Expand All @@ -33,10 +32,6 @@ jobs:
- 'apps/frontend/**'
- '.github/workflows/frontend-deploy.yml'
- '.github/workflows/main-validation.yml'
frontend_v2:
- 'apps/frontend-v2/**'
- '.github/workflows/frontend-v2-deploy.yml'
- '.github/workflows/main-validation.yml'
backend:
- 'apps/backend/**'
- '.github/workflows/backend-docker-publish.yml'
Expand Down Expand Up @@ -72,39 +67,13 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build frontend
run: pnpm run build

frontend-v2:
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.frontend_v2 == 'true'
defaults:
run:
working-directory: apps/frontend-v2
steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v6
with:
version: 11.0.9

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: pnpm
cache-dependency-path: apps/frontend-v2/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check frontend formatting
run: pnpm run format:check

- name: Lint frontend-v2
- name: Lint frontend
run: pnpm run lint

- name: Build frontend-v2
- name: Build frontend
run: pnpm run build

backend:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Frontend:
```bash
cd apps/frontend
pnpm install
pnpm format:check
pnpm lint
pnpm build
```
Expand Down
Loading
Loading