diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 3d934ef0a..85e756b2c 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -1,4 +1,4 @@ -name: Validate, build and push backend. +name: Validate backend. on: push: @@ -31,21 +31,3 @@ jobs: run: npm run -w backend unit-test - name: Integration tests run: npm run -w backend integration-test - - build-and-push: - needs: tests - runs-on: ubuntu-latest - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v4 - with: - push: true - file: backend/Dockerfile - tags: sjakusch/steam-game-stats-backend:latest diff --git a/.github/workflows/cicd-backend.yml b/.github/workflows/cicd-backend.yml new file mode 100644 index 000000000..19373cf2e --- /dev/null +++ b/.github/workflows/cicd-backend.yml @@ -0,0 +1,59 @@ +name: Validate and deploy backend. + +on: + push: + branches: [master] + paths: ["backend/**"] + +jobs: + tests: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.12.1] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + - name: Install backend dependencies + run: npm ci -w backend + - name: Prettier check + run: npm run -w backend prettier:check + - name: Unit tests + run: npm run -w backend unit-test + - name: Integration tests + run: npm run -w backend integration-test + + build-and-push: + needs: tests + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + push: true + file: backend/Dockerfile + tags: sjakusch/steam-game-stats-backend:latest + + deploy: + needs: build-and-push + runs-on: ubuntu-latest + steps: + - name: Deploy on Render + if: github.ref == 'refs/heads/master' + env: + deploy_url: ${{ secrets.RENDER_DEPLOY_HOOK_URL }} + run: | + curl "$deploy_url"