Skip to content

Commit

Permalink
Merge pull request #6 from acederberg/feature/poetry
Browse files Browse the repository at this point in the history
Packaging and Actions Part 1
  • Loading branch information
acederberg authored Aug 20, 2024
2 parents 4817645 + fe6ba75 commit 04e93e7
Show file tree
Hide file tree
Showing 123 changed files with 4,056 additions and 1,314 deletions.
8 changes: 8 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends: ['@commitlint/config-conventional']
rules:
subject-case: [0, never, 'sentence-case']
subject-full-stop: [2, 'always', '.']
type-enum:
- 2
- always
- ['build', 'chore', 'ci', 'docs', 'feature', 'fix', 'revert', 'wip']
14 changes: 11 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
.data
.git
.github
.mypy_cache
.pytest_cache
.ruff_cache
.venv
.venv-local
configs
plugins
scripts
logs
.venv-local
__pycache__
.data
.venv

110 changes: 110 additions & 0 deletions .github/workflows/commit_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Commit Checks.
on:
workflow_dispatch:
pull_request:
paths-ignore:
- '**.rst'
push:

jobs:
# NOTE: https://commitlint.js.org/guides/ci-setup.html
lint-commit:
name: Lint Commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install required dependencies
run: |
sudo apt update && sudo apt install -y git curl
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs
npm install conventional-changelog-conventionalcommits
npm install commitlint@latest @commitlint/config-conventional
- name: Print versions
run: |
echo "git version: $(git --version)" >> $GITHUB_STEP_SUMMARY
echo "node version: $(node --version)" >> $GITHUB_STEP_SUMMARY
echo "npm version: $(npm --version)" >> $GITHUB_STEP_SUMMARY
echo "commitlint version: $(npx commitlint --version)" >> $GITHUB_STEP_SUMMARY
- name: Validate current commit (last commit) with commitlint
if: github.event_name == 'push'
run: npx commitlint --last --verbose

lint-code:
name: Lint Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Cache Pip
uses: actions/cache@v3
id: venv
with:
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}

- name: Venv and Setup
run: |
echo -e "## Python Info\n" >> $GITHUB_STEP_SUMMARY
echo "- Python Version: \`$( python --version )\`" >> $GITHUB_STEP_SUMMARY
echo "- Python Binary: \`$( which python )\`" >> $GITHUB_STEP_SUMMARY
python -m venv .venv
source .venv/bin/activate
python -m pip install poetry mypy ruff
poetry install
- name: MyPy Check Source.
id: mypy_check_src
run: |
source .venv/bin/activate
echo -e "## MyPy \`./src\`\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
poetry run mypy --config-file pyproject.toml --pretty ./src >> $GITHUB_STEP_SUMMARY
echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
continue-on-error: true

- name: MyPy Check Tests.
id: mypy_check_tests
run: |
source .venv/bin/activate
echo -e "## MyPy \`./tests\`\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
poetry run mypy --config-file pyproject.toml --pretty ./tests >> $GITHUB_STEP_SUMMARY
echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
continue-on-error: true

- name: Ruff Linting.
id: ruff
run: |
source .venv/bin/activate
echo -e "## Ruff\n\n~~~stdout" >> $GITHUB_STEP_SUMMARY
poetry run ruff check --config pyproject.toml --output-format github .>> $GITHUB_STEP_SUMMARY
echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
continue-on-error: true

- run: |
if ( \
[ "${{ steps.mypy_check_src.outcome }}" != "success" ] \
|| [ "${{ steps.mypy_check_tests.outcome }}" != "success" ] \
|| [ "${{ steps.ruff.outcome }}" != 'success' ]
); then
echo "One or more checks failed. See the summary for details."
exit 1
fi
47 changes: 47 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Package and Release
on:
push:
# NOTE: From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
tags: ["^[0-9]+.[0-9]+.[0-9]+(-?(alpha|beta))?$"]
jobs:
release:
runs-on: ubuntu-latest
needs: bumpver
steps:
# NOTE: https://github.com/actions/download-artifact
- name: Checkout.
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get Body.
run: |
tag_body=$( git tag -l --format='%(contents:body)' 0.1.5 )
echo "CAPTURA_TAG_BODY=$tag_body" >> $GITHUB_ENV
- name: Get Artifacts.
uses: actions/download-artifact@v4
with:
name: captura-build-${{ git.ref_name }}
github-token: ${{ secrets.GH_PAT }}
path: ./dist

- name: Publish to PyPI.
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Create Release
id: release-create
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref_name }}
release_name: Version ${{ github.ref_name }}
body: ${{ env.TAG_BODY }}
draft: false
prerelease: false



174 changes: 174 additions & 0 deletions .github/workflows/pr_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Pull Request Checks.
on:
workflow_dispatch:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
paths-ignore:
- '**.rst'
jobs:
pytest:
name: PyTest
runs-on: ubuntu-latest
steps:
- name: Checkout.
uses: actions/checkout@v4

# NOTE: Use ``docker compose --file docker/compose.yaml config | less``
# to see the config with interpolated variables from ``.env``.
# More about interpolation: https://docs.docker.com/compose/environment-variables/variable-interpolation/
#
# NOTE: More on caching can be found in the following:
# - https://github.com/docker/build-push-action?tab=readme-ov-file#usage
# - https://docs.docker.com/build/cache/backends/gha/
- name: Setup Docker Buildx.
uses: docker/setup-buildx-action@v3

- name: Build Server Image.
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/dockerfile
target: ci
# NOTE: ``bumpver`` will be looking for this. Futher, this should
# match tags in ``./docker/compose.ci.yaml`` which are updated
# by bumpver.
tags: acederberg/captura-ci:0.1.5
pull: false
push: false
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Setup.
run: |
docker_config_path='/home/captura/app/tests/assets/act.yaml'
echo "CAPTURA_CONFIG_CLIENT_TEST=$docker_config_path" > .env
echo "CAPTURA_CONFIG_CLIENT=$docker_config_path" >> .env
echo "CAPTURA_CONFIG_APP_TEST=$docker_config_path" >> .env
echo "CAPTURA_CONFIG_APP=$docker_config_path" >> .env
echo "CAPTURA_FLAKEY=/home/captura/flakey.yaml" >> .env
- name: Start Docker Compose Project.
run: |
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
up --detach --quiet-pull
# NOTE: ``act.yaml`` defined everything necessary for the client and server.
- name: Generate Dummy Data In Server.
run: |
version=$( \
docker compose \
--file docker/compose.ci.yaml \
exec db mysql --version \
)
echo "MySQL Version: $version" >> $GITHUB_STEP_SUMMARY
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run simulatus initialize \
&& poetry run simulatus apply'
# echo -e "# Dummy Data Report\n\n~~~" >> $GITHUB_STEP_SUMMARY
# docker compose \
# --file docker/compose.ci.yaml \
# exec server \
# bash -c ' \
# source ~/app/.venv/bin/activate \
# && poetry run simulatus --loud reports aggregate' \
# >> $GITHUB_STEP_SUMMARY
# echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
- name: Run Tests.
run: |
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& pip install poetry \
&& poetry run coverage run -m pytest --count 1'
continue-on-error: true

# --------------------------------------------------------------------- #
# NOTE: ``master/develop`` only.
- name: Create Coverage Report.
id: coverage-report
if: |
contains('
refs/heads/master
refs/heads/development
', github.ref)
run: |
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run coverage html --directory ./coverage-report'
continue-on-error: true

- name: Copy Coverage Report To Host.
id: coverage-report-to-host
if: |
contains('
refs/heads/master
refs/heads/development
', github.ref)
run: |
docker compose \
--file docker/compose.ci.yaml \
cp server:/home/captura/app/coverage-report ./coverage-report
- name: Upload Coverage Report.
id: coverage-report-upload
if: |
contains('
refs/heads/master
refs/heads/development
', github.ref)
uses: actions/upload-pages-artifact@v3
with:
path: './coverage-report'

# --------------------------------------------------------------------- #
# NOTE: Finalize.
#
- name: Stop Compose Project.
if: always()
run: docker compose --file docker/compose.ci.yaml down

# NOTE: Publish only when on master/development.
coverage:
name: PyTest Coverage
if: |
contains('
refs/heads/master
refs/heads/development
', github.ref)
needs: pytest
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: coverage-report-pages
uses: actions/deploy-pages@v4





Loading

0 comments on commit 04e93e7

Please sign in to comment.