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