mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-26 17:07:58 +03:00
139 lines
3.8 KiB
YAML
139 lines
3.8 KiB
YAML
name: Server CI/CD
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "staging"
|
|
- "release/*"
|
|
paths:
|
|
- "server/**"
|
|
- "common/**"
|
|
pull_request:
|
|
branches:
|
|
- "staging"
|
|
- "release/*"
|
|
paths:
|
|
- "server/**"
|
|
- "common/**"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
NODE_ENV: "test"
|
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: pnpm/action-setup@v2
|
|
with:
|
|
version: latest
|
|
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
run: pnpm --filter tachi-server... --filter . install
|
|
|
|
# configure external dbs
|
|
- uses: supercharge/mongodb-github-action@1.4.1
|
|
- uses: supercharge/redis-github-action@1.1.0
|
|
|
|
- name: Run tests
|
|
run: pnpm --filter tachi-server test
|
|
env:
|
|
NODE_ENV: "test"
|
|
PORT: 8080
|
|
MONGO_URL: "127.0.0.1"
|
|
REDIS_URL: "127.0.0.1"
|
|
|
|
- name: Lint code
|
|
run: pnpm --filter tachi-server lint
|
|
|
|
- name: Typecheck code
|
|
run: pnpm --filter tachi-server typecheck
|
|
|
|
- name: Upload coverage
|
|
if: always()
|
|
run: |
|
|
pnpm install -g codecov
|
|
cat coverage/lcov.info | codecov
|
|
docker-push:
|
|
runs-on: ubuntu-latest
|
|
needs: [test]
|
|
defaults:
|
|
run:
|
|
working-directory: ./server
|
|
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Docker Hub login
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
|
|
- name: Develop tag
|
|
if: github.ref == 'refs/heads/staging'
|
|
run: echo "BRANCH_TAG=develop" >> $GITHUB_ENV
|
|
|
|
- name: Stable tag
|
|
if: startsWith(github.ref, 'refs/heads/release')
|
|
run: echo "BRANCH_TAG=stable" >> $GITHUB_ENV
|
|
|
|
- name: Version tag
|
|
run: 'echo "VERSION_TAG=$(cat package.json | grep version | head -1 | awk -F: ''{ print $2 }'' | sed ''s/[", ]//g'')" >> $GITHUB_ENV'
|
|
|
|
- name: Commit Hash
|
|
run: 'echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV'
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Build and push
|
|
id: docker_build
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: ./
|
|
push: true
|
|
tags: ${{ secrets.DOCKER_USERNAME }}/tachi-server:${{ env.BRANCH_TAG }},${{ secrets.DOCKER_USERNAME }}/tachi-server:${{ env.VERSION_TAG }}
|
|
file: ./Dockerfile.server
|
|
build-args: |
|
|
COMMIT_HASH=${{ env.SHORT_SHA }}
|
|
cache-from: type=gha,scope=$GITHUB_REF_NAME-server
|
|
cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-server
|
|
|
|
|
|
- name: Image digest
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
needs: [docker-push]
|
|
defaults:
|
|
run:
|
|
working-directory: ./server
|
|
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
|
|
steps:
|
|
- name: Deploy to staging
|
|
if: github.ref == 'refs/heads/staging'
|
|
uses: appleboy/ssh-action@1a8b3784eaa665f677fa114edd5683bb6a6bfaa8
|
|
with:
|
|
host: ${{ secrets.TACHI_HOST }}
|
|
username: tachi
|
|
key: ${{ secrets.TACHI_KEY }}
|
|
script: tachi-server-deploy -s
|
|
|
|
- name: Deploy to live
|
|
if: startsWith(github.ref, 'refs/heads/release')
|
|
uses: appleboy/ssh-action@1a8b3784eaa665f677fa114edd5683bb6a6bfaa8
|
|
with:
|
|
host: ${{ secrets.TACHI_HOST }}
|
|
username: tachi
|
|
key: ${{ secrets.TACHI_KEY }}
|
|
script: tachi-server-deploy
|