Merge pull request #4 from xixu-me/alert-autofix-2 #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: [main, develop] | |
pull_request: | |
branches: [main] | |
release: | |
types: [published] | |
jobs: | |
test: | |
permissions: | |
contents: read | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
python-version: ["3.12", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e .[dev] | |
- name: Lint with ruff | |
run: | | |
ruff check src tests | |
- name: Format check with ruff | |
run: | | |
ruff format --check src tests | |
- name: Run tests | |
run: | | |
pytest --cov=tzst --cov-branch --cov-report=xml | |
- name: Upload coverage to Codecov | |
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
slug: xixu-me/tzst | |
build: | |
needs: test | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build twine | |
- name: Build package | |
run: python -m build | |
- name: Check package | |
run: twine check dist/* | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name == 'release' && github.event.action == 'published' | |
environment: | |
name: pypi | |
url: https://pypi.org/p/tzst | |
permissions: | |
id-token: write | |
steps: | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
update_badges: | |
needs: [build, publish] | |
if: always() && needs.build.result == 'success' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} | |
- name: Wait if this is after a publish | |
if: github.event_name == 'release' && github.event.action == 'published' | |
run: sleep 30 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Fetch PyPI version | |
id: pypi_version | |
run: | | |
pip install requests | |
python -c " | |
import requests, json, os | |
try: | |
data = requests.get('https://pypi.org/pypi/tzst/json').json() | |
version = data['info']['version'] | |
print(f'PyPI version: {version}') | |
except Exception as e: | |
print(f'Error fetching version: {e}') | |
version = 'unknown' | |
with open(os.environ['GITHUB_OUTPUT'], 'a') as f: | |
f.write(f'version={version}\n') | |
" | |
- name: Update README badge | |
run: | | |
echo "Updating PyPI badge with version: ${{ steps.pypi_version.outputs.version }}" | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
- name: Commit and push changes | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Update badges [skip ci]" | |
file_pattern: README.md | |
branch: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} |