Skip to content

Commit

Permalink
Update release (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
osoucy committed Dec 12, 2023
1 parent 3c4a857 commit 2246c9f
Show file tree
Hide file tree
Showing 32 changed files with 838 additions and 155 deletions.
87 changes: 87 additions & 0 deletions .github/scripts/bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import logging
from datetime import datetime
from packaging import version

script_root = os.path.dirname(__file__)
laktory_root = "./settus/"


def main():

# Filepaths
version_filepath = os.path.join(laktory_root, "_version.py")
local_env_filepath = os.path.join(script_root, "git.env")
git_env_filepath = os.getenv("GITHUB_OUTPUT", local_env_filepath)
changelog_filepath = os.path.join("./", "CHANGELOG.md")

# Read version file
with open(version_filepath) as fp:
v0 = fp.read().split("=")[-1].strip().replace('"', '')
v0 = version.parse(v0)
v1 = version.Version(f"{v0.major}.{v0.minor}.{v0.micro + 1}")
print(f"Bumping laktory to {v1}")

# Update version file
print(f"Updating _version.py")
with open(version_filepath, "w") as fp:
fp.write(f'VERSION = "{v1}"')

# Set version as git action variable
print(f"Setting git env var version {git_env_filepath}")
with open(git_env_filepath, 'a') as fp:
fp.write(f"version={v1}")

# Update CHANGELOG
update_changelog(changelog_filepath, v0, v1)

# Cleanup
if git_env_filepath == local_env_filepath and os.path.exists(local_env_filepath):
os.remove(local_env_filepath)


def update_changelog(changelog_filepath, v0, v1):

# Update CHANGELOG
print(f"Updating changelog")
with open(changelog_filepath, 'r') as fp:
content = fp.read()

# Set version line
version_line = f'## [{v0}] - Unreleased'

# Validate
if version_line not in content:
msg = f"CHANGELOG does not include version {v0}"
print('ValueError: ' + msg)
raise ValueError(msg)

# Update current version release date
today = datetime.utcnow()
new_version_line = f"## [{v0}] - {today.strftime('%Y-%m-%d')}"
content = content.replace(version_line, new_version_line)

# Add placeholder for next version
next_version_lines = [
'# Release History',
'',
f'## [{v1}] - Unreleased',
'###Added',
'* n/a',
'###Fixed',
'* n/a',
'###Updated',
'* n/a',
'###Breaking changes',
'* n/a',
''
]
content = content.replace('# Release History\n', '\n'.join(next_version_lines))

# Write
with open(changelog_filepath, 'w') as fp:
fp.write(content)


if __name__ == "__main__":
main()
100 changes: 95 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: release

on:
pull_request:
types:
- closed
workflow_dispatch:
logLevel:
description: 'Log level'
default: 'info'
branches:
- main

jobs:
release:
if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') }}
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -28,3 +28,93 @@ jobs:
TWINE_REPOSITORY_URL: ${{ vars.TWINE_REPOSITORY_URL }}
TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}

tag:
permissions:
contents: write # required to push release tag
runs-on: ubuntu-latest
needs: publish
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get versions
id: get_version
run: |
import os
with open("./settus/_version.py") as fp:
v = fp.read().split("=")[-1].strip().replace('"', '')
with open(os.environ['GITHUB_OUTPUT'], 'a') as fp:
print(f"version={v}", file=fp)
print(f"Releasing settus {v}")
shell: python

- name: Set up Git
run: git config --global user.email "actions@github.com" && git config --global user.name "GitHub Actions"

- name: Create release tag
run: git tag v${{ steps.get_version.outputs.version }}

- name: Push release tag
run: git push origin v${{ steps.get_version.outputs.version }}


bump:
permissions:
contents: write # required to push new branch
pull-requests: write # required to create pull-request
runs-on: ubuntu-latest
needs: tag
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Bump version
id: bump_version
run: python ./.github/scripts/bump_version.py

- name: Set up Git
run: git config --global user.email "okubot@okube.ai" && git config --global user.name "okube-git-bot"

- name: Commit changes
run: |
git checkout -b version-bump-v${{ steps.bump_version.outputs.version }}
git add ./settus/_version.py
git add ./CHANGELOG.md
git commit -m "version bump"
- name: Push changes
uses: ad-m/github-push-action@v0.8.0
with:
branch: version-bump-v${{ steps.bump_version.outputs.version }}

