Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dab releases #3

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions ansible_base/__init__.py
Original file line number Diff line number Diff line change
@@ -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('.'))
1 change: 1 addition & 0 deletions ansible_base/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '0.0.0.dev'
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ classifiers = [
]
dynamic = ["version", "dependencies", "optional-dependencies"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
include = ["ansible_base*"]

Expand All @@ -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]
Expand Down
68 changes: 68 additions & 0 deletions tools/ansible/release.yml
Original file line number Diff line number Diff line change
@@ -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
Loading