Skip to content

Commit 5bc88f8

Browse files
Feat: Init Commit and Read Endpoints (#1)
* feat: adds server code * adds generic table read endpt and get table names (wip) * feat: finishes tests, adds github workflows and issue templates * feat: cache get table, renames routes * adds cache for get table * cleanup PR * fixes typo in readme * fix: moves github dir, some small nit fixes * linter fix * RESTful convention routes --------- Co-authored-by: Jon Young <104453205+jtyoung84@users.noreply.github.com>
1 parent fce6042 commit 5bc88f8

26 files changed

Lines changed: 1229 additions & 1 deletion
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: User story
3+
about: This template provides a basic structure for user story issues.
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
# User story
11+
As a ..., I want to ..., so I can ...
12+
13+
*Ideally, this is in the issue title, but if not, you can put it here. If so, delete this section.*
14+
15+
# Acceptance criteria
16+
- [ ] This is something that can be verified to show that this user story is satisfied.
17+
18+
# Sprint Ready Checklist
19+
- [ ] 1. Acceptance criteria defined
20+
- [ ] 2. Team understands acceptance criteria
21+
- [ ] 3. Team has defined solution / steps to satisfy acceptance criteria
22+
- [ ] 4. Acceptance criteria is verifiable / testable
23+
- [ ] 5. External / 3rd Party dependencies identified
24+
- [ ] 6. Ticket is prioritized and sized
25+
26+
# Notes
27+
*Add any helpful notes here.*
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
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 }}

.github/workflows/test_server.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run tests for server code
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- aind-dataverse-service-server/**
9+
10+
jobs:
11+
tests:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [ '3.10', '3.11', '3.12' ]
16+
defaults:
17+
run:
18+
working-directory: ./aind-dataverse-service-server
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install -e .[dev] --no-cache-dir
28+
- name: Run linter checks
29+
run: flake8 . && interrogate --verbose .
30+
- name: Run tests and coverage
31+
run: coverage run -m pytest && coverage report

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ cython_debug/
173173
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174174
# and can be added to the global gitignore or merged into this file. For a more nuclear
175175
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
176-
#.idea/
176+
.idea/
177177

178178
# Abstra
179179
# Abstra is an AI-powered process automation framework.

0 commit comments

Comments
 (0)