Files
imphnen-frontend-service/.github/workflows/nix-build.yml
T
maulanasdqnandClaude Opus 4.6 e14f6d4ef7 ci: replace update-infra with clan deploy
- Update flake.lock in imphnen-infrastructure
- Deploy to Hetzner server using clan machines update
- Requires SERVER_SSH_KEY secret for server access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 14:27:31 +07:00

127 lines
3.9 KiB
YAML

name: Nix Build & Deploy
on:
push:
branches: ['develop']
pull_request:
branches: ['develop']
jobs:
detect:
runs-on: ubuntu-latest
outputs:
affected: ${{ steps.affected.outputs.apps }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Detect affected apps
id: affected
run: |
AFFECTED=$(npx nx show projects --affected --base=HEAD~1 --type=app 2>/dev/null | tr '\n' ' ')
echo "Affected apps: $AFFECTED"
APPS="[]"
for app in landing backoffice gacha dimentorin hackathon infra qrcampaign; do
if echo "$AFFECTED" | grep -qw "$app"; then
APPS=$(echo "$APPS" | jq -c ". + [\"$app\"]")
fi
done
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
echo "Matrix: $APPS"
build:
needs: detect
if: needs.detect.outputs.affected != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJson(needs.detect.outputs.affected) }}
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Setup Cachix
uses: cachix/cachix-action@v15
with:
name: msdqn
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build ${{ matrix.app }}
run: nix build .#${{ matrix.app }} -o result-${{ matrix.app }}
- name: Push to Cachix
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
run: cachix push msdqn result-${{ matrix.app }}
deploy:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Setup Cachix
uses: cachix/cachix-action@v15
with:
name: msdqn
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Setup SSH
env:
INFRA_DEPLOY_KEY: ${{ secrets.INFRA_DEPLOY_KEY }}
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
mkdir -p ~/.ssh
echo "${INFRA_DEPLOY_KEY}" > ~/.ssh/infra_deploy
chmod 600 ~/.ssh/infra_deploy
if [ -n "${SERVER_SSH_KEY}" ]; then
echo "${SERVER_SSH_KEY}" > ~/.ssh/server_key
chmod 600 ~/.ssh/server_key
fi
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
ssh-keyscan 167.235.70.37 >> ~/.ssh/known_hosts 2>/dev/null
- name: Clone infrastructure
run: |
export GIT_SSH_COMMAND="ssh -i ~/.ssh/infra_deploy -o IdentitiesOnly=yes"
git clone git@github.com:IMPHNEN/imphnen-infrastructure.git /tmp/infra
- name: Update flake.lock
working-directory: /tmp/infra
run: |
nix flake update imphnen-frontend
if git diff --quiet flake.lock; then
echo "flake.lock unchanged, skipping commit"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/infra_deploy -o IdentitiesOnly=yes"
git add flake.lock
git commit -m "chore: update imphnen-frontend-service to ${GITHUB_SHA::7}"
git push
fi
- name: Deploy with clan
working-directory: /tmp/infra
run: |
if [ -f ~/.ssh/server_key ]; then
export NIX_SSHOPTS="-i $HOME/.ssh/server_key -o StrictHostKeyChecking=accept-new"
fi
nix develop .#default --command clan machines update hetzner
- name: Cleanup SSH keys
if: always()
run: rm -f ~/.ssh/infra_deploy ~/.ssh/server_key