-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from eamigo86/actions
Implementing GitHub Actions
- Loading branch information
Showing
5 changed files
with
306 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,153 @@ | ||
name: WIP | ||
name: Continuous Integration & Delivery | ||
on: | ||
pull_request: | ||
branches: [ master ] | ||
workflow_dispatch: | ||
branches: [ master, actions ] | ||
jobs: | ||
demo: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- python: 3.6 | ||
django: 2.2 | ||
toxenv: py36-django22 | ||
- python: 3.6 | ||
django: 3.0 | ||
toxenv: py36-django30 | ||
- python: 3.7 | ||
django: 2.2 | ||
toxenv: py37-django22 | ||
- python: 3.7 | ||
django: 3.0 | ||
toxenv: py37-django30 | ||
- python: 3.8 | ||
django: 2.2 | ||
toxenv: py38-django22 | ||
- python: 3.8 | ||
django: 3.0 | ||
toxenv: py38-django30 | ||
- python: 3.9 | ||
django: 2.2 | ||
toxenv: py39-django22 | ||
- python: 3.9 | ||
django: 3.0 | ||
toxenv: py39-django30 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run a one-line script | ||
- uses: actions/setup-python@v1 | ||
name: Set up Python ${{ matrix.python }} ${{ matrix.django }} | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install pip packages | ||
run: | | ||
echo Hello, world 1! | ||
pip install pip --upgrade | ||
pip install codecov poetry tox | ||
- name: "Run tox - testenv: ${{ matrix.toxenv }}" | ||
env: | ||
DJANGO: ${{ matrix.django }} | ||
TOXENV: ${{ matrix.toxenv }} | ||
run: tox | ||
- name: Run notification script | ||
env: | ||
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }} | ||
GITHUB_JOB_STATUS: ${{ job.status }} | ||
GITHUB_RUN_URL: ${{ github.event.repository.url }}/actions/runs/${{ github.run_id }} | ||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | ||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} | ||
run: ./scripts/notification.sh | ||
|
||
quality: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- python: 3.6 | ||
toxenv: quality | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v1 | ||
name: Set up Python ${{ matrix.python }} | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install pip packages | ||
run: | | ||
pip install pip --upgrade | ||
pip install poetry tox | ||
- name: "Run tox - testenv: ${{ matrix.toxenv }}" | ||
env: | ||
TOXENV: ${{ matrix.toxenv }} | ||
run: tox | ||
|
||
security: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- python: 3.6 | ||
toxenv: security | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v1 | ||
name: Set up Python ${{ matrix.python }} | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install pip packages | ||
run: | | ||
pip install pip --upgrade | ||
pip install poetry tox | ||
- name: "Run tox - testenv: ${{ matrix.toxenv }}" | ||
env: | ||
TOXENV: ${{ matrix.toxenv }} | ||
run: tox | ||
|
||
# # AUTHOR: Lukasz Dynowski | ||
# # TODO: Uncomment this code only if we agreed for Continuous Delivery. | ||
# # TODO: Update PYPI envars to production values! | ||
# publish: | ||
# needs: | ||
# - test | ||
# - security | ||
# - quality | ||
# runs-on: ubuntu-latest | ||
# strategy: | ||
# matrix: | ||
# include: | ||
# - python: 3.6 | ||
# toxenv: build | ||
# steps: | ||
# - uses: actions/checkout@v2 | ||
# - uses: actions/setup-python@v1 | ||
# name: Set up Python ${{ matrix.python }} | ||
# with: | ||
# python-version: ${{ matrix.python }} | ||
# - name: Install pip packages | ||
# run: | | ||
# pip install pip --upgrade | ||
# pip install poetry tox | ||
# - name: Bump package version | ||
# run: ./scripts/bump.py --dry-run no | ||
# - name: "Build package - testenv: ${{ matrix.toxenv }}" | ||
# env: | ||
# TOXENV: ${{ matrix.toxenv }} | ||
# run: tox | ||
# - name: "Publish - testenv: ${{ matrix.toxenv }}" | ||
# env: | ||
# PYPI_ACCESS_TOKEN: ${{ secrets.PYPI_ACCESS_TOKEN }} | ||
# # Values production 'https://pypi.org/', testing 'https://test.pypi.org/legacy/' | ||
# PYPI_REPOSITORY_URL: https://test.pypi.org/legacy/ | ||
# # Values production 'pypi', testing 'testpypi' | ||
# PYPI_REPOSITORY: testpypi | ||
# PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
# run: | | ||
# poetry config repositories.$PYPI_REPOSITORY $PYPI_REPOSITORY_URL | ||
# poetry config pypi-token.$PYPI_REPOSITORY $PYPI_ACCESS_TOKEN | ||
# poetry publish -r $PYPI_REPOSITORY -u $PYPI_USERNAME | ||
# - name: Create bump commit | ||
# uses: EndBug/add-and-commit@latest | ||
# with: | ||
# author_name: github_actions | ||
# author_email: github_actions | ||
# message: PR Auto bumping package version | ||
# add: pyproject.toml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from pathlib import Path | ||
import argparse | ||
import re | ||
import toml | ||
|
||
|
||
def get_args(): | ||
"""Set up CLI args""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--major", | ||
type=int, | ||
nargs="*", | ||
help="Major version bump. Empty flag will auto bump current version.", | ||
) | ||
parser.add_argument( | ||
"--minor", | ||
type=int, | ||
nargs="*", | ||
help="Minor version bump. Empty flag will auto bump current version.", | ||
) | ||
parser.add_argument( | ||
"--patch", | ||
type=int, | ||
nargs="*", | ||
help="Patch version bump. Empty flag will auto bump current version.", | ||
) | ||
parser.add_argument( | ||
"--dry-run", type=str, default="yes", choices=["yes", "no"], help="Dry run" | ||
) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def get_version(pyproject_file_path): | ||
"""Function returns tuple that elements follow semantic versioning order""" | ||
with open(pyproject_file_path) as file: | ||
pyproject = toml.loads(file.read()) | ||
current_version = pyproject["tool"]["poetry"]["version"] | ||
|
||
validate_version(current_version) | ||
|
||
# Normalize version to tuple | ||
if current_version.count(".") == 0: | ||
return tuple(int(current_version)) | ||
|
||
return tuple(int(v) for v in current_version.split(".")) | ||
|
||
|
||
def validate_version(current_version, pattern=r"^\d+\.\d+\.\d+$"): | ||
""" | ||
Validate that extracted version follows "MAJOR.MINOR.PATCH" pattern | ||
""" | ||
match = re.search(pattern, current_version) | ||
if not match: | ||
print( | ||
f'Error: Package version {current_version} is not following semantic versioning "MAJOR.MINOR.PATCH"' | ||
) | ||
exit(1) | ||
|
||
|
||
def bump_major(version): | ||
if not version: | ||
return CURRENT_VERSION[0] + 1 | ||
|
||
return version[0] | ||
|
||
|
||
def bump_minor(version): | ||
if not version: | ||
return CURRENT_VERSION[1] + 1 | ||
|
||
return version[0] | ||
|
||
|
||
def bump_patch(version): | ||
if not version: | ||
return CURRENT_VERSION[2] + 1 | ||
|
||
return version[0] | ||
|
||
|
||
def bump_version(major, minor, patch): | ||
if major or type(major) == list: | ||
major = bump_major(major) | ||
|
||
if minor or type(minor) == list: | ||
minor = bump_minor(minor) | ||
|
||
if (type(patch) == list) or all(v is None for v in (major, minor, patch)): | ||
patch = bump_patch(patch) | ||
|
||
# Construct bump from new version and current version | ||
bump = [] | ||
new_versions = (major, minor, patch) | ||
for index in range(len(new_versions)): | ||
if new_versions[index] is None: | ||
bump.append(CURRENT_VERSION[index]) | ||
else: | ||
bump.append(new_versions[index]) | ||
|
||
return tuple(bump) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = get_args() | ||
|
||
# Obtain 'pyproject.toml' file path | ||
current_file_path = str(Path(__file__).resolve()) | ||
pyproject_file_path = current_file_path.replace(current_file_path, "pyproject.toml") | ||
|
||
# Bump and normalize current version | ||
CURRENT_VERSION = get_version(pyproject_file_path) | ||
NEW_VERSION = bump_version(args.major, args.minor, args.patch) | ||
CURRENT_VERSION = ".".join(map(str, CURRENT_VERSION)) | ||
NEW_VERSION = ".".join(map(str, NEW_VERSION)) | ||
|
||
# Print version check | ||
if args.dry_run == "yes": | ||
print(f"Current version: {CURRENT_VERSION}") | ||
print(f"New version: {NEW_VERSION}") | ||
else: | ||
with open(pyproject_file_path, "r") as file: | ||
content = file.read() | ||
|
||
with open(pyproject_file_path, "w") as file: | ||
CV = f'version = "{CURRENT_VERSION}"' | ||
NV = f'version = "{NEW_VERSION}"' | ||
content = content.replace(CV, NV) | ||
file.write(content) | ||
print( | ||
f"Successfully updated package version from {CURRENT_VERSION} to {NEW_VERSION}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.