feat: add infra (#11) #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
MONGO_CONNECTION_STRING: mongodb://root:example@localhost:27017/invitation?authSource=admin | |
IMAGE_NAME: invitation-api | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: ['20.x', '22.x'] | |
services: | |
# Label used to access the service container | |
mongo: | |
image: mongo:8 | |
ports: | |
- 27017:27017 | |
env: | |
MONGO_INITDB_ROOT_USERNAME: root | |
MONGO_INITDB_ROOT_PASSWORD: example | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- run: corepack enable && yarn --immutable | |
- run: yarn build | |
- name: Test | |
run: yarn test | |
env: | |
MONGO_CONNECTION_STRING: 'mongodb://root:example@localhost:27017/invitation?authSource=admin' | |
test-infra: | |
runs-on: ubuntu-24.04 | |
if: github.event_name == 'pull_request' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js 22.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22.x | |
- name: Install Dependencies | |
working-directory: ./infra | |
run: npm i | |
- name: Build | |
working-directory: ./infra | |
run: npm run build | |
docker-test: | |
runs-on: ubuntu-24.04 | |
needs: build | |
if: ${{ github.event_name == 'pull_request' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run tests | |
run: docker build . | |
# Push image to GitHub Packages. | |
# See also https://docs.docker.com/docker-hub/builds/ | |
docker-push: | |
# Ensure test job passes before pushing image. | |
needs: build | |
runs-on: ubuntu-24.04 | |
if: ${{ github.event_name == 'push' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
bervproject/${{ env.IMAGE_NAME }} | |
ghcr.io/${{ github.repository }} | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |