-
Notifications
You must be signed in to change notification settings - Fork 75
133 lines (131 loc) · 3.82 KB
/
main.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
name: Main
on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types:
- published
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install dependencies
run: yarn install
- name: Run lint
run: yarn run lint
test:
name: Test
runs-on: ubuntu-latest
needs: lint
services:
mariadb:
image: mariadb:latest
ports:
- 3306
env:
MARIADB_USER: quotes
MARIADB_PASSWORD: p4ssw0rd
MARIADB_DATABASE: quotes
MARIADB_ROOT_PASSWORD: p4ssw0rd
options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
- name: Install dependencies
run: yarn install
- name: Verify MariaDB connection
env:
PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"$PORT" --silent; do
sleep 1
done
- name: Build projects, run migrations and seeds
env:
DATABASE_HOST: "127.0.0.1"
DATABASE_NAME: quotes
DATABASE_USER: quotes
DATABASE_PASSWORD: p4ssw0rd
DATABASE_PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
yarn run build
yarn run migrate
yarn run seed
- name: Run tests
env:
DATABASE_HOST: "127.0.0.1"
DATABASE_NAME: quotes
DATABASE_USER: quotes
DATABASE_PASSWORD: p4ssw0rd
DATABASE_PORT: ${{ job.services.mariadb.ports[3306] }}
TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
yarn test
CODECOV_TOKEN="$TOKEN" bash <(curl -s https://codecov.io/bash)
push_latest_dockerhub:
name: Push image with latest tag to DockerHub
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Login to DockerHub
env:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
run: docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_ACCESS_TOKEN
- name: Build and tag Docker image
env:
USER: ${{ secrets.DOCKER_HUB_USER }}
REPOSITORY: express-graphql-example
TAG: latest
run: docker build -t $USER/$REPOSITORY:$TAG .
- name: Push Docker image
env:
USER: ${{ secrets.DOCKER_HUB_USER }}
REPOSITORY: express-graphql-example
TAG: latest
run: docker push $USER/$REPOSITORY:$TAG
push_release_dockerhub:
name: Push image with release version tag to DockerHub
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set tag variable
id: version
run: echo ::set-output name=tag::${GITHUB_REF#"refs/tags/"}
- name: Login to DockerHub
env:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
run: docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_ACCESS_TOKEN
- name: Build and tag Docker image
env:
USER: ${{ secrets.DOCKER_HUB_USER }}
REPOSITORY: express-graphql-example
TAG: ${{ steps.version.outputs.tag }}
run: docker build -t $USER/$REPOSITORY:$TAG .
- name: Push Docker image
env:
USER: ${{ secrets.DOCKER_HUB_USER }}
REPOSITORY: express-graphql-example
TAG: ${{ steps.version.outputs.tag }}
run: docker push $USER/$REPOSITORY:$TAG