Skip to content

Commit

Permalink
feat(cli): add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Jan 11, 2022
1 parent dcab169 commit 2a9ad4e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
39 changes: 10 additions & 29 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ on:
push:

jobs:
tests:
runs-on: ubuntu-latest
test_and_build:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Python
uses: actions/setup-python@v2
Expand Down Expand Up @@ -78,27 +80,12 @@ jobs:
with:
files: ./coverage.xml

build:
runs-on: ubuntu-latest
container: wakemeops/debian:bullseye-slim
needs: [tests]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
install_packages \
poetry \
python3-dev \
ca-certificates \
binutils
- name: Build single binary application
run: |
poetry install --no-dev --extras pyinstaller
poetry install --extras pyinstaller
poetry run poetry-dynamic-versioning
poetry run pyinstaller --onefile src/ops2deb/__main__.py --name ops2deb -s
dist/ops2deb --help
dist/ops2deb version
mv dist/ops2deb ops2deb_linux_amd64
- name: Upload build artifact
Expand All @@ -111,7 +98,7 @@ jobs:
release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [build]
needs: [test_and_build]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -144,7 +131,7 @@ jobs:

publish:
runs-on: ubuntu-latest
needs: [build]
needs: [test_and_build]
if: startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout
Expand All @@ -164,14 +151,8 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Get Release Version
if: "startsWith(github.ref, 'refs/tags')"
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build Distribution
run: |
poetry version "$RELEASE_VERSION";
poetry build
run: poetry run poetry build

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ description: |-
releases of upstream applications and automatically bump application versions
in its configuration file.
script:
- ./build-single-binary-application.sh
- poetry install -E pyinstaller
- poetry run task single_binary_application
- install -m 755 build/x86_64-unknown-linux-gnu/release/install/ops2deb {{src}}/usr/bin/
```

Expand All @@ -157,6 +158,30 @@ To run ops2deb test suite run:
poetry run task check
```

To build a python wheel:

```shell
poetry run poetry build
```

Note that the `poetry run` is important to enable [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning)
which is installed as a dev dependency.

To build a single binary applicatin:

Install required build dependencies:

```shell
sudo apt install binutils python3-dev
poetry install -E pyinstaller
```

And run:

```shell
poetry run task single_binary_application
```

## Important notes

`ops2deb` **DOES NOT** sandbox build instructions so if you do something like:
Expand Down
2 changes: 1 addition & 1 deletion ops2deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
- fakeroot
- debhelper
fetch:
url: https://github.com/upciti/ops2deb/releases/download/{{version}}/ops2deb_linux_amd64.tar.gz
url: https://github.com/upciti/ops2deb/releases/download/{{version}}/ops2deb_linux_amd64
sha256: 211bc67e965cda9ab7cdcb227cf114f5114eaa85689eda55a3833d297aea698c
script:
- mv ops2deb {{src}}/usr/bin/
70 changes: 69 additions & 1 deletion poetry.lock

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

12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ safety = "*"
types-aiofiles = "*"
types-PyYAML = "*"
pytest-asyncio = "^0.16.0"
poetry-dynamic-versioning = "^0.13.1"

[tool.taskipy.tasks]
check = """
Expand Down Expand Up @@ -81,5 +82,14 @@ line_length = 90
profile = "black"

[build-system]
requires = ["poetry>=1.0"]
requires = ["poetry>=1.0.2", "poetry-dynamic-versioning"]
build-backend = "poetry.masonry.api"

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"
pattern = "(?x)^(?P<base>\\d+\\.\\d+\\.\\d+)(-?((?P<stage>[a-zA-Z]+)\\.?(?P<revision>\\d+)?))?(\\+(?P<tagged_metadata>.+))?$"

[tool.poetry-dynamic-versioning.substitution]
files = ["src/ops2deb/__init__.py"]
1 change: 1 addition & 0 deletions src/ops2deb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0"
7 changes: 6 additions & 1 deletion src/ops2deb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import typer

from . import builder, formatter, generator, logger, parser, updater
from . import __version__, builder, formatter, generator, logger, parser, updater
from .exceptions import Ops2debError
from .fetcher import DEFAULT_CACHE_DIRECTORY, Fetcher

Expand Down Expand Up @@ -118,6 +118,11 @@ def format(configuration_path: Path = OPTION_CONFIGURATION) -> None:
error(e)


@app.command(help="Outputs ops2deb version.")
def version() -> None:
logger.info(__version__)


@app.callback()
def args_cb(
verbose: bool = typer.Option(
Expand Down

0 comments on commit 2a9ad4e

Please sign in to comment.