Skip to content
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
18 changes: 18 additions & 0 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"template": "https://github.com/woltapp/wolt-python-package-cookiecutter",
"commit": "b773d08f38d1980e215aeb8dcdcfa7a8af7e1620",
"checkout": null,
"context": {
"cookiecutter": {
"author_name": "Jerry Pussinen",
"author_email": "jerry.pussinen@gmail.com",
"github_username": "jerry-git",
"project_name": "pytest-split",
"project_slug": "pytest-split",
"package_name": "pytest_split",
"project_short_description": "Pytest plugin which splits the test suite to equally sized \"sub suites\" based on test execution time.",
"_template": "https://github.com/woltapp/wolt-python-package-cookiecutter"
}
},
"directory": null
}
21 changes: 21 additions & 0 deletions .github/actions/python-poetry-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Setup Python + Poetry environment'
description: 'Setup Python + Poetry environment'

inputs:
python-version:
required: false
description: 'Python version'
default: '3.9'
outputs: {}
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v2
with:
python-version: ${{inputs.python-version}}
- name: Install poetry
run: python -m pip install poetry
shell: bash
- name: Create virtual environment
run: poetry install
shell: bash
81 changes: 81 additions & 0 deletions .github/workflows/cookiecutter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Autoupdate project structure
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # at the end of every day

jobs:
auto-update-project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Set credentials for private templates
run: |
git config --global url."https://api:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}@github.com/".insteadOf "git@github.com:"

- name: Install dependencies
run: python -m pip install cruft poetry jello tabulate

- name: Update project structure
run: |
cruft update -y

- name: Check if there are changes
id: changes
uses: UnicornGlobal/has-changes-action@v1.0.11

- name: apply additional changes and fixes
if: steps.changes.outputs.changed == 1
run: |
poetry lock --no-update # add new dependencies
poetry install
poetry run pre-commit run -a || true # we have to fix other issues manually

- name: Get template versions
id: get_versions
if: steps.changes.outputs.changed == 1
run: |
echo ::set-output name=current_version::$(git show HEAD:.cruft.json | jello -r "_['commit'][:8]")
echo ::set-output name=next_version::$(cat .cruft.json | jello -r "_['commit'][:8]")

- name: Get changelog
id: get_changelog
if: steps.changes.outputs.changed == 1
run: |
export TEMPLATE=$(cat .cruft.json | jello -r "_['template']")
git clone $TEMPLATE /tmp/template
cd /tmp/template
body=$((echo "Date;Change;Hash"; git log --pretty=format:"%as;%s;%h" ${{ steps.get_versions.outputs.current_version }}..${{ steps.get_versions.outputs.next_version }}) | tabulate --header --format github -s ';' -)
body=$(cat <<EOF
Changes from $TEMPLATE

$body
EOF
)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=changelog::$body

# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
env:
# a PAT is required to be able to update workflows
GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_GITHUB_TOKEN }}
if: ${{ steps.changes.outputs.changed == 1 && env.GITHUB_TOKEN != 0 }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ env.GITHUB_TOKEN }}
commit-message: >-
chore: update project structure to ${{ steps.get_versions.outputs.next_version }}
title: "[Actions] Auto-Update cookiecutter template"
body: ${{ steps.get_changelog.outputs.changelog }}
branch: chore/auto-update-project-from-template
delete-branch: true
56 changes: 56 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Autoupdate dependencies
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"

jobs:
auto-update-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env

- name: Install tabulate
run: python -m pip install tabulate

- name: Gather outdated dependencies
id: check_for_outdated_dependencies
run: |
body=$(poetry show -o -n)
echo ::set-output name=body::$body

- name: Format PR message
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
id: get_outdated_dependencies
run: |
body=$(poetry show -o -n | sed 's/(!)//' | awk 'BEGIN {print "Package","Used","Update"}; {print $1,$2,$3}' | tabulate --header --format github -)
body=$(cat <<EOF
The following packages are outdated

$body
EOF
)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body

- name: Update outdated packages
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
run: poetry lock

# behaviour if PR already exists: https://github.com/marketplace/actions/create-pull-request#action-behaviour
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.check_for_outdated_dependencies.outputs.body != 0 }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ env.GITHUB_TOKEN }}
commit-message: >-
chore: update dependencies
title: "[Actions] Auto-Update dependencies"
body: ${{ steps.get_outdated_dependencies.outputs.body }}
branch: chore/update-dependencies
delete-branch: true
50 changes: 50 additions & 0 deletions .github/workflows/draft_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Draft a release

on:
workflow_dispatch:
inputs:
version:
description: 'The version number (e.g. 1.2.3) OR one of: patch|minor|major|prepatch|preminor|premajor|prerelease'
required: true
default: 'patch'

jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env
- name: Update version
id: updated_version
run: |
poetry version ${{ github.event.inputs.version }}
version=$(poetry version --short)
echo ::set-output name=version::$version
- name: Update changelog
id: changelog
run: |
poetry run kacl-cli release ${{ steps.updated_version.outputs.version }} --modify --auto-link
echo "" >> CHANGELOG.md
body=$(poetry run kacl-cli get ${{ steps.updated_version.outputs.version }})
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
add: 'CHANGELOG.md pyproject.toml'
message: 'Release ${{ steps.updated_version.outputs.version }}'
- name: Create tag
run: |
git tag ${{ steps.updated_version.outputs.version }}
git push origin ${{ steps.updated_version.outputs.version }}
- name: Create a draft release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.updated_version.outputs.version }}
release_name: Release ${{ steps.updated_version.outputs.version }}
body: ${{ steps.changelog.outputs.body }}
draft: true
35 changes: 0 additions & 35 deletions .github/workflows/publish.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on:
release:
types: [ published ]

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env
- name: Publish to pypi
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build --no-interaction
- name: Deploy docs
run: poetry run mkdocs gh-deploy --force
75 changes: 18 additions & 57 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,36 @@
name: test
name: Test

on:
pull_request:
branches:
- "**"
push:
branches:
- master
- "**"

jobs:
linting:
lint-cruft:
name: Check if automatic project update was successful
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: actions/cache@v2
with:
path: |
~/.cache/pip
~/.cache/pre-commit
key: ${{ runner.os }}-pip-2
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- run: python -m pip install pre-commit
- run: pre-commit run --all-files
- name: Fail if .rej files exist as structure update was not successful
run: test -z "$(find . -iname '*.rej')"

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env
- run: poetry run pre-commit run --all-files

test:
needs: linting
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.6", "3.7", "3.8", "3.9", ]
pytest-version: [ "5", "6" ]
python-version: ["3.7", "3.8", "3.9"]
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v2
- uses: ./.github/actions/python-poetry-env
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: snok/install-poetry@v1.2.1
with:
virtualenvs-in-project: true

- name: Load cached venv
uses: actions/cache@v2
id: cache-venv
with:
path: .venv
key: ${{ hashFiles('**/poetry.lock') }}-2

- name: Install dependencies
run: poetry install --no-interaction --no-root
if: steps.cache-venv.outputs.cache-hit != 'true'

- name: Install Pytest
run: |
source .venv/bin/activate
pip install pytest==${{ matrix.pytest-version }}

- name: Install package
run: poetry install --no-interaction

- name: Run tests
run: |
source .venv/bin/activate
coverage run -m pytest --verbose --assert=plain
coverage report
- run: poetry run pytest
Loading