|
| 1 | +name: Tag and publish |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | +# Remove line 67 to enable automated semantic version bumps. |
| 7 | +# Requires that svc-aindscicomp be added to the repo with "write" role. |
| 8 | + |
| 9 | +# Change line 73 from "if: false" to "if: true" to enable PyPI publishing. |
| 10 | +# Requires that the repo has been added as a Trusted Publisher in the PyPI. |
| 11 | +# Please submit a request to Scientific Computing to add the Trusted Publisher. |
| 12 | +jobs: |
| 13 | + update_badges: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + continue-on-error: true |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v6 |
| 18 | + with: |
| 19 | + ref: ${{ env.DEFAULT_BRANCH }} |
| 20 | + fetch-depth: 0 |
| 21 | + token: ${{ secrets.SERVICE_TOKEN }} |
| 22 | + - name: Set up Python 3.10 |
| 23 | + uses: astral-sh/setup-uv@v7 |
| 24 | + with: |
| 25 | + python-version: '3.10' |
| 26 | + - name: Install dependencies |
| 27 | + run: uv sync |
| 28 | + - name: Get Python version and Update README.md |
| 29 | + run: | |
| 30 | + python_version=$(grep "requires-python" pyproject.toml | grep -o ">=[^\"]*") |
| 31 | + python_badge=$(grep '^\!\[Python\]' README.md | sed -n 's/.*\(python-[^)]*\).*/\1/p') |
| 32 | + new_python_badge="python-$python_version-blue?logo=python" |
| 33 | + sed -i "s/$python_badge/$new_python_badge/g" README.md |
| 34 | + - name: Get interrogate values and Update README.md |
| 35 | + run: | |
| 36 | + interrogate_val=$(uv run interrogate . | grep -o 'actual: [0-9]*\.[0-9]*' | awk '{print $2}') |
| 37 | + interrogate_badge=$(grep '^\!\[Interrogate\]' README.md | sed -n 's/.*\(interrogate-[^)]*\).*/\1/p') |
| 38 | + if (( $(echo "$interrogate_val >= 90.00" | bc -l) )); then |
| 39 | + new_interrogate_badge="interrogate-$interrogate_val%25-brightgreen" |
| 40 | + elif (( $(echo "$interrogate_val < 80.00" | bc -l) )); then |
| 41 | + new_interrogate_badge="interrogate-$interrogate_val%25-red" |
| 42 | + else |
| 43 | + new_interrogate_badge="interrogate-$interrogate_val%25-yellow" |
| 44 | + fi |
| 45 | + sed -i "s/$interrogate_badge/$new_interrogate_badge/g" README.md |
| 46 | + - name: Get Coverage values and Update README.md |
| 47 | + run: | |
| 48 | + uv run coverage run -m unittest discover |
| 49 | + coverage_val=$(uv run coverage report | grep "^TOTAL" | grep -o '[0-9]\+%' | grep -o '[0-9]\+') |
| 50 | + coverage_badge=$(grep '^\!\[Coverage\]' README.md | sed -n 's/.*\(coverage-[^)]*\).*/\1/p') |
| 51 | + if (( $(echo "$coverage_val >= 90.00" | bc -l) )); then |
| 52 | + new_coverage_badge="coverage-$coverage_val%25-brightgreen" |
| 53 | + elif (( $(echo "$coverage_val < 80.00" | bc -l) )); then |
| 54 | + new_coverage_badge="coverage-$coverage_val%25-red" |
| 55 | + else |
| 56 | + new_coverage_badge="coverage-$coverage_val%25-yellow" |
| 57 | + fi |
| 58 | + sed -i "s/$coverage_badge/$new_coverage_badge/g" README.md |
| 59 | + - name: Commit changes |
| 60 | + uses: EndBug/add-and-commit@v9 |
| 61 | + with: |
| 62 | + default_author: github_actions |
| 63 | + message: "ci: update badges [skip actions]" |
| 64 | + add: '["README.md"]' |
| 65 | + tag: |
| 66 | + needs: update_badges |
| 67 | + if: ${{github.event.repository.name == 'aind-library-template'}} |
| 68 | + uses: AllenNeuralDynamics/.github/.github/workflows/release-bump-version-uv.yml@main |
| 69 | + secrets: |
| 70 | + repo-token: ${{ secrets.SERVICE_TOKEN }} |
| 71 | + publish: |
| 72 | + needs: tag |
| 73 | + if: false |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + # IMPORTANT: this permission is mandatory for Trusted Publishing |
| 78 | + id-token: write |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v6 |
| 81 | + - name: Pull latest changes |
| 82 | + run: git pull origin main |
| 83 | + - name: Set up Python 3.10 |
| 84 | + uses: astral-sh/setup-uv@v7 |
| 85 | + with: |
| 86 | + python-version: '3.10' |
| 87 | + - name: Build and validate package |
| 88 | + run: | |
| 89 | + uv build |
| 90 | + uvx twine check dist/* |
| 91 | + - name: Publish on PyPI |
| 92 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments