Skip to content

fix: use GITHUB_TOKEN for semantic-release push permissions #5

fix: use GITHUB_TOKEN for semantic-release push permissions

fix: use GITHUB_TOKEN for semantic-release push permissions #5

Workflow file for this run

name: CI/CD
on:
push:
branches: [master, main]
pull_request:
branches: [master, main]
permissions:
contents: write
id-token: write
pages: write
jobs:
# ===========================================================================
# Run Tests
# ===========================================================================
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run tests
run: pytest tests/ -v --tb=short
# ===========================================================================
# Lint Check
# ===========================================================================
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install ruff black isort
- name: Check formatting with black
run: black --check src/LZGraphs tests || true
- name: Check imports with isort
run: isort --check-only src/LZGraphs tests || true
- name: Lint with ruff
run: ruff check src/LZGraphs tests || true
# ===========================================================================
# Release (only on push to master, after tests pass)
# ===========================================================================
release:
needs: [test, lint]
runs-on: ubuntu-latest
concurrency: release
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-semantic-release build twine
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Python Semantic Release
id: release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
semantic-release version
semantic-release publish
- name: Publish to PyPI
if: steps.release.outcome == 'success'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
if [ -d "dist" ] && [ "$(ls -A dist)" ]; then
twine upload dist/*
else
echo "No distribution files to upload"
fi
# ===========================================================================
# Deploy Documentation to GitHub Pages
# ===========================================================================
docs:
needs: [test, lint]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
- name: Install documentation dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[docs]"
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Build and deploy documentation
run: mkdocs gh-deploy --force