diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..f34196838 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +--- +name: Release django-ansible-base + +env: + LC_ALL: "C.UTF-8" # prevent ERROR: Ansible could not initialize the preferred locale: unsupported locale setting + +on: + workflow_dispatch: + +jobs: + stage: + runs-on: ubuntu-latest + timeout-minutes: 90 + permissions: + packages: write + contents: write + steps: + - name: Checkout dab + uses: actions/checkout@v3 + with: + path: dab + + - name: Create release + working-directory: dab + run: | + ansible-playbook tools/ansible/release.yml -e github_token=${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 5eefa5bbc..05d96d903 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ pre-commit-user # Make target touch files .docker-compose-built +# Ignore the build version file +ansible_base._version.py + # Python & setuptools __pycache__ /build diff --git a/ansible_base/__init__.py b/ansible_base/__init__.py index e69de29bb..eda57835c 100644 --- a/ansible_base/__init__.py +++ b/ansible_base/__init__.py @@ -0,0 +1,15 @@ +try: + from ._version import version +except ImportError: + version = '0.0.0.dev' + +from typing import Tuple, Union + +VERSION_TUPLE = Tuple[Union[int, str], ...] + +__version__: str +__version_tuple__: VERSION_TUPLE +version_tuple: VERSION_TUPLE + +__version__ = version +__version_tuple__ = version_tuple = tuple(version.split('.')) diff --git a/ansible_base/_version.py b/ansible_base/_version.py new file mode 100644 index 000000000..391661b6a --- /dev/null +++ b/ansible_base/_version.py @@ -0,0 +1 @@ +version = '0.0.0.dev' diff --git a/pyproject.toml b/pyproject.toml index 4e962044b..8de87a692 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,9 @@ classifiers = [ ] dynamic = ["version", "dependencies", "optional-dependencies"] +[tool.setuptools] +include-package-data = false + [tool.setuptools.packages.find] include = ["ansible_base*"] @@ -46,9 +49,10 @@ optional-dependencies.api_documentation = { file = [ "requirements/requirements_ optional-dependencies.rest_filters = { file = [ "requirements/requirements_rest_filters.in" ] } optional-dependencies.channel_auth = { file = [ "requirements/requirements_channels.in" ] } optional-dependencies.jwt_consumer = { file = [ "requirements/requirements_jwt_consumer.in" ] } +version = {attr = "ansible_base.__version__"} [build-system] -requires = ["setuptools>=64", "setuptools_scm>=8"] +requires = ["setuptools>=64"] build-backend = 'setuptools.build_meta' [tool.black] diff --git a/tools/ansible/release.yml b/tools/ansible/release.yml new file mode 100644 index 000000000..60baaecf5 --- /dev/null +++ b/tools/ansible/release.yml @@ -0,0 +1,68 @@ +--- +- name: Release django-ansible-base + hosts: localhost + connection: local + gather_facts: true + vars: + repo_identifier: "john-westcott-iv/django-ansible-base" + api_repo_prefix: "https://api.github.com/repos/{{ repo_identifier }}" + + # Note: + # When this playbook runs it will run in the directory of the playbook so ../../ would be a reference to the django-ansible-base root + + tasks: + - name: Generate calver release number + set_fact: + release_number: "{{ ansible_date_time.year }}.{{ ansible_date_time.month }}.{{ ansible_date_time.day }}" + + - name: "Update version file with {{ release_number }}" + ansible.builtin.lineinfile: + create: True + line: "version = '{{ release_number }}'" + path: "../../ansible_base/_version.py" + regex: "^version = .*" + + - name: Build django-ansible-base + command: + cmd: make build + creates: 'dist/django-ansible-base-{{ release_number }}.tar.gz' + args: + chdir: '../../' + tags: + - build + + - name: Create release in github + uri: + url: "{{ api_repo_prefix }}/releases" + method: POST + body_format: json + body: + tag_name: "{{ release_number }}" + name: "v{{ release_number }}" + draft: False + generate_release_notes: True + make_latest: True + headers: + Accept: 'application/vnd.github.v3+json' + Authorization: 'bearer {{ github_token }}' + register: new_release_response + tags: + - github + + - name: Upload the build files + debug: + msg: "{{ file_name }}" + uri: + url: "{{ new_release_response.json['upload_url'] }}?name={{ file_name }}" + method: POST + src: "dist/{{ file_name }}" + headers: + Accept: 'application/vnd.github.v3+json' + Authorization: 'bearer {{ github_token }}' + vars: + file_name: "{{ item | basename }}" + loop: "{{ lookup('ansible.builtin.fileglob', '../../dist/*', wantlist=True) }}" + loop_control: + label: "{{ item | basename }}" + tags: + - github