1+ name : Tag and publish
2+ on :
3+ push :
4+ branches :
5+ - main
6+
7+ jobs :
8+ update_badges :
9+ runs-on : ubuntu-latest
10+ continue-on-error : true
11+ defaults :
12+ run :
13+ working-directory : ./aind-dataverse-service-server
14+ steps :
15+ - uses : actions/checkout@v4
16+ with :
17+ ref : ${{ env.DEFAULT_BRANCH }}
18+ fetch-depth : 0
19+ token : ${{ secrets.SERVICE_TOKEN }}
20+ - name : Set up Python 3.10
21+ uses : actions/setup-python@v5
22+ with :
23+ python-version : ' 3.10'
24+ - name : Install dependencies
25+ run : |
26+ python -m pip install -e .[dev] --no-cache-dir
27+ - name : Get Python version and Update README.md
28+ run : |
29+ python_version=$(grep "requires-python" pyproject.toml | grep -o ">=[^\"]*")
30+ python_badge=$(grep '^\!\[Python\]' README.md | sed -n 's/.*\(python-[^)]*\).*/\1/p')
31+ new_python_badge="python-$python_version-blue?logo=python"
32+ sed -i "s/$python_badge/$new_python_badge/g" README.md
33+ - name : Get interrogate values and Update README.md
34+ run : |
35+ interrogate_val=$(interrogate . | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}')
36+ interrogate_badge=$(grep '^\!\[Interrogate\]' README.md | sed -n 's/.*\(interrogate-[^)]*\).*/\1/p')
37+ if (( $(echo "$interrogate_val >= 90.00" | bc -l) )); then
38+ new_interrogate_badge="interrogate-$interrogate_val%25-brightgreen"
39+ elif (( $(echo "$interrogate_val < 80.00" | bc -l) )); then
40+ new_interrogate_badge="interrogate-$interrogate_val%25-red"
41+ else
42+ new_interrogate_badge="interrogate-$interrogate_val%25-yellow"
43+ fi
44+ sed -i "s/$interrogate_badge/$new_interrogate_badge/g" README.md
45+ - name : Get Coverage values and Update README.md
46+ run : |
47+ coverage run -m pytest
48+ coverage_val=$(coverage report | grep "^TOTAL" | grep -o '[0-9]\+%' | grep -o '[0-9]\+')
49+ coverage_badge=$(grep '^\!\[Coverage\]' README.md | sed -n 's/.*\(coverage-[^)]*\).*/\1/p')
50+ if (( $(echo "$coverage_val >= 90.00" | bc -l) )); then
51+ new_coverage_badge="coverage-$coverage_val%25-brightgreen"
52+ elif (( $(echo "$coverage_val < 80.00" | bc -l) )); then
53+ new_coverage_badge="coverage-$coverage_val%25-red"
54+ else
55+ new_coverage_badge="coverage-$coverage_val%25-yellow"
56+ fi
57+ sed -i "s/$coverage_badge/$new_coverage_badge/g" README.md
58+ - name : Commit changes
59+ uses : EndBug/add-and-commit@v9
60+ with :
61+ default_author : github_actions
62+ message : " ci: update badges [skip actions]"
63+ add : ' ["aind-dataverse-service-server/README.md"]'
64+ bump_version :
65+ name : Bump version
66+ needs : update_badges
67+ runs-on : ubuntu-latest
68+ outputs :
69+ new_version : ${{ steps.output_version.outputs.new_version }}
70+ defaults :
71+ run :
72+ working-directory : ./aind-dataverse-service-server
73+ steps :
74+ - name : Checkout
75+ uses : actions/checkout@v4
76+ with :
77+ ref : ${{ inputs.default_branch }}
78+ fetch-depth : 0
79+ token : ${{ secrets.SERVICE_TOKEN }}
80+ - name : Pull latest changes
81+ run : git pull origin main
82+ - name : Compute new version number
83+ id : tag_version
84+ uses : mathieudutour/github-tag-action@v6.2
85+ with :
86+ github_token : ${{ secrets.SERVICE_TOKEN }}
87+ release_branches : ${{ inputs.default_branch }}
88+ default_bump : patch
89+ dry_run : true # Perform dryrun first to calculate new version
90+ - name : Get version file name set variables
91+ run : |
92+ pkg_name=$(grep -P 'version = \{attr = .*\}' pyproject.toml | grep -oP '\w+.__version__')
93+ init_file="./src/${pkg_name//.__version__}/__init__.py"
94+ pkg_version=$(grep -Po '[0-9]+\.[0-9]+\.[0-9]+' "$init_file")
95+ abs_init_file_path="aind-dataverse-service-server/${init_file}"
96+ echo "VERSION_FILE=$init_file" >> "$GITHUB_ENV"
97+ echo "ABS_VERSION_FILE=$abs_init_file_path" >> "$GITHUB_ENV"
98+ echo "VERSION=${{ steps.tag_version.outputs.new_version }}" >> "$GITHUB_ENV"
99+ - name : Update version file with new version
100+ run : |
101+ grep "__version__" "$VERSION_FILE"
102+ sed -i --debug --expression="s|__version__.*|__version__ = \"${{ env.VERSION }}\"|" "$VERSION_FILE"
103+ - name : Set output
104+ id : output_version
105+ run : echo "new_version=${{ env.VERSION }}" >> "$GITHUB_OUTPUT"
106+ - name : Commit changes
107+ uses : EndBug/add-and-commit@v9
108+ with :
109+ default_author : github_actions
110+ message : " ci: version bump [skip actions]"
111+ add : ${{ env.ABS_VERSION_FILE }}
112+ build_client :
113+ runs-on : ubuntu-latest
114+ needs : bump_version
115+ steps :
116+ - uses : actions/checkout@v4
117+ with :
118+ ref : ${{ inputs.default_branch }}
119+ fetch-depth : 0
120+ token : ${{ secrets.SERVICE_TOKEN }}
121+ - name : Pull latest changes
122+ run : git pull origin main
123+ - name : Update version
124+ run : |
125+ sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc.json
126+ sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc_async.json
127+ - name : Set up Python 3.10
128+ uses : actions/setup-python@v5
129+ with :
130+ python-version : ' 3.10'
131+ - name : Install dependencies
132+ run : |
133+ python -m pip install -e aind-dataverse-service-server --no-cache-dir
134+ python -m pip install toml
135+ - name : Generate OpenAPI file
136+ run : |
137+ python scripts/generate_openapi.py
138+ - name : Generate Python Client
139+ uses : openapi-generators/openapitools-generator-action@v1.5.0
140+ with :
141+ generator : python
142+ generator-tag : v7.13.0
143+ openapi-file : openapi.json
144+ config-file : openapirc.json
145+ - name : Handle files
146+ run : |
147+ rm -rf aind-dataverse-service-client
148+ mv python-client aind-dataverse-service-client
149+ rm -rf aind-dataverse-service-client/.github
150+ rm -f aind-dataverse-service-client/.gitignore
151+ rm -f aind-dataverse-service-client/.gitlab-ci.yml
152+ rm -f aind-dataverse-service-client/git_push.sh
153+ rm -f aind-dataverse-service-client/.travis.yml
154+ - name : Generate Python Async Client
155+ uses : openapi-generators/openapitools-generator-action@v1.5.0
156+ with :
157+ generator : python
158+ generator-tag : v7.13.0
159+ openapi-file : openapi.json
160+ config-file : openapirc_async.json
161+ - name : Handle async files
162+ run : |
163+ rm -rf aind-dataverse-service-async-client
164+ mv python-client aind-dataverse-service-async-client
165+ rm -rf aind-dataverse-service-async-client/.github
166+ rm -f aind-dataverse-service-async-client/.gitignore
167+ rm -f aind-dataverse-service-async-client/.gitlab-ci.yml
168+ rm -f aind-dataverse-service-async-client/git_push.sh
169+ rm -f aind-dataverse-service-async-client/.travis.yml
170+ - name : Commit changes
171+ uses : EndBug/add-and-commit@v9
172+ with :
173+ default_author : github_actions
174+ message : " ci: add clients [skip actions]"
175+ add : ' ["openapirc.json","aind-dataverse-service-client","openapirc_async.json","aind-dataverse-service-async-client"]'
176+ update_tag :
177+ runs-on : ubuntu-latest
178+ needs : [bump_version, build_client]
179+ steps :
180+ - uses : actions/checkout@v4
181+ - name : Pull latest changes
182+ run : git pull origin main
183+ - name : Update tag
184+ run : |
185+ git tag v${{ needs.bump_version.outputs.new_version }}
186+ git push origin v${{ needs.bump_version.outputs.new_version }}
187+ publish_server :
188+ runs-on : ubuntu-latest
189+ needs : [bump_version, update_tag]
190+ defaults :
191+ run :
192+ working-directory : ./aind-dataverse-service-server
193+ steps :
194+ - uses : actions/checkout@v4
195+ - name : Pull latest changes
196+ run : git pull origin main
197+ - name : Set up Docker Buildx
198+ id : buildx
199+ uses : docker/setup-buildx-action@v2
200+ - name : Login to Github Packages
201+ uses : docker/login-action@v2
202+ with :
203+ registry : ghcr.io
204+ username : ${{ github.actor }}
205+ password : ${{ secrets.GITHUB_TOKEN }}
206+ - name : Build image and push to GitHub Container Registry
207+ uses : docker/build-push-action@v3
208+ with :
209+ # relative path to the place where source code with Dockerfile is located
210+ context : ./aind-dataverse-service-server
211+ push : true
212+ tags : |
213+ ghcr.io/allenneuraldynamics/aind-dataverse-service-server:${{ needs.bump_version.outputs.new_version }}
214+ ghcr.io/allenneuraldynamics/aind-dataverse-service-server:latest
215+ publish_client :
216+ runs-on : ubuntu-latest
217+ needs : update_tag
218+ defaults :
219+ run :
220+ working-directory : ./aind-dataverse-service-client
221+ steps :
222+ - uses : actions/checkout@v4
223+ - name : Pull latest changes
224+ run : git pull origin main
225+ - name : Set up Python 3.10
226+ uses : actions/setup-python@v5
227+ with :
228+ python-version : ' 3.10'
229+ - name : Install dependencies
230+ run : |
231+ pip install --upgrade setuptools wheel twine build
232+ python -m build
233+ twine check dist/*
234+ - name : Publish on PyPI
235+ uses : pypa/gh-action-pypi-publish@release/v1.12
236+ with :
237+ packages-dir : ./aind-dataverse-service-client/dist
238+ password : ${{ secrets.AIND_PYPI_TOKEN }}
239+ publish_async_client :
240+ runs-on : ubuntu-latest
241+ needs : update_tag
242+ defaults :
243+ run :
244+ working-directory : ./aind-dataverse-service-async-client
245+ steps :
246+ - uses : actions/checkout@v4
247+ - name : Pull latest changes
248+ run : git pull origin main
249+ - name : Set up Python 3.10
250+ uses : actions/setup-python@v5
251+ with :
252+ python-version : ' 3.10'
253+ - name : Install dependencies
254+ run : |
255+ pip install --upgrade setuptools wheel twine build
256+ python -m build
257+ twine check dist/*
258+ - name : Publish on PyPI
259+ uses : pypa/gh-action-pypi-publish@release/v1.12
260+ with :
261+ packages-dir : ./aind-dataverse-service-async-client/dist
262+ password : ${{ secrets.AIND_PYPI_TOKEN }}
0 commit comments