generated from nlpsandbox/phi-annotator-example
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (130 loc) · 3.97 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
name: CI
on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches:
- main
tags:
- '*.*.*'
pull_request:
env:
docker_repository: docker.synapse.org/syn25992884/bert-phi-annotator
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 =~ ^[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: Lint Python code with Flake8
uses: docker://alpine/flake8:latest
with:
args: --config server/setup.cfg server
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
- name: Test with tox
run: |
cd server
tox
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 Synapse Docker Registry
if: env.push == 'true'
uses: docker/login-action@v1
with:
registry: docker.synapse.org
username: ${{ secrets.SYNAPSE_USERNAME }}
password: ${{ secrets.SYNAPSE_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 }}