From a2afe48cdcdb0ca0cb65ed454bd1c3dfd0f7b8d7 Mon Sep 17 00:00:00 2001 From: Ben Thomasson Date: Thu, 22 Feb 2024 09:54:10 -0500 Subject: [PATCH] chore: add automated release --- .bumpversion.cfg | 9 ----- .github/workflows/release.yml | 36 +++++++++++++++++ Makefile | 5 ++- ansible_rulebook/__init__.py | 6 +-- pyproject.toml | 28 +++++++++++++ requirements_dev.txt | 5 ++- setup.cfg | 2 +- tests/unit/test_cli.py | 2 +- tools/ansible/release.yml | 76 +++++++++++++++++++++++++++++++++++ 9 files changed, 153 insertions(+), 16 deletions(-) delete mode 100644 .bumpversion.cfg create mode 100644 .github/workflows/release.yml create mode 100644 tools/ansible/release.yml diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index 0890ac06..00000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[bumpversion] -current_version = 1.0.5 -commit = False -tag = False -search = {current_version} - -[bumpversion:file:setup.cfg] - -[bumpversion:file:ansible_rulebook/__init__.py] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..f8610465 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +--- +name: Release ansible-rulebook + +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 ansible-rulebook + uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Get python version from Makefile + run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV + + - name: Install python ${{ env.py_version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.py_version }} + + - name: Install python deps + run: pip install -r requirements_dev.txt + + - name: Create release + run: ansible-playbook tools/ansible/release.yml -i localhost -e github_token=${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 109059c7..19bd655c 100644 --- a/Makefile +++ b/Makefile @@ -88,4 +88,7 @@ install: clean ## install the package to the active Python's site-packages pip install . minimal-ee: - ansible-builder build -f ./minimal-decision-environment.yml -t minimal-de:latest \ No newline at end of file + ansible-builder build -f ./minimal-decision-environment.yml -t minimal-de:latest + +PYTHON_VERSION: + @echo '3.9' diff --git a/ansible_rulebook/__init__.py b/ansible_rulebook/__init__.py index 83bc4114..f3a20acb 100644 --- a/ansible_rulebook/__init__.py +++ b/ansible_rulebook/__init__.py @@ -12,15 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Top-level package for Ansible Events.""" +"""Top-level package for Ansible Rulebook.""" import yaml -__version__ = "1.0.5" - def construct_vault_encrypted_unicode(loader, node): return loader.construct_scalar(node) yaml.SafeLoader.add_constructor("!vault", construct_vault_encrypted_unicode) + +__version__ = "1.0.6b8" diff --git a/pyproject.toml b/pyproject.toml index 9329969a..7d14dc40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,3 +12,31 @@ profile = "black" combine_as_imports = true line_length = 79 extend_skip = ["docs"] + +[tool.bumpver] +current_version = "1.0.6b8" +version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]" +commit_message = "chore: bump version {old_version} -> {new_version}" +tag_message = "{new_version}" +tag_scope = "default" +pre_commit_hook = "" +post_commit_hook = "" +commit = true +tag = true +push = true + +[tool.setuptools_scm] + + + +[tool.bumpver.file_patterns] +"pyproject.toml" = [ + 'current_version = "{version}"', +] +"ansible_rulebook/__init__.py" = [ + '__version__ = "{version}"', +] +"setup.cfg" = [ + 'version = {version}', +] + diff --git a/requirements_dev.txt b/requirements_dev.txt index aaec948b..91bd67a1 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,7 +2,7 @@ -r requirements_lint.txt -r docs/requirements.txt -bump2version +bumpver # Packaging / distribution twine @@ -16,3 +16,6 @@ coverage ansible-builder pre-commit + +# For buiding releases +setuptools-scm diff --git a/setup.cfg b/setup.cfg index 63bf0da1..7bf410dc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ansible_rulebook -version = 1.0.5 +version = 1.0.6b8 description = Event driven automation for Ansible url = https://github.com/ansible/ansible-rulebook license = Apache-2.0 diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 5581154a..5932ceae 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -11,7 +11,7 @@ def test_get_version(): output = get_version() pattern = re.compile( - r"""\d+\.\d+\.\d+ + r"""\d+\.\d+\.\d+(.+) Executable location = (.+) Drools_jpy version = \d+\.\d+\.\d+ Java home = (.+) diff --git a/tools/ansible/release.yml b/tools/ansible/release.yml new file mode 100644 index 00000000..5901bdf7 --- /dev/null +++ b/tools/ansible/release.yml @@ -0,0 +1,76 @@ +--- +- name: Release ansible-rulebook + hosts: localhost + connection: local + gather_facts: true + vars: + repo_identifier: "ansible/ansible-rulebook" + 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 ansible-rulebook root + + tasks: + + - name: Get the build number from setuptools-scm + command: + cmd: python -m setuptools_scm --strip-dev + register: setuptools_command_version + + - set_fact: + release_number: "{{ setuptools_command_version.stdout }}" + + - name: Tag the repo + command: + cmd: "git tag -f {{ release_number }}" + + - set_fact: + release_number: "{{ git_version.stdout }}" + + - name: Build ansible-rulebook + command: + cmd: make dist + 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 + status_code: + - 201 + headers: + Accept: 'application/vnd.github.v3+json' + Authorization: 'bearer {{ github_token }}' + register: new_release_response + tags: + - github + + - name: Upload the build files + uri: + # For some reason the upload_url ends with ansible-rulebook/releases/138751035/assets{?name,label} + # We have to strip that off before adding our args to the URLs + url: "{{ new_release_response.json['upload_url'] | regex_replace('{.*}', '') }}?name={{ file_name }}" + method: POST + src: "{{ item }}" + status_code: + - 201 + headers: + Accept: 'application/vnd.github.v3+json' + Authorization: 'bearer {{ github_token }}' + Content-Type: "{{ file_name.endswith('tar.gz') | ternary('application/gzip', 'application/x-wheel+zip') }}" + vars: + file_name: "{{ item | basename }}" + loop: "{{ lookup('ansible.builtin.fileglob', '../../dist/*', wantlist=True) }}" + loop_control: + label: "{{ item | basename }}" + tags: + - github