Skip to content

Fix 28 histology info (#29) #13

Fix 28 histology info (#29)

Fix 28 histology info (#29) #13

name: Tag and publish
on:
push:
branches:
- main
jobs:
update_badges:
runs-on: ubuntu-latest
continue-on-error: true
defaults:
run:
working-directory: ./aind-slims-service-server
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.DEFAULT_BRANCH }}
fetch-depth: 0
token: ${{ secrets.SERVICE_TOKEN }}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install -e .[dev] --no-cache-dir
- name: Get Python version and Update README.md
run: |
python_version=$(grep "requires-python" pyproject.toml | grep -o ">=[^\"]*")
python_badge=$(grep '^\!\[Python\]' README.md | sed -n 's/.*\(python-[^)]*\).*/\1/p')
new_python_badge="python-$python_version-blue?logo=python"
sed -i "s/$python_badge/$new_python_badge/g" README.md
- name: Get interrogate values and Update README.md
run: |
interrogate_val=$(interrogate . | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}')
interrogate_badge=$(grep '^\!\[Interrogate\]' README.md | sed -n 's/.*\(interrogate-[^)]*\).*/\1/p')
if (( $(echo "$interrogate_val >= 90.00" | bc -l) )); then
new_interrogate_badge="interrogate-$interrogate_val%25-brightgreen"
elif (( $(echo "$interrogate_val < 80.00" | bc -l) )); then
new_interrogate_badge="interrogate-$interrogate_val%25-red"
else
new_interrogate_badge="interrogate-$interrogate_val%25-yellow"
fi
sed -i "s/$interrogate_badge/$new_interrogate_badge/g" README.md
- name: Get Coverage values and Update README.md
run: |
coverage run -m pytest
coverage_val=$(coverage report | grep "^TOTAL" | grep -o '[0-9]\+%' | grep -o '[0-9]\+')
coverage_badge=$(grep '^\!\[Coverage\]' README.md | sed -n 's/.*\(coverage-[^)]*\).*/\1/p')
if (( $(echo "$coverage_val >= 90.00" | bc -l) )); then
new_coverage_badge="coverage-$coverage_val%25-brightgreen"
elif (( $(echo "$coverage_val < 80.00" | bc -l) )); then
new_coverage_badge="coverage-$coverage_val%25-red"
else
new_coverage_badge="coverage-$coverage_val%25-yellow"
fi
sed -i "s/$coverage_badge/$new_coverage_badge/g" README.md
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "ci: update badges [skip actions]"
add: '["aind-slims-service-server/README.md"]'
bump_version:
name: Bump version
needs: update_badges
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.output_version.outputs.new_version }}
defaults:
run:
working-directory: ./aind-slims-service-server
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.default_branch }}
fetch-depth: 0
token: ${{ secrets.SERVICE_TOKEN }}
- name: Pull latest changes
run: git pull origin main
- name: Compute new version number
id: tag_version
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.SERVICE_TOKEN }}
release_branches: ${{ inputs.default_branch }}
default_bump: patch
dry_run: true # Perform dryrun first to calculate new version
- name: Get version file name set variables
run: |
pkg_name=$(grep -P 'version = \{attr = .*\}' pyproject.toml | grep -oP '\w+.__version__')
init_file="./src/${pkg_name//.__version__}/__init__.py"
pkg_version=$(grep -Po '[0-9]+\.[0-9]+\.[0-9]+' "$init_file")
abs_init_file_path="aind-slims-service-server/${init_file}"
echo "VERSION_FILE=$init_file" >> "$GITHUB_ENV"
echo "ABS_VERSION_FILE=$abs_init_file_path" >> "$GITHUB_ENV"
echo "VERSION=${{ steps.tag_version.outputs.new_version }}" >> "$GITHUB_ENV"
- name: Update version file with new version
run: |
grep "__version__" "$VERSION_FILE"
sed -i --debug --expression="s|__version__.*|__version__ = \"${{ env.VERSION }}\"|" "$VERSION_FILE"
- name: Set output
id: output_version
run: echo "new_version=${{ env.VERSION }}" >> "$GITHUB_OUTPUT"
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "ci: version bump [skip actions]"
add: ${{ env.ABS_VERSION_FILE }}
build_client:
runs-on: ubuntu-latest
needs: bump_version
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.default_branch }}
fetch-depth: 0
token: ${{ secrets.SERVICE_TOKEN }}
- name: Pull latest changes
run: git pull origin main
- name: Update version
run: |
sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc.json
sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc_async.json
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install -e aind-slims-service-server --no-cache-dir
python -m pip install toml
- name: Generate OpenAPI file
run: |
python scripts/generate_openapi.py
- name: Generate Python Client
uses: openapi-generators/openapitools-generator-action@v1.5.0
with:
generator: python
generator-tag: v7.13.0
openapi-file: openapi.json
config-file: openapirc.json
- name: Handle files
run: |
rm -rf aind-slims-service-client
mv python-client aind-slims-service-client
rm -rf aind-slims-service-client/.github
rm -f aind-slims-service-client/.gitignore
rm -f aind-slims-service-client/.gitlab-ci.yml
rm -f aind-slims-service-client/git_push.sh
rm -f aind-slims-service-client/.travis.yml
- name: Generate Python Async Client
uses: openapi-generators/openapitools-generator-action@v1.5.0
with:
generator: python
generator-tag: v7.13.0
openapi-file: openapi.json
config-file: openapirc_async.json
- name: Handle async files
run: |
rm -rf aind-slims-service-async-client
mv python-client aind-slims-service-async-client
rm -rf aind-slims-service-async-client/.github
rm -f aind-slims-service-async-client/.gitignore
rm -f aind-slims-service-async-client/.gitlab-ci.yml
rm -f aind-slims-service-async-client/git_push.sh
rm -f aind-slims-service-async-client/.travis.yml
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "ci: add clients [skip actions]"
add: '["openapirc.json","aind-slims-service-client","openapirc_async.json","aind-slims-service-async-client"]'
update_tag:
runs-on: ubuntu-latest
needs: [bump_version, build_client]
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin main
- name: Update tag
run: |
git tag v${{ needs.bump_version.outputs.new_version }}
git push origin v${{ needs.bump_version.outputs.new_version }}
publish_server:
runs-on: ubuntu-latest
needs: [bump_version, update_tag]
defaults:
run:
working-directory: ./aind-slims-service-server
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin main
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: ./aind-slims-service-server
push: true
tags: |
ghcr.io/allenneuraldynamics/aind-slims-service-server:${{ needs.bump_version.outputs.new_version }}
ghcr.io/allenneuraldynamics/aind-slims-service-server:latest
publish_client:
runs-on: ubuntu-latest
needs: update_tag
defaults:
run:
working-directory: ./aind-slims-service-client
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin main
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install --upgrade setuptools wheel twine build
python -m build
twine check dist/*
- name: Publish on PyPI
uses: pypa/gh-action-pypi-publish@release/v1.12
with:
packages-dir: ./aind-slims-service-client/dist
password: ${{ secrets.AIND_PYPI_TOKEN }}
publish_async_client:
runs-on: ubuntu-latest
needs: update_tag
defaults:
run:
working-directory: ./aind-slims-service-async-client
steps:
- uses: actions/checkout@v4
- name: Pull latest changes
run: git pull origin main
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install --upgrade setuptools wheel twine build
python -m build
twine check dist/*
- name: Publish on PyPI
uses: pypa/gh-action-pypi-publish@release/v1.12
with:
packages-dir: ./aind-slims-service-async-client/dist
password: ${{ secrets.AIND_PYPI_TOKEN }}