feat: Switch to PEP621 compliant pyproject.toml and pyproject.nix #224
Workflow file for this run
This file contains 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: Lint & release project | |
on: | |
push: | |
paths: | |
- "pyproject.toml" | |
- "poetry.lock" | |
- "tgpy/**" | |
- ".github/workflows/main.yml" | |
- ".github/workflows/docker.yml" | |
pull_request: | |
paths: | |
- "pyproject.toml" | |
- "poetry.lock" | |
- "tgpy/**" | |
- ".github/workflows/main.yml" | |
- ".github/workflows/docker.yml" | |
workflow_dispatch: {} | |
jobs: | |
Lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: DeterminateSystems/nix-installer-action@main | |
- uses: DeterminateSystems/magic-nix-cache-action@main | |
- name: Load dependency cache | |
id: load-cache | |
uses: actions/cache@v2 | |
with: | |
path: .venv | |
key: app-${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('poetry.lock') }} | |
- name: Install dependencies | |
run: | | |
nix develop -c poetry config virtualenvs.in-project true | |
nix develop -c poetry install | |
if: steps.load-cache.outputs.cache-hit != 'true' | |
- name: Check code style | |
if: github.event_name != 'push' | |
run: | | |
nix develop -c poetry run black --check --diff . | |
nix develop -c poetry run isort --check --diff . | |
- name: Reformat code | |
if: github.event_name == 'push' | |
run: | | |
nix develop -c poetry run black . | |
nix develop -c poetry run isort . | |
- name: Commit chanes | |
if: github.event_name == 'push' | |
shell: bash | |
run: | | |
if [ ! -n "$(git status --porcelain)" ]; then | |
exit | |
fi | |
git add -A | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
git commit -m "style: reformat [skip ci]" | |
git push | |
Release: | |
concurrency: release | |
needs: Lint | |
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: DeterminateSystems/nix-installer-action@main | |
- uses: DeterminateSystems/magic-nix-cache-action@main | |
- name: Load dependency cache | |
id: load-cache | |
uses: actions/cache@v2 | |
with: | |
path: .venv | |
key: app-${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('poetry.lock') }} | |
- name: Install dependencies | |
run: | | |
nix develop -c poetry config virtualenvs.in-project true | |
nix develop -c poetry install --with release | |
if: steps.load-cache.outputs.cache-hit != 'true' | |
- name: Release | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
run: | | |
source .venv/bin/activate | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
export GH_TOKEN="${GITHUB_TOKEN}" | |
export REPOSITORY_USERNAME="__token__" | |
export REPOSITORY_PASSWORD="${PYPI_TOKEN}" | |
python -m semantic_release publish -D commit_author="github-actions <[email protected]>" | |
- name: Save release commit hash | |
id: release-commit-hash | |
run: echo "::set-output name=release-commit-hash::$(git rev-parse HEAD)" | |
outputs: | |
release-commit-hash: ${{ steps.release-commit-hash.outputs.release-commit-hash }} | |
Build-dev-docker: | |
needs: Lint | |
name: Build dev docker image | |
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref != 'refs/heads/master' | |
uses: ./.github/workflows/docker.yml | |
secrets: inherit | |
Build-release-docker: | |
name: Build release docker image | |
needs: Release | |
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master' | |
uses: ./.github/workflows/docker.yml | |
with: | |
commit-hash: ${{ needs.Release.outputs.release-commit-hash }} | |
secrets: inherit |