forked from politics-rewired/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (106 loc) · 3.35 KB
/
ci-cd.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
name: CI/CD Pipeline
on:
push:
jobs:
hadolint:
runs-on: ubuntu-latest
name: "Hadolint"
steps:
- uses: actions/checkout@v2
- uses: jbergstroem/hadolint-gh-action@v1
with:
error_level: 0
dockerfile: "Dockerfile"
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 20.16.0-buster
container:
image: node:${{ matrix.node-version }}
services:
postgres:
image: postgres:13.4
env:
POSTGRES_DB: spoke
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd "pg_isready -h localhost -p 5432"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
NODE_ENV: test
WEBPACK_HOST: "localhost"
WEBPACK_PORT: "3000"
DEV_APP_PORT: "8090"
BASE_URL: "localhost:3000"
SESSION_SECRET: "SuperSecret"
PHONE_NUMBER_COUNTRY: US
SUPPRESS_SELF_INVITE: "false"
JOBS_SAME_PROCESS: "1"
TEST_DATABASE_URL: "postgres://postgres:postgres@postgres:5432/spoke"
PASSPORT_STRATEGY: "local"
steps:
- name: checkout
uses: actions/checkout@v2
- uses: actions/cache@v2
id: yarn-cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
- name: Install dependencies
run: yarn install
- name: Run codegen
run: yarn codegen:ts
- name: Lint Apps
run: yarn lint && yarn format
- name: Run migrations
run: yarn migrate:worker && yarn knex migrate:latest
- name: Run Tests
run: yarn jest --forceExit --detectOpenHandles src/**/*
publish-docker-image:
if: startsWith( github.ref, 'refs/tags/v')
needs: test
name: Publish Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
- name: Get image tags
id: image-tags
run: |
export GIT_SHA="${{ github.sha }}"
export GIT_SHA_SHORT=${GIT_SHA:0:7}
echo "::set-output name=sha::$GIT_SHA_SHORT"
export GIT_REF=${GITHUB_REF#refs/*/}
echo "$GIT_REF"
export SPOKE_VERSION=${GIT_REF#"v"}
export SPOKE_VERSION=${SPOKE_VERSION//[\/]/-}
echo "::set-output name=version::$SPOKE_VERSION"
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-west1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
build-args: |
SPOKE_VERSION=${{ steps.image-tags.outputs.version }}
tags: |
us-west1-docker.pkg.dev/spoke-407503/spoke/core:latest
us-west1-docker.pkg.dev/spoke-407503/spoke/core:${{ steps.image-tags.outputs.version }}
us-west1-docker.pkg.dev/spoke-407503/spoke/core:${{ steps.image-tags.outputs.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max