Skip to content

Commit

Permalink
Improvements to CI and Release workflow (#18)
Browse files Browse the repository at this point in the history
* Remove stale import

* Add Version Bump Script and package.json

* Update used CI Scripts to latest version

* Change Actions Version to main version without typing the minor version

* Add Version Bump Workflow

* Add Draft Release workflow
Add release.yml for templating release notes
  • Loading branch information
simonl169 authored May 26, 2024
1 parent ef80c0f commit 6c287a8
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
changelog:
categories:
- title: ⚠️ Breaking Changes
labels:
- breaking-change

- title: 🖥️ Web
labels:
- web

- title: 🐍 Python
labels:
- python

- title: ⚡ API
labels:
- api

- title: 📓 Documentation
labels:
- documentation

- title: 🔨 Maintenance
labels:
- deployment
- dependencies
- renovate
- maintenance
- tech-debt

- title: Other changes
labels:
- "*"
55 changes: 55 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Bump Version and Commit to main

on:
workflow_dispatch:
inputs:
serverBump:
description: 'Bump Script Version'
required: true
default: 'false'
type: choice
options:
- 'False'
- minor
- patch
- major


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-root
cancel-in-progress: true

jobs:
bump_version:
runs-on: ubuntu-latest

outputs:
ref: ${{ steps.push-tag.outputs.commit_long_sha }}

steps:
- name: Checkout
uses: actions/checkout@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token

- name: setup python
uses: actions/setup-python@v5
with:
python-version: '3.12' # install the python version needed

- name: install python packages
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Bump version
run: python test.py --server="${{ inputs.serverBump }}"

- name: Commit and tag
id: push-tag
uses: EndBug/add-and-commit@v9
with:
author_name: Simon_Bot
message: 'Version ${{ env.NEXT_SERVER }}'
tag: ${{ env.NEXT_SERVER }}
push: true
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions .github/workflows/prepare_draft_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Prepare new draft release

on:
workflow_dispatch:


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-root
cancel-in-progress: true

jobs:
prepare_release:
runs-on: ubuntu-latest
needs: build_mobile

steps:
- name: Checkout
uses: actions/checkout@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create draft release
uses: softprops/action-gh-release@v2
with:
draft: true
tag_name: ${{ env.NEXT_SERVER }}
generate_release_notes: true
# body_path: misc/release/notes.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
89 changes: 89 additions & 0 deletions bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json
import argparse
import os


def get_current_version(file: str = "package.json") -> tuple[str, str, str]:
"""
This reads a json file and return the current version from the field 'version'
:param file: input a json file which has the key 'data'
:return: returns major, minor and patch version as a tuple of strings
"""
# print(f'Reading current version from file {file}')
with open(file, 'r') as f:
data = json.load(f)
major, minor, patch = data['version'].split(".")

return major, minor, patch


def print_current_version(major: str, minor: str, patch: str) -> None:
print(f"Current Version: {major}.{minor}.{patch}")


def print_next_version(major: str, minor: str, patch: str) -> None:
print(f"Next Version: {major}.{minor}.{patch}")


def parse_version_bump():
parser = argparse.ArgumentParser(description="Script that adds 3 numbers from CMD")
parser.add_argument("--server", "-s", required=False, type=str)
args = parser.parse_args()

if args.server == "major":
return "major"
elif args.server == "minor":
return "minor"
elif args.server == "patch":
return "patch"
elif args.server == "False":
return "None"
else:
return "None"


def bump_version(current_major: str, current_minor: str, current_patch: str, bump: str) -> tuple[str, str, str]:
next_major = current_major
next_minor = current_minor
next_patch = current_patch
if bump == "major":
next_major = str(int(next_major) + 1)
elif bump == "minor":
next_minor = str(int(next_minor) + 1)
elif bump == "patch":
next_patch = str(int(next_patch) + 1)
elif bump == "False":
pass

return next_major, next_minor, next_patch


def update_json_file(next_major: str, next_minor: str, next_patch: str, file: str = "package.json"):
with open(file, 'r') as f:
data = json.load(f)
f.close()
data['version'] = f"{next_major}.{next_minor}.{next_patch}"
with open(file, 'w') as f:
json_object = json.dumps(data, indent=4)
f.write(json_object)
f.close()
print("Updated Version")


if __name__ == "__main__":

major, minor, patch = get_current_version()
print_current_version(major, minor, patch)
bump = parse_version_bump()
next_major, next_minor, next_patch = bump_version(major, minor, patch, bump)
print_next_version(next_major, next_minor, next_patch)
update_json_file(next_major, next_minor, next_patch)

if os.getenv("GITHUB_ACTIONS") == "true":
import os

env_file = os.getenv('GITHUB_ENV')

with open(env_file, "a") as myfile:
myfile.write(f"NEXT_SERVER={next_major}.{next_minor}.{next_patch}")
1 change: 0 additions & 1 deletion dns_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pydig
import json
from notifications import Notifier
from owl import print_owl
from config import load_config


Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "dns-owl",
"version": "0.3.1"
}

0 comments on commit 6c287a8

Please sign in to comment.