This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (168 loc) · 5.34 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: CI
on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches:
- main
tags:
- '*.*.*'
pull_request:
env:
docker_repository: sagebionetworks/rocc-service
# github.event.repository.default_branch not available for on: schedule
default_branch: main
jobs:
configure:
runs-on: ubuntu-latest
steps:
- name: Create configuration
run: |
DOCKER_IMAGE=${{ env.docker_repository }}
VERSION=noop
PUSH=false
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
PUSH=true
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
PUSH=true
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION == "edge" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:edge-${GITHUB_SHA::8}"
elif [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
PUSH=true
fi
printf "%s\n" \
"version=${VERSION}" \
"tags=${TAGS}" \
"created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
"push=${PUSH}" | tee -a .github_env
- name: Upload .github_env
uses: actions/upload-artifact@v2
with:
name: GITHUB_ENV
path: .github_env
lint:
needs: [configure]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Dockerfiles
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: server/Dockerfile
# - name: Validate docker-compose.yml
# run: |
# docker-compose -f docker-compose.yml config >/dev/null
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check server/requirements.txt
sort -f --check server/test-requirements.txt
- name: Validate Python code style with Black
uses: psf/black@stable
with:
options: "--check --exclude 'openapi_server/(models|test)'"
src: "./server/openapi_server"
version: "22.1.0"
# - name: Lint Python code with Flake8
# uses: docker://alpine/flake8:latest
# with:
# args: --config server/setup.cfg server
# - name: Lint Python code with Black
# uses: psf/black@stable
# with:
# options: "--check --verbose --line-length 79 --exclude 'openapi_server/(models|test)'"
# src: "./openapi_server"
# version: "21.12b0"
test:
needs: [lint]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
cd server
python -m pip install --upgrade pip
pip install tox tox-gh-actions coveralls
- name: Test with tox
run: |
export $(grep -v '^#' .env.example | xargs -d '\n')
cd server
tox
- name: Prepare environment for coveralls
run: |
echo "PYTHON_ENV=$(echo py${{ matrix.python-version }} | tr -d .)" >> $GITHUB_ENV
# - name: Coveralls Parallel
# env:
# COVERALLS_FLAG_NAME: ${{ env.PYTHON_ENV }}
# COVERALLS_PARALLEL: true
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# cd server
# coveralls --service=github
# finish-coveralls:
# needs: [test]
# runs-on: ubuntu-latest
# container: python:3-slim
# steps:
# - name: Finish Coveralls Parallel
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# pip3 install --upgrade coveralls
# coveralls --finish
docker:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download .github_env
uses: actions/download-artifact@v2
with:
name: GITHUB_ENV
path: .
- name: Restore $GITHUB_ENV
run: cat .github_env >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
if: env.push == 'true'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: server
file: server/Dockerfile
platforms: linux/amd64
push: ${{ env.push }}
tags: ${{ env.tags }}
labels: |
org.opencontainers.image.created=${{ env.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ env.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}