forked from redpwn/rctf
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (126 loc) · 3.7 KB
/
ci.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: CI
on:
push:
branches: [master]
pull_request:
jobs:
check-commits:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
with:
# Fetch all history
fetch-depth: 0
- name: Check commit messages
run: |
scripts/check-commits.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Shellcheck
run: |
shellcheck install/*.sh scripts/*.sh
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12]
steps:
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: |
yarn install --frozen-lockfile
- name: Lint
run: |
yarn lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12]
postgres: [12]
redis: [6]
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
redis:
image: redis:${{ matrix.redis }}
ports:
- 6379:6379
env:
RCTF_DATABASE_URL: postgres://postgres:password@localhost/rctf
RCTF_REDIS_URL: redis://@localhost:6379/0
RCTF_TOKEN_KEY: 32_byte_long_base64_encoded_value_for_token
steps:
- uses: actions/checkout@v2
- name: Set up Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: |
yarn install --frozen-lockfile
- name: Create DB
run: |
psql postgres://postgres:password@localhost -c 'CREATE DATABASE rctf;'
- name: Load configuration
run: |
cp test/conf-test.yaml conf.d
- name: Run migrations
run: |
yarn migrate
- name: Add data to DB
run: |
psql "$RCTF_DATABASE_URL" -c $'INSERT INTO challenges (id, data) VALUES (\'id\', \'{"flag": "flag{good_flag}", "name": "name", "files": [], "author": "author", "points": {"max": 500, "min": 100}, "category": "category", "description": "description", "tiebreakEligible": true}\')'
- name: Build
run: |
yarn build
- name: Run tests
run: |
yarn test:report
- name: Upload coverage reports
uses: codecov/codecov-action@v1
docker-build:
runs-on: ubuntu-latest
# TODO: handle tagging releases correctly
if: github.ref == 'refs/heads/master'
needs:
- shellcheck
- lint
- test
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@3f83d7b89cb3b72c3cb1c57dd6faaa722bb5895c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@3a3bb3a81753dc99f090d24ee7e5343838b73a96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,enable=true,event=branch
type=sha,enable=true,prefix=,format=long
- name: Build and push Docker image
uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}