-
Notifications
You must be signed in to change notification settings - Fork 1
207 lines (187 loc) · 6.54 KB
/
build_job.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
name: Build and publish the container image
run-name: ${{ github.actor }} is preparing the next release
"on":
workflow_dispatch:
push:
tags:
- "v*.*.*"
jobs:
release-type-determination:
name: Determine if tag is pre-released or not
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get tag
id: get-tag
run: |
echo "tag=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
- name: Check if tag is a pre-release
id: check-prerelease
run: |
TAG="${{ steps.get-tag.outputs.tag }}"
if [[ "$TAG" == *"-dev"* || "$TAG" == *"-beta"* || "$TAG" == *"-alpha"* ]]; then
echo "image=ghcr.io/freva-clint/freva-rest-api-dev" >> image.txt
else
echo "image=ghcr.io/freva-clint/freva-rest-api" >> image.txt
fi
echo "${{ steps.get-tag.outputs.tag }}" > tag.txt
echo "${{ steps.check-prerelease.outputs.is_prerelease }}" > is_prerelease.txt
- name: Upload Outputs
uses: actions/upload-artifact@v4
with:
name: release-metadata
path: |
image.txt
tag.txt
is_prerelease.txt
tests:
uses: ./.github/workflows/ci_job.yml
docs:
runs-on: ubuntu-latest
needs: [tests, release-type-determination]
if: needs.release-type-determination.outputs.is_prerelease == 'false'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.X"
- name: Install freva rest dependencies
run: |
python3 -m pip install -e ./freva-rest[dev] ./freva-data-portal-worker
- name: Generate self signed keys
run: python dev-env/config/dev-utils.py gen-certs
- name: Set up services
run: |
docker compose -f dev-env/docker-compose.yaml up -d --remove-orphans
- name: Waiting for keycloak
run: >
python dev-env/config/dev-utils.py oidc
http://localhost:8080/realms/freva/.well-known/openid-configuration
- name: Starting the local server
run: |
python run_server.py --config dev-env/api_config.toml --debug --dev -p 7777
- name: Creating docs
run: tox -e docs
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
# Upload entire repository
path: './docs/build/html'
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
build-and-push-image:
runs-on: ubuntu-latest
needs: [tests, release-type-determination]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Download Release Metadata
uses: actions/download-artifact@v4
with:
name: release-metadata
- name: Read Metadata
run: |
IMAGE=$(cat image.txt)
TAG=$(cat tag.txt)
IS_PRERELEASE=$(cat is_prerelease.txt)
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_ENV
echo "DEBUG: IMAGE=$IMAGE"
echo "DEBUG: TAG=$TAG"
echo "DEBUG: IS_PRERELEASE=$IS_PRERELEASE"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.ACCESS_TOKEN }}
- name: Build and push freva-rest API image
uses: docker/build-push-action@v4
with:
context: freva-rest
file: freva-rest/Dockerfile
build-args: VERSION=${{ env.TAG }}
platforms: linux/amd64, linux/arm64, linux/ppc64le
push: true
no-cache: true
tags: |
${{ env.IMAGE }}:${{ env.TAG }}
${{ env.IMAGE }}:${{ env.IS_PRERELEASE == 'false' && 'latest' || env.TAG }}
pypi:
name: Create Pip package
needs: [tests, build-and-push-image, docs, release-type-determination]
if: needs.release-type-determination.outputs.is_prerelease == 'false'
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
-
name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
-
name: Install flit
run: python -m pip install flit
-
name: Building freva-client 📦 with flit
run: flit build
working-directory: freva-client
-
name: publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
verbose: true
packages-dir: freva-client/dist
bump-databrowser-version:
runs-on: ubuntu-latest
needs: [build-and-push-image, docs, release-type-determination]
if: needs.release-type-determination.outputs.is_prerelease == 'false'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: "3.X"
- name: Pull the latest solr image
run: docker pull solr:latest
- name: Get the latest solr version
id: solr
run: echo tag=$(docker inspect solr:latest -f '{{index .Config.Labels "org.opencontainers.image.version"}}') >> $GITHUB_OUTPUT
- name: Get tag
id: repository
run: |
echo "repo=$(echo ${{ github.repository }}|tr 'A-Z' 'a-z')" >> $GITHUB_OUTPUT
echo "tag=$(python freva-rest/src/freva_rest/__init__.py)" >> $GITHUB_OUTPUT
- name: Installing dependencies
run: pip install git-python packaging tomli requests
- name: Getting realease job
run: curl -Ls -o bump.py https://raw.githubusercontent.com/FREVA-CLINT/freva-deployment/main/release.py
- name: Do the release job
run: python3 bump.py deploy freva_rest -p freva-rest -v -s solr ${{steps.solr.outputs.tag}}
env:
GITHUB_TOKEN: ${{secrets.ACCESS_TOKEN}}
REPO_VERSION: ${{ steps.repository.outputs.tag }}