generated from nlpsandbox/i2b2-phi-dataset
-
Notifications
You must be signed in to change notification settings - Fork 2
227 lines (204 loc) · 7.08 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: CI
on:
push:
branches:
- main
tags:
- '*.*.*'
pull_request:
env:
docker_repository: nlpsandbox/notebooks
# github.event.repository.clone_url not available for on: schedule
clone_url: https://github.com/nlpsandbox/notebooks.git
# 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_IMAGE=false
PUSH_NOTEBOOKS=false
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=weekly
PUSH_IMAGE=true
PUSH_NOTEBOOKS=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_IMAGE=true
PUSH_NOTEBOOKS=true
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
PUSH_IMAGE=false
PUSH_NOTEBOOKS=true
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
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
fi
printf "%s\n" \
"version=${VERSION}" \
"version_major=${MAJOR}" \
"version_minor=${MINOR}" \
"tags=${TAGS}" \
"created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
"push_image=${PUSH_IMAGE}" \
"push_notebooks=${PUSH_NOTEBOOKS}" | 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: Dockerfile
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check conda/nlpsandbox/requirements.txt
test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set environment variables
run: |
cp .env.example .env
export $(grep -v '^#' .env | xargs -d '\n')
- name: Validate docker-compose.yml
run: docker-compose -f docker-compose.yml config >/dev/null
build-and-publish:
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
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Login to Docker Hub
if: env.push_image == 'true'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
load: true
push: false
platforms: linux/amd64
tags: rstudio-cached:latest
- name: Create .env
run: |
cp .env.example .env
printf "%s\n" \
"PASSWORD=${{ secrets.RSTUDIO_PASSWORD }}" \
"USERID=$(id -u)" \
"GROUPID=$(id -g)" \
"SYNAPSE_TOKEN=${{ secrets.SYNAPSE_TOKEN }}" | tee -a .env >/dev/null
# - name: Generate HTML notebooks
# run: |
# docker run --rm \
# --env-file .env \
# -v $(pwd):/project \
# rstudio-cached:latest \
# render /project/notebooks/*.Rmd
- name: Push image
if: env.push_image == 'true'
id: docker_push
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
platforms: linux/amd64
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 }}
# - name: Prepare to publish HTML notebooks to GH Pages
# if: env.push_notebooks == 'true'
# run: |
# git clone ${{ env.clone_url }} \
# --branch gh-pages --single-branch gh-pages
# # Update gh-pages: version specified
# NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version }}/notebooks
# rm -fr ${NOTEBOOKS_TARGET_DIR}
# mkdir -p ${NOTEBOOKS_TARGET_DIR}
# cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# # Update gh-pages: latest, major, and minor versions
# if [ ! -z "${{ env.version_major }}" ]; then
# # Update latest (e.g. "1.2.3" => "latest")
# NOTEBOOKS_TARGET_DIR=gh-pages/latest/notebooks
# rm -fr ${NOTEBOOKS_TARGET_DIR}
# mkdir -p ${NOTEBOOKS_TARGET_DIR}
# cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# # Update major version (e.g. "1.2.3" => "1")
# NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version_major }}/notebooks
# rm -fr ${NOTEBOOKS_TARGET_DIR}
# mkdir -p ${NOTEBOOKS_TARGET_DIR}
# cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# # Update minor version (e.g. "1.2.3" => "1.2")
# NOTEBOOKS_TARGET_DIR=gh-pages/${{ env.version_minor }}/notebooks
# rm -fr ${NOTEBOOKS_TARGET_DIR}
# mkdir -p ${NOTEBOOKS_TARGET_DIR}
# cp -R notebooks/*.html ${NOTEBOOKS_TARGET_DIR}
# fi
# cd gh-pages
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git commit -m "Update notebooks" -a || true
# # The above command will fail if no changes were present, so we ignore
# # that.
# - name: Push to gh-pages
# if: env.push_notebooks == 'true'
# uses: ad-m/github-push-action@master
# with:
# branch: gh-pages
# directory: gh-pages
# github_token: ${{ secrets.GITHUB_TOKEN }}
# force: true