Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance CI/CD Workflow with TestPyPI Publishing, Linting Improvements, and minor docs update #42

Merged
merged 13 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 89 additions & 41 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ name: CI-CD

# only run on pushes to main or pull requests
on:
push:
# push to any branch *
branches: ["*"]
# push:
# push to any branch *
# branches: ["*"]
pull_request:
branches: [main, development]

branches: ["*"]

jobs:
################################################################################################
Expand Down Expand Up @@ -69,6 +68,30 @@ jobs:
verbose: true
name: codecov-umbrella

################################################################################################
# Ruff: Run ruff linter
################################################################################################
Ruff:
runs-on: ubuntu-latest
env:
PIXI_ENV: "dev"
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
environments: ${{ env.PIXI_ENV }}
pixi-version: v0.33.0
cache: true
locked: false

- name: Run Ruff
run: pixi run lint

################################################################################################
# Semantic-Release: Run semantic-release to automate versioning and publishing
################################################################################################
Expand All @@ -80,7 +103,7 @@ jobs:
issues: write
pull-requests: write

needs: [Unit-Tests]
needs: [Unit-Tests, Ruff]

# if pulling to main, deploy to PyPI
if: github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -119,54 +142,79 @@ jobs:
environments: ${{ env.PIXI_ENV }}
pixi-version: v0.33.0
cache: true
locked: false
locked: false
# cache-key: pixi-ENV_${{ env.PIXI_ENV }}-

- name: Print Semver
env:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pixi run semver

- name: Run semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: release
run: pixi run release

- name: Test Outputs of semantic release step
run: |
echo "${{ steps.release.outputs.released }}"
echo "${{ steps.release.outputs.version }}"
echo "${{ steps.release.outputs.tag }}"
################################################################################################
###############################################################################################
# Publish-To-PyPi & Test-PyPi-Installation: Publish to PyPI and test installation
################################################################################################
# Publish-To-PyPi:
# needs: Semantic-Release
# env:
# PIXI_ENV: "publish"
# # if: needs.Semantic-Release.outputs.released == 'true'
# strategy:
# matrix:
# os: [ubuntu-latest]

# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout the code with tag ${{ needs.Semantic-Release.outputs.tag }}
# uses: actions/checkout@v4
# with:
# ref: ${{ needs.Semantic-Release.outputs.tag }}

# - name: Install Pixi
# uses: prefix-dev/setup-pixi@v0.8.1
# with:
# environments: ${{ env.PIXI_ENV }}
# pixi-version: v0.33.0
# # cache-key: pixi-ENV_${{ env.PIXI_ENV }}-
# cache: true
# locked: false # wont be the same because of the tag

# - name: Test Build
# run: |
# pixi run -e ${{ env.PIXI_ENV }} build
###############################################################################################
Publish-To-Test-PyPi:
needs: Semantic-Release
env:
PIXI_ENV: "publish"
if: needs.Semantic-Release.outputs.released == 'true'
strategy:
matrix:
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout the code with tag ${{ needs.Semantic-Release.outputs.tag }}
uses: actions/checkout@v4
with:
ref: ${{ needs.Semantic-Release.outputs.tag }}

- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
environments: ${{ env.PIXI_ENV }}
pixi-version: v0.33.0
cache: true
locked: false # wont be the same because of the tag

- name: Publish to TestPyPI
env:
HATCH_INDEX_USER: __token__
HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
pixi run -e ${{ env.PIXI_ENV }} publish-test
Test-TestPypi-Installation:
needs: [Semantic-Release, Publish-To-Test-PyPi]
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.12"]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout the code with tag ${{ needs.Semantic-Release.outputs.tag }}
uses: actions/checkout@v4
with:
ref: ${{ needs.Semantic-Release.outputs.tag }}

