From d06e104f047ac2f1086c43e67dcf7035821f598b Mon Sep 17 00:00:00 2001 From: xyzuan Date: Tue, 5 Nov 2024 11:42:51 +0700 Subject: [PATCH] misc(ci/cd): Merge test to build --- .github/workflows/build-dev.yml | 67 +++++++++++++++++++++++++++---- .github/workflows/treaty-test.yml | 48 ---------------------- 2 files changed, 60 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/treaty-test.yml diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 4bcb95f..bd14758 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -1,14 +1,57 @@ name: Build xyzuan-api-v2 Development Build on: - workflow_run: - workflows: ["Run Tests with Elysia Treaty"] - types: [completed] + push: + branches: + - dev jobs: - build: + test: + name: Run Treaty Tests runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Initialize Bun Environtment + uses: oven-sh/setup-bun@v2 + + - name: Declaring some Global Environtment vars + run: | + echo "PORT=3121" >> $GITHUB_ENV + echo "DOMAIN=localhost" >> $GITHUB_ENV + echo "NODE_ENV=dev" >> $GITHUB_ENV + echo "PASSWORD_PEPPER=${{ secrets.PASSWORD_PEPPER }}" >> $GITHUB_ENV + echo "DATABASE_URL=${{ secrets.DATABASE_URL_DEV }}" >> $GITHUB_ENV + echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> $GITHUB_ENV + echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> $GITHUB_ENV + echo "GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}" >> $GITHUB_ENV + echo "GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }}" >> $GITHUB_ENV + echo "LINKEDIN_CLIENT_ID=${{ secrets.LINKEDIN_CLIENT_ID }}" >> $GITHUB_ENV + echo "LINKEDIN_CLIENT_SECRET=${{ secrets.LINKEDIN_CLIENT_SECRET }}" >> $GITHUB_ENV + echo "TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }}" >> $GITHUB_ENV + echo "TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }}" >> $GITHUB_ENV + echo "CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }}" >> $GITHUB_ENV + echo "CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }}" >> $GITHUB_ENV + echo "CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }}" >> $GITHUB_ENV + + - name: Run Treaty Tests + id: treaty_test + run: | + bun install + bunx prisma generate + bun test + echo "::set-output name=result::success" + + - name: Mark as failed if tests fail + if: failure() + run: echo "::set-output name=result::failure" + build: + name: Build & Serving to Eden Server + runs-on: ubuntu-latest + needs: test + if: success() steps: - name: Checkout code uses: actions/checkout@v3 @@ -68,18 +111,28 @@ jobs: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }} docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{env.SHA}} - - name: Serving the Images in Eden Server realms. + serve: + name: Serve Images in Eden Server realms + runs-on: ubuntu-latest + needs: build + if: success() + steps: + - name: Authenticating to Eden Server realms + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.SERVER_PRIVATE_KEY }} + + - name: Serve the Images run: | ssh-keyscan -t rsa ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts ssh ${{ github.actor }}@${{ secrets.SERVER_HOST }} << 'EOF' - echo 'Authenticating to GHCR realms...' echo "${{ secrets.GH_TOKEN }}" | docker login -u "${{ github.actor }}" ghcr.io --password-stdin echo 'Pulling the latest image from GHCR...' docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }} - echo 'Force Blowing the exist Docker Container...' + echo 'Force Blowing the existing Docker Container...' docker rm -f ${{ env.CT_NAME }} echo 'Running the Docker Container...' diff --git a/.github/workflows/treaty-test.yml b/.github/workflows/treaty-test.yml deleted file mode 100644 index 28df163..0000000 --- a/.github/workflows/treaty-test.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Run Tests with Elysia Treaty - -on: - push: - branches: - - dev - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Initialize Bun Environtment - uses: oven-sh/setup-bun@v2 - - - name: Declaring some Global Environtment vars - run: | - echo "PORT=3121" >> $GITHUB_ENV - echo "DOMAIN=localhost" >> $GITHUB_ENV - echo "NODE_ENV=dev" >> $GITHUB_ENV - echo "PASSWORD_PEPPER=${{ secrets.PASSWORD_PEPPER }}" >> $GITHUB_ENV - echo "DATABASE_URL=${{ secrets.DATABASE_URL_DEV }}" >> $GITHUB_ENV - echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> $GITHUB_ENV - echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> $GITHUB_ENV - echo "GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}" >> $GITHUB_ENV - echo "GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }}" >> $GITHUB_ENV - echo "LINKEDIN_CLIENT_ID=${{ secrets.LINKEDIN_CLIENT_ID }}" >> $GITHUB_ENV - echo "LINKEDIN_CLIENT_SECRET=${{ secrets.LINKEDIN_CLIENT_SECRET }}" >> $GITHUB_ENV - echo "TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }}" >> $GITHUB_ENV - echo "TELEGRAM_CHAT_ID=${{ secrets.TELEGRAM_CHAT_ID }}" >> $GITHUB_ENV - echo "CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }}" >> $GITHUB_ENV - echo "CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }}" >> $GITHUB_ENV - echo "CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }}" >> $GITHUB_ENV - - - name: Run Treaty Tests - id: treaty_test - run: | - bun install - bunx prisma generate - bun test - echo "::set-output name=result::success" - - - name: Mark as failed if tests fail - if: failure() - run: echo "::set-output name=result::failure"