# PR creation can't use secrets.GITHUB_TOKEN as it will prevent triggering
# other workflows.
# TODO: Setup git user for specifically creating PR
- name: Create pull request
run: gh pr create --base main --head version-bump-v${{ steps.bump_version.outputs.version }} --title "version-bump-${{ steps.bump_version.outputs.version }}" --body "Automated version bump" --label version-bump
env:
GH_TOKEN: ${{ secrets.GIT_ACTIONS_TOKEN }}

- name: Approve pull request
run: gh pr review --approve --body "Automatically approved by GitHub Actions"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# TODO: Review why branch is not deleted
- name: Merge pull request
run: gh pr merge --auto --squash --delete-branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

doc:
permissions:
contents: write
runs-on: ubuntu-latest
needs: tag
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Publish doc
run: make publishdoc
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,32 @@ jobs:
- '3.10'
- '3.11'
steps:
- name: Check if run tests
env:
VERSION_BUMP: ${{ contains(github.event.pull_request.labels.*.name, 'version-bump') }}
run: |
if ${VERSION_BUMP} == true; then
echo "run_tests=false" >> $GITHUB_ENV
echo "tests will be skipped"
else
echo "run_tests=true" >> $GITHUB_ENV
echo "tests will be run"
fi
- name: Checkout
if: ${{ env.run_tests == 'true' && success()}}
uses: actions/checkout@v3

# - name: Unshallow
# run: git fetch --prune --unshallow

- uses: actions/setup-python@v4
if: ${{ env.run_tests == 'true' && success()}}
with:
python-version: ${{ matrix.pyVersion }}

- name: Run lean tests
if: ${{ env.run_tests == 'true' && success()}}
run: make dev_lean test
env:
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Expand All @@ -41,6 +56,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Run tests
if: ${{ env.run_tests == 'true' && success()}}
run: make dev test
env:
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Expand Down
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# PyCharm configuration
**/.idea/**

# Local settings and environment variables
# Seecret values
secrets/*.*

# --------------------------------------------------------------------------- #
# Installation and build #
# --------------------------------------------------------------------------- #

#**/*.egg-info/**
dist
**/*.egg-info
build
#**/dist/**
dist
/site/

# --------------------------------------------------------------------------- #
# Testing and coverage #
Expand All @@ -34,6 +34,9 @@ build
coverage.xml
htmlcov

# Test data
tests/data

# Test results
junit

Expand Down
53 changes: 21 additions & 32 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
# Release History

## [0.0.9]

**Added**
-

**Fixed**
-

**Updated**
-
## [0.0.9] - Unreleased
###Added
* Documentation

## [0.0.8] - 2023-09-24

**Added**
- Lean tests for installation without optional dependencies
###Added
* Lean tests for installation without optional dependencies

## [0.0.7] - 2023-09-24

**Fixed**
- ModuleNotFoundError with optional dependencies

###Fixed
* ModuleNotFoundError with optional dependencies

## [0.0.6] - 2023-09-23
**Fixed**
- ModuleNotFoundError with optional dependencies

**Updated**
- Documentation to include required environment variables.
###Fixed
* ModuleNotFoundError with optional dependencies
###Updated
* Documentation to include required environment variables.

## [0.0.5] - 2023-09-22
**Added**
- Support for AWS secrets
###Added
* Support for AWS secrets

## [0.0.4] - 2023-09-21
**Added**
- Support for the same alias(es) used across multiple fields
###Added
* Support for the same alias(es) used across multiple fields

## [0.0.3] - 2023-09-17
**Added**
- Azure Keyvault support
###Added
* Azure Keyvault support

## [0.0.2] - 2023-07-30
**Updated**
- Changed build backend from flit to setuptools
###Updated
* Changed build backend from flit to setuptools

## [0.0.1] - 2023-07-16
**Added**
- Initial pypi release
###Added
* Initial pypi release
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ publish:
pip install build twine
python -m build
twine upload dist/*

publishdoc:
pip install mkdocs mkdocstrings[python] mkdocs-material
mkdocs gh-deploy --force
Loading

0 comments on commit 2246c9f

Please sign in to comment.