-
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (93 loc) · 2.69 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 }}