- name: setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install using TestPyPI
run: |
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ readii
15 changes: 8 additions & 7 deletions config/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ extend-exclude = [

extend-include = []

include = [
"src/readii/loaders.py"
]

[lint]
select = [
Expand All @@ -24,20 +27,18 @@ select = [
"W", # flake8
"C", # mccabe
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
# "N", # pep8-naming
"ANN", # flake8-annotations
"BLE", # flake8-blind-except
"B", # flake8-bugbear
"A", # flake8-builtins
"G", # flake8-logging-format
# "G", # flake8-logging-format
"ERA", # eradicate
"RUF", # Ruff-specific rules
"TCH", # flake8-type-checking
]
ignore = ["ANN101"]
unfixable = [
"ERA", # Don't remove commented-out code
]


[lint.per-file-ignores]
Expand All @@ -57,10 +58,10 @@ relative-imports-order = "closest-to-furthest"


[lint.pydocstyle]
convention = "google"
convention = "numpy"


[format]
quote-style = "single"
quote-style = "double"
docstring-code-format = true
docstring-code-line-length = 20
16 changes: 1 addition & 15 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 40 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ myst-nb = "*"
sphinx-autoapi = "*"
sphinx-rtd-theme = "*"


# TODO::add tasks to build documentation

############################################## STYLE ###############################################
Expand All @@ -80,11 +79,37 @@ sphinx-rtd-theme = "*"
ruff = ">=0.4.4"
pre-commit = ">=3.7.1,<3.8"

# TODO::add tasks to run style checks
# as of 10-21-2024, `ruff check` has 152 errors
[tool.pixi.feature.style.tasks]
[tool.pixi.feature.style.tasks.lint]
cmd = "ruff check --config=config/ruff.toml"
inputs = ["src", "config/ruff.toml"]
description = "Run ruff linter"

[tool.pixi.feature.style.tasks.format]
cmd = "ruff format --config=config/ruff.toml"
inputs = ["src", "config/ruff.toml"]
description = "Run ruff formatter, use `--diff` to see changes only"

#################################### RELEASE & BUILD ###############################################

[tool.pixi.feature.release.dependencies]
python-semantic-release = "*"

[tool.pixi.feature.release.tasks]
semver = 'echo "Next Version is: $(semantic-release version --print)"'
release = "semantic-release version"

[tool.semantic_release]
version_variables = ["src/readii/__init__.py:__version__"]
version_toml = ["pyproject.toml:project.version"] # version location
changelog_file = "CHANGELOG.md" # changelog file
dist_path = "dist/" # where to put dists
upload_to_release = true # auto-create GitHub release
remove_dist = false # don't remove dists
patch_without_tag = true # patch release by default

[tool.semantic_release.branches.main]
match = "(main|development)"

[tool.pixi.feature.build.dependencies]
hatch = "*"
Expand All @@ -93,7 +118,6 @@ hatch = "*"
build-backend = "hatchling.build"
requires = ["hatchling"]


[tool.pixi.feature.build.tasks]
# Builds the package
build = { cmd = [
Expand All @@ -106,26 +130,16 @@ build = { cmd = [
"pyproject.toml",
], outputs = [
"dist/*",
], env = { HATCH_CONFIG = "config/hatch.toml" } }


], env = { HATCH_CONFIG = "config/hatch.toml" }, description = "Build the package" }

[tool.pixi.feature.release.dependencies]
python-semantic-release = "*"

[tool.pixi.feature.release.tasks]
# Semver task will only work on the main or dev/develop branch (see releaserc.toml:branches)
semver = 'echo "Next Version is: $(semantic-release version --print)"'
release = "semantic-release version"

[tool.semantic_release]
version_variables = ["src/readii/__init__.py:__version__"]
version_toml = ["pyproject.toml:tool.poetry.version"] # version location
changelog_file = "CHANGELOG.md" # changelog file
dist_path = "dist/" # where to put dists
upload_to_release = true # auto-create GitHub release
remove_dist = false # don't remove dists
patch_without_tag = true # patch release by default

[tool.semantic_release.branches.main]
match = "*"
publish-test = { cmd = [
"hatch",
"publish",
"--yes",
"--repo",
"test",
], inputs = [
"dist/*",
], depends-on = [
"build",
], env = { HATCH_CONFIG = "config/hatch.toml" }, description = "Publish to test PyPI" }
Loading
Loading