From 234db1c033e3da8364b75df0fc64574d1871cb14 Mon Sep 17 00:00:00 2001 From: ereti <43418802+ereti@users.noreply.github.com> Date: Thu, 28 Oct 2021 03:11:32 +0100 Subject: [PATCH 1/3] Update and rename tests.yml to test-build-deploy.yml --- .../.github/workflows/test-build-deploy.yml | 99 +++++++++++++++++++ server/.github/workflows/tests.yml | 56 ----------- 2 files changed, 99 insertions(+), 56 deletions(-) create mode 100644 server/.github/workflows/test-build-deploy.yml delete mode 100644 server/.github/workflows/tests.yml diff --git a/server/.github/workflows/test-build-deploy.yml b/server/.github/workflows/test-build-deploy.yml new file mode 100644 index 000000000..6cef0cb9b --- /dev/null +++ b/server/.github/workflows/test-build-deploy.yml @@ -0,0 +1,99 @@ +name: Test, Build, Deploy + +on: + push: + branches: [master, develop] + pull_request: + branches: [master, develop] + +jobs: + test: + runs-on: ubuntu-latest + env: + NODE_ENV: "test" + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install Node.js 16 + uses: actions/setup-node@v2 + with: + node-version: 16.x + + - name: Install PNPM + uses: pnpm/action-setup@v2.0.1 + with: + version: 6.0.2 + + - name: Install Dependencies + run: pnpm i + + # configure external dbs + - uses: supercharge/mongodb-github-action@1.4.1 + - uses: supercharge/redis-github-action@1.1.0 + + - name: Move Config File + run: mv ./.github/test.conf.json5 ./test.conf.json5 + + - name: Run Tests + run: pnpm test + + - name: Lint Code + run: pnpm lint + + - name: Upload Coverage + if: always() + run: | + pnpm install -g codecov + cat coverage/lcov.info | codecov + docker-push: + runs-on: ubuntu-latest + needs: [test] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Docker Hub login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Latest tag + if: github.ref == 'refs/heads/develop' + run: echo "BRANCH_TAG=latest" >> $GITHUB_ENV + + - name: Stable tag + if: github.ref == 'refs/heads/master' + 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-server:${{ env.BRANCH_TAG }},${{ secrets.DOCKER_USERNAME }}/tachi-server:${{ env.VERSION_TAG }}, + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + deploy: + runs-on: ubuntu-latest + needs: [docker-push] + if: github.ref == 'refs/heads/master' + steps: + - name: Run deploy script on server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.TACHI_HOST }} + username: tachi + key: ${{ secrets.TACHI_KEY }} + script: tachi-server-deploy diff --git a/server/.github/workflows/tests.yml b/server/.github/workflows/tests.yml deleted file mode 100644 index 958fe0cf0..000000000 --- a/server/.github/workflows/tests.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Tachi-Server CI - -env: - NODE_ENV: "test" - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - -on: - push: - branches: [master, develop] - pull_request: - branches: [master, develop] - -jobs: - test: - name: Build and Test - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v2 - - - name: Install Node.js 16 - uses: actions/setup-node@v2 - with: - node-version: 16.x - - - name: Install PNPM - uses: pnpm/action-setup@v2.0.1 - with: - version: 6.0.2 - - # configure external dbs - - uses: supercharge/mongodb-github-action@1.4.1 - - uses: supercharge/redis-github-action@1.1.0 - - - name: Install Dependencies - run: pnpm i - - - name: Move Config File - run: mv ./.github/test.conf.json5 ./test.conf.json5 - - - name: Run Tests - run: pnpm test - env: - PORT: 8080 - MONGO_URL: "127.0.0.1" - REDIS_URL: "127.0.0.1" - CDN_FILE_ROOT: "./test-cdn" - - - name: Lint Code - run: pnpm lint - - - name: Upload Coverage - if: always() - run: | - pnpm install -g codecov - cat coverage/lcov.info | codecov From f1549ab56342842d0721a8026fb83ebe40da7dc0 Mon Sep 17 00:00:00 2001 From: ereti <43418802+ereti@users.noreply.github.com> Date: Thu, 28 Oct 2021 03:16:18 +0100 Subject: [PATCH 2/3] Update test-build-deploy.yml --- server/.github/workflows/test-build-deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/.github/workflows/test-build-deploy.yml b/server/.github/workflows/test-build-deploy.yml index 6cef0cb9b..c91a59624 100644 --- a/server/.github/workflows/test-build-deploy.yml +++ b/server/.github/workflows/test-build-deploy.yml @@ -50,6 +50,7 @@ jobs: docker-push: runs-on: ubuntu-latest needs: [test] + if: github.event_name == 'push' steps: - name: Checkout uses: actions/checkout@v2 @@ -88,7 +89,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: [docker-push] - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' && github.event_name == 'push' steps: - name: Run deploy script on server uses: appleboy/ssh-action@master From b2e77e5e0d90b1f4f361f30302b6a1326aae9fab Mon Sep 17 00:00:00 2001 From: ereti <43418802+ereti@users.noreply.github.com> Date: Thu, 28 Oct 2021 03:18:30 +0100 Subject: [PATCH 3/3] Update test-build-deploy.yml --- server/.github/workflows/test-build-deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/.github/workflows/test-build-deploy.yml b/server/.github/workflows/test-build-deploy.yml index c91a59624..1b3303fb7 100644 --- a/server/.github/workflows/test-build-deploy.yml +++ b/server/.github/workflows/test-build-deploy.yml @@ -38,6 +38,11 @@ jobs: - name: Run Tests run: pnpm test + env: + PORT: 8080 + MONGO_URL: "127.0.0.1" + REDIS_URL: "127.0.0.1" + CDN_FILE_ROOT: "./test-cdn" - name: Lint Code run: pnpm lint