Skip to content

Commit

Permalink
chore: add automated release
Browse files Browse the repository at this point in the history
  • Loading branch information
benthomasson committed Feb 26, 2024
1 parent 67004a0 commit 2902c34
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 15 deletions.
9 changes: 0 additions & 9 deletions .bumpversion.cfg

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
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

- 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 deeps
run: pip install -r requirements/requirements_dev.txt

- name: Create release
run: ansible-playbook tools/ansible/release.yml -i localhost -e github_token=${{ secrets.GITHUB_TOKEN }}
7 changes: 3 additions & 4 deletions ansible_rulebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# 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__ = "2024.2.26"
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,30 @@ profile = "black"
combine_as_imports = true
line_length = 79
extend_skip = ["docs"]

[tool.setuptools_scm]
version_scheme = "calver-by-date"

[tool.bumpver]
current_version = "2024.2.26"
version_pattern = "YYYY.MM.DD"
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.bumpver.file_patterns]
"pyproject.toml" = [
'current_version = "{version}"',
]
"ansible_rulebook/__init__.py" = [
'__version__ = "{version}"',
]
"setup.cfg" = [
'version = {version}',
]

2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-r requirements_lint.txt
-r docs/requirements.txt

bump2version
bumpver

# Packaging / distribution
twine
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ansible_rulebook
version = 1.0.5
version = 2024.2.26
description = Event driven automation for Ansible
url = https://github.com/ansible/ansible-rulebook
license = Apache-2.0
Expand Down
80 changes: 80 additions & 0 deletions tools/ansible/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
- 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: Generate calver release number
set_fact:
# setuptools-scm will strip leading 0's off the date format so we need to do that too
release_number: "{{ (ansible_date_time.date | to_datetime('%Y-%m-%d')).strftime('%Y.%m.%d') | regex_replace('\\.0', '.') }}"

- name: Tag the repo
command:
cmd: "git tag -f {{ release_number }}"

- name: Get the build number from setuptools-scm
command:
cmd: python -m setuptools_scm
register: setuptools_command_version

- name: Make sure the selected release number and setuptools_scm agree
assert:
that:
release_number == setuptools_command_version.stdout
msg: "We expected the release number to be {{ release_number }} but setuptools-scm wanted it to be {{ setuptools_command_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

0 comments on commit 2902c34

Please sign in to comment.