Skip to content

Commit

Permalink
[skip ci] revamp github actions release and lint workflow
Browse files Browse the repository at this point in the history
- use hatch build system
- use pypi trusted publisher upload method
- update checkout action version
- use artifacts on each run
  • Loading branch information
jack-mil committed Jul 18, 2024
1 parent 3bdec7c commit ef85b98
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 82 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ jobs:
name: Run Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- uses: actions/setup-python@v4
- name: Checkout code
uses: actions/checkout@v4
with:
python-version: '3.x'
cache: "poetry"
fetch-depth: 0

- name: Install dependencies
run: poetry install --only dev
- name: Set up Python >= 3.10
uses: actions/setup-python@v5
with:
python-version: '>=3.10'
cache: pip

- name: Run black
run: poetry run black --check --verbose .
- name: Install ruff
run: pip install ruff

- name: Run flake8
run: poetry run flake8 --statistics
- name: Run ruff lint
run: ruff check --output-format=github .

- name: Run isort
run: poetry run isort -cv .
- name: Run ruff format
run: ruff format --check .
132 changes: 67 additions & 65 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
name: Release

on:
workflow_dispatch:
inputs:
testing:
description: 'Publish to PyPI testing'
required: true
type: boolean
push:
branches: [master, develop]
tags:
- "v*.*.*"

jobs:
release:
name: Publish Release
build:
name: Build Distribution
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install poetry
run: pipx install poetry
- name: Set up Python >= 3.10
uses: actions/setup-python@v5
with:
python-version: '>=3.10'
cache: pip

- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'poetry'
- name: Install hatch
run: pip install -U hatch hatch-vcs

- name: Build project for distribution
run: poetry build
- name: Build Project
run: hatch build

- name: Get Package Version
id: check-version
run: |
VERSION=$(poetry version --short)
echo "version=v$VERSION" >> $GITHUB_ENV
[[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> $GITHUB_OUTPUT
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: bing-rewards
path: dist/

- name: Setup Git Config
run: |
git config user.name "Github Actions"
git config user.email "<[email protected]>"
publish:
name: Publish to Test PyPI
runs-on: ubuntu-latest
needs:
- build
# if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
environment:
name: testpypi
url: https://test.pypi.org/p/bing-rewards
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bing-rewards
path: dist/

- name: Create Github Release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ env.version }}"
prerelease: ${{ steps.check-version.outputs.prerelease == 'true' }}
draft: true
files: |
dist/*
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

- name: Publish to Test PyPI
if: ${{ inputs.testing }}
env:
POETRY_TEST_PYPI_TOKEN: ${{ secrets.PYPI_TESTING_API_TOKEN }}
run: |
poetry config repositories.testpypi "https://test.pypi.org/legacy/"
poetry config pypi-token.testpypi $POETRY_TEST_PYPI_TOKEN
poetry publish -r testpypi
release:
name: Create Github Release
runs-on: ubuntu-latest
needs:
- build
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Publish to PyPI
if: ${{ ! inputs.testing && (steps.check-version.outputs.prerelease != 'true') }}
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry publish
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bing-rewards
path: dist/

- name: Bump Dev Version
if: ${{ ! inputs.testing }}
run: |
git checkout develop
git merge origin/master --no-ff
poetry version minor
git add pyproject.toml
git commit -m "[skip ci] Bump version to v$(poetry version --short)" --no-verify
git push origin develop
- name: Create Github Release
uses: softprops/action-gh-release@v2
with:
files: dist/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
fail_fast: true
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ build-backend = "hatchling.build"
[tool.hatch.version]
source = "vcs"
fallback-version = "UNKNOWN"
raw-options = {local_scheme = 'no-local-version'}

[tool.hatch.build.targets.sdist]
exclude = [
Expand Down

0 comments on commit ef85b98

Please sign in to comment.