-
Notifications
You must be signed in to change notification settings - Fork 51
206 lines (171 loc) · 6.12 KB
/
nucliadb_train.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
name: nucliadb Train (py)
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
COMPONENT: nucliadb-train
CONTAINER_REGISTRY: eu.gcr.io/${{ secrets.PROJECT_ID }}
IMAGE_NAME: nucliadb_train
jobs:
# Job to run pre-checks
pre-checks:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install package
run: make -C nucliadb/ install-dev
- name: Run pre-checks
run: make -C nucliadb/ lint-train
# Job to run tests
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install the package
run: make -C nucliadb/ install-dev
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
workflows:
- 'nucliadb_node/**'
- 'nucliadb_fields_tantivy/**'
- 'nucliadb_paragraphs_tantivy/**'
- 'nucliadb_vectors/**'
- 'nucliadb_relations/**'
- name: Calc git info
id: git
run: |-
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Install rust binding for testing
if: steps.filter.outputs.workflows == 'true'
env:
SECRET_KEY: ${{ secrets.RUST_BUILD_SERVER_SECRET }}
COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
BRANCH: ${{ steps.git.outputs.branch }}
MATURIN: "true"
ENV: '{"RUSTFLAGS": "--cfg tokio_unstable"}'
run: |
./scripts/download-build.sh && pip install builds/wheels/*_x86_64.whl || (
echo "Failed building from the build server." && make build-node-binding-debug
)
- name: Run tests
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_minutes: 10
command: |
pytest -rfE --cov=nucliadb.train -s --tb=native -v --cov-report xml --cov-append nucliadb/nucliadb/train
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: train
# PR workflows END here
# PUSH workflows contine with deploy activities
build:
name: Build image and push
runs-on: ubuntu-latest
needs: tests
if: github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Calculate short sha
id: env-vars
run: |-
HASH=`git rev-parse --short HEAD`
BRANCH=${GITHUB_REF##*/}
echo "short_sha=$HASH" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
- name: Setup gcloud CLI
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: Configure Docker
run: docker login -u oauth2accesstoken -p "$(gcloud auth application-default print-access-token)" https://eu.gcr.io
# We need to setup buildx to be able to cache with gha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.env-vars.outputs.short_sha }}
${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.env-vars.outputs.branch }}
cache-from: type=gha
cache-to: type=gha,mode=min
deploy:
name: Deploy Helm chart and trigger internal CI
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Calculate short sha
id: env-vars
run: |-
HASH=`git rev-parse --short HEAD`
echo "short_sha=$HASH" >> $GITHUB_OUTPUT
- name: Set helm package image
id: version_step
run: |-
sed -i.bak "s#IMAGE_TO_REPLACE#$IMAGE_NAME:${{ steps.env-vars.outputs.short_sha }}#" ./charts/nucliadb_train/values.yaml
sed -i.bak "s#CONTAINER_REGISTRY_TO_REPLACE#$CONTAINER_REGISTRY#" ./charts/nucliadb_train/values.yaml
VERSION=`cat VERSION`
VERSION_SHA=$VERSION+${{ steps.env-vars.outputs.short_sha }}
sed -i.bak "s#99999.99999.99999#$VERSION_SHA#" ./charts/nucliadb_train/Chart.yaml
echo "version_number=$VERSION_SHA" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.4.0
- name: Push helm package
run: |-
helm lint charts/nucliadb_train
helm package charts/nucliadb_train
curl --data-binary "@nucliadb_train-${{ steps.version_step.outputs.version_number }}.tgz" ${{ secrets.HELM_CHART_URL }}/api/charts
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GH_CICD_PUBLIC }}
repository: nuclia/nucliadb_deploy
event-type: promote
client-payload: '{"component": "nucliadb_train", "chart-version": "${{ steps.version_step.outputs.version_number }}"}'