Skip to content

Commit

Permalink
Merge pull request #30 from lucas-labs/29-ci
Browse files Browse the repository at this point in the history
ci: πŸ”„ push-pr ci config
  • Loading branch information
lucas-labs authored Dec 29, 2023
2 parents f486546 + 885de8d commit f69c727
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 24 deletions.
7 changes: 7 additions & 0 deletions .github/actions/check-version/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3-slim
RUN pip install --upgrade pip
RUN pip install requests tomli packaging

COPY version_checker.py /version_checker.py

ENTRYPOINT ["python3", "/version_checker.py"]
29 changes: 29 additions & 0 deletions .github/actions/check-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# action.yaml
name: "poetry project configuration"
description: "get information about poetry project: version, name, description, etc."
branding:
icon: 'aperture'
color: 'green'
inputs:
pyproject-path:
description: "location of pyproject file"
required: true
default: "./pyproject.toml"
outputs:
is-local-higher:
description: "True if local version is higher than public version"
local-version:
description: "Local version of the package"
published-version:
description: "Public version of the package"
package-name:
description: "Name of the package"
package-description:
description: "Description of the package"

runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.pyproject-path }}
- ${{ inputs.test-regex }}
37 changes: 37 additions & 0 deletions .github/actions/check-version/version_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys

import tomli
from packaging import version

# def get_public_version(project_name: str, is_test = False) -> Version:
# response = requests.get(
# f'https://{"test." if is_test else ""}pypi.org/pypi/{project_name}/json'
# )
# response.raise_for_status()
# return version.parse(json.loads(response.content)['info']['version'])


if __name__ == '__main__':
pyproject_toml_path = sys.argv[1]

with open(pyproject_toml_path, 'rb') as f:
project = tomli.load(f)

print(project)

# project_version = version.parse(project['tool']['poetry']['version'])
name = project.get('tool', {}).get('poetry', {}).get('name', None)
project_version = version.parse(project.get('tool', {}).get('poetry', {}).get('version', None))
description = project.get('tool', {}).get('poetry', {}).get('description', None)
is_test = False
# public_project_version = get_public_version(project['project']['name'], is_test)

with open(os.environ['GITHUB_OUTPUT'], 'at') as f:
# f.write(
# f'local_version_is_higher={str(project_version > public_project_version).lower()}\n'
# )
# f.write(f'public_version={str(public_project_version)}\n')
f.write(f'local-version={str(project_version)}\n')
f.write(f'package-name={name}\n')
f.write(f'package-description={description}\n')
102 changes: 102 additions & 0 deletions .github/img/latex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "πŸ”„ ci & publish"

on:
push:
branches:
- master
paths-ignore:
- '**.md'
- .editorconfig
- .gitignore
pull_request:
branches:
- "*"

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
if:
github.event_name == 'pull_request' ||
startsWith(github.event.head_commit.message, 'release:') ||
startsWith(github.event.head_commit.message, 'release(')
uses: ./.github/workflows/test.yml


draft_release:
if:
github.event_name == 'push' &&
(
startsWith(github.event.head_commit.message, 'release:') ||
startsWith(github.event.head_commit.message, 'release(')
)
needs: [tests]
uses: ./.github/workflows/release.yml
secrets: inherit

52 changes: 52 additions & 0 deletions .github/workflows/composites/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "🏞️ » setup environment"
description: "setup all necessary tools for the workflow to run"
inputs:
python-version:
description: "Version of python to install"
required: true

defaults:
run:
shell: 'bash'

runs:
using: "composite"

steps:
- name: 🏞️ » setup environment
shell: bash
run: echo "🏞️ » setup environment with python ${{inputs.python-version}}"

- name: 🐍 » setup python@3
uses: actions/setup-python@v5
with:
python-version: ${{inputs.python-version}}
cache: "pip"

- name: πŸ“˜ Β» install Poetry
shell: bash
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: πŸ‘— Β» install nox
shell: bash
run: |
pip install nox nox-poetry
- name: 🧊 » install task
uses: arduino/setup-task@v1
with:
version: 3.x

- name: πŸ”€ Β» update PATH env var
shell: bash
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: πŸ“œ Β» log sysinfo
shell: bash
run: |
uname -a
python --version
pip --version
poetry --version
task --version
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "πŸš€ Β» publish"
on:
release:
types: [published]

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: 'bash'

jobs:
publish-test-pypi:
name: πŸš€ Β» publish to test.pypi βš—οΈ
if: ${{ github.event.act }}
runs-on: ubuntu-latest
environment: pypi-test
steps:
# checkout
- name: πŸ“ Β» checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: πŸš€ Β» build & publish to test.pypi
uses: JRubics/poetry-publish@v1.17
with:
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}
repository_name: "testpypi"
repository_url: "https://test.pypi.org/legacy/"

publish:
name: πŸš€ Β» publish to pypi 🏭
if: ${{ !github.event.act }}
runs-on: ubuntu-latest
environment: pypi
steps:
# checkout
- name: πŸ“ Β» checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: πŸš€ Β» build & publish to test.pypi
uses: JRubics/poetry-publish@v1.17
with:
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}


62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "πŸ”– Β» draft release"
on:
workflow_call:
workflow_dispatch:

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: 'bash'

jobs:
release:
name: "πŸ”– Β» draft release"
runs-on: ubuntu-latest
outputs:
release-note: ${{ steps.changelog.outputs.changelog }}
version: ${{ steps.version.outputs.local-version }}

steps:
- name: πŸ“ Β» checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: ⬅️ Β» get previous git tag
id: tag
run: echo "last-tag=$(git describe --tags --abbrev=0 || git rev-list --max-parents=0 ${{github.ref}})" >> $GITHUB_OUTPUT

- name: 🏷️ » get versions
uses: ./.github/actions/check-version
id: version
with:
pyproject-path: "./pyproject.toml"

- name: πŸ“‘ Β» generate changelog
uses: lucaslabstech/action-release@v1.0.4
id: changelog
with:
token: ${{ secrets.GITHUB_TOKEN }}
from: ${{ steps.tag.outputs.last-tag }}
to: ${{ github.ref }}
next-version: v${{ steps.version.outputs.local-version }}


- name: πŸ—‘οΈ Β» delete outdated drafts
uses: hugo19941994/delete-draft-releases@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: πŸ”– Β» create draft release
uses: ncipollo/release-action@v1.11.1
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
with:
prerelease: false
draft: true
tag: v${{ steps.version.outputs.local-version }}
name: v${{ steps.version.outputs.local-version }}
body: ${{ steps.changelog.outputs.changelog }}
68 changes: 68 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "πŸ§ͺ Β» test"
on:
workflow_call:
workflow_dispatch:

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: 'bash'

jobs:
lint:
name: "🧹 » lint"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]

steps:
- name: πŸ“ Β» checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 🐍 » setup python, poetry and task
uses: ./.github/workflows/composites/setup
with:
python-version: ${{ matrix.python-version }}

- name: πŸ“¦ Β» install ruff globally
run: pip install ruff

- name: 🧹 » lint
run: task lint:check

test:
name: "πŸ§ͺ Β» tests"
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: πŸ“ Β» checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 🐍 » setup python, poetry and task
uses: ./.github/workflows/composites/setup
with:
python-version: ${{ matrix.python-version }}

- name: πŸ§ͺ Β» run tests
run: task test:${{ matrix.python-version }}

# if python 3.11, upload coverage to codecov
- name: β˜‚οΈ Β» upload coverage to codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
verbose: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test.py

.github/act-test

# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode

Expand Down
12 changes: 6 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

// πŸ§ͺ tests
// "tests": true,
"noxfile.py": true,
"conftest.py": true,
".nox": true,
"htmlcov": true,
"coverage": true,
".coverage": true,
// "noxfile.py": true,
// "conftest.py": true,
// ".nox": true,
// "htmlcov": true,
// "coverage": true,
// ".coverage": true,

// πŸ—‘οΈ
".task": true, // task-go
Expand Down
Loading

0 comments on commit f69c727

Please sign in to comment.