-
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (131 loc) · 4.2 KB
/
node.js.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
name: "Build & Test"
env:
PGUSER: postgres
PGHOST: localhost
PGPASSWORD: testpsqlpassword
PGDATABASE: musics
PGPORT: 5432
REDIS_SERVER: localhost
REDIS_PORT: 6379
RABBITMQ_SERVER: amqp://localhost
ACCESS_TOKEN_KEY: fa3dfb26baa6cf6cb78ba2782a328f8242a6104561fbacda3a8fc09acb0dcdb2
REFRESH_TOKEN_KEY: 43ca7b289d3c3e4eaaa837eb6ab7a3a0b94b599a910ffd3f1c78a82dba40d1c9
ACCESS_TOKEN_AGE: 1800
DATABASE_URL: postgres://postgres:testpsqlpassword@localhost:5432/musics
services:
postgres:
image: postgres:15-alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: testpsqlpassword
POSTGRES_DB: musics
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
redis:
image: redis:6-alpine
ports:
- 6379:6379
rabbitmq:
image: rabbitmq:3-alpine
ports:
- 5672:5672
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Package Install
run: yarn --frozen-lockfile
- name: Lint
run: yarn lerna run lint
- name: Migrate DB
run: yarn lerna run migrate --scope=@berviantoleo/music-api -- -- up
- name: Test
run: yarn lerna run test:coverage
- name: Upload to Codecov
if: ${{ matrix.node-version == '18.x' }}
uses: codecov/codecov-action@v4
- name: Build
run: yarn lerna run build
- name: Store Artifacts
uses: actions/upload-artifact@v4
if: ${{ matrix.node-version == '18.x' }}
with:
name: compiled-libs
path: |
packages/api/lib/**/*
packages/consumer/lib/**/*
docker-build:
needs: "build"
name: "Docker Build"
if: ${{ github.event_name == 'push' }}
runs-on: "ubuntu-22.04"
steps:
- uses: actions/checkout@v4
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: compiled-libs
path: packages/
- name: Check files
run: |
ls -la packages/api/lib
ls -la packages/consumer/lib
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_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: Docker metadata Web API
id: meta-webapi
uses: docker/metadata-action@v5
with:
images: |
berviantoleo/music-api-dicoding
ghcr.io/${{ github.repository }}
- name: Docker metadata Consumer
id: meta-consumer
uses: docker/metadata-action@v5
with:
images: |
berviantoleo/music-consumer-dicoding
ghcr.io/${{ github.repository }}-consumer
- name: Build and push (Web API)
uses: docker/build-push-action@v5
with:
context: packages/api
push: true
tags: ${{ steps.meta-webapi.outputs.tags }}
labels: ${{ steps.meta-webapi.outputs.labels }}
- name: Build and push (Consumer)
uses: docker/build-push-action@v5
with:
context: packages/consumer
push: true
tags: ${{ steps.meta-consumer.outputs.tags }}
labels: ${{ steps.meta-consumer.outputs.labels }}