From 6ae16271bf84600b2596455435fe4709fd7019ce Mon Sep 17 00:00:00 2001 From: Iacami Gevaerd Date: Tue, 14 Nov 2023 10:14:29 -0300 Subject: [PATCH] chore: unify gh workflows and deploy docker only when releasing a tag --- .github/workflows/docker.yml | 44 -------------------------- .github/workflows/nodejs.yml | 60 ++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index d2ed337d..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: 'docker publish' -on: - push: - branches: - - develop - -jobs: - build: - runs-on: 'ubuntu-latest' - - steps: - - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: '16' - - - name: 'Checkout Project' - uses: 'actions/checkout@v3' - with: - fetch-depth: 1 - - - name: Install Dependencies and lint code - run: yarn install && yarn lint - - - name: Test build - run: yarn build-release - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build docker image - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - builder: ${{ steps.buildx.outputs.name }} - push: true - tags: vnguyen/openbeta-graph-api:latest diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 88cde9a8..a821877d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -4,25 +4,55 @@ on: push: branches: - develop + - test + pull_request: -jobs: - build: - runs-on: 'ubuntu-latest' + release: + types: [published] +jobs: + release: + needs: test + if: startsWith(github.ref, 'refs/tags/v') steps: - - name: Setup Node.js environment - uses: actions/setup-node@v3 + - name: 'Checkout Project' + uses: 'actions/checkout@v3' with: - node-version: '16.15' + fetch-depth: 1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build docker image + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: vnguyen/openbeta-graph-api:latest + + test: + runs-on: 'ubuntu-latest' + + steps: - name: 'Checkout Project' uses: 'actions/checkout@v3' with: fetch-depth: 1 - - name: Install Dependencies and lint code - run: yarn install && yarn lint + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: '16.15' + cache: 'yarn' - name: Start MongoDB uses: supercharge/mongodb-github-action@1.8.0 @@ -30,6 +60,12 @@ jobs: mongodb-version: 5 mongodb-replica-set: rs0 + - name: Install dependencies + run: yarn install --immutable + + - name: Lint code + run: yarn lint + - name: Wait for the database to start run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- localhost:27017 -- echo "Database is up" env: @@ -44,8 +80,8 @@ jobs: run: | docker container restart mongodb - - name: Build and run tests - run: yarn test - env: - NODE_OPTIONS: --experimental-vm-modules + - name: Run tests + run: yarn test --ci + - name: Build sources + run: yarn build-release --noEmit