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

RELEASE #16

Closed
wants to merge 17 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .ci/store_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
software_version=`python3 -m poetry version --short`
echo $software_version
echo "software_version=${software_version}" >> ${GITHUB_ENV}
115 changes: 115 additions & 0 deletions .ci/update_setup_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os
import re
from datetime import datetime
from sys import argv


# os.environ['GITHUB_WORKSPACE'] = '/Users/wphyo/Projects/unity/unity-data-services'
# os.environ['PR_TITLE'] = 'breaking: test1'
# os.environ['PR_NUMBER'] = '342'
# PR_NUMBER: ${{ github.event.number }}
# PR_TITLE: ${{ github.event.pull_request.title }}


class VersionUpdate:
def __init__(self):
self.pr_title = os.environ.get('PR_TITLE')
self.pr_number = os.environ.get('PR_NUMBER')
self.root_dir = os.environ.get('GITHUB_WORKSPACE')
self.pr_title = self.pr_title.strip().lower()
self.major1, self.minor1, self.patch1 = 0, 0, 0
self.change_log_line, self.setup_py_path = '', ''
# Define a regular expression pattern to match the version
self.version_pattern = r"version\s*=\s*['\"](.*?)['\"]"

def get_new_bumps_from_title(self):
if self.pr_title.startswith('breaking'):
self.major1, self.minor1, self.patch1 = 1, 0, 0
self.change_log_line = '### Added'
elif self.pr_title.startswith('feat'):
self.major1, self.minor1, self.patch1 = 0, 1, 0
self.change_log_line = '### Changed'
elif self.pr_title.startswith('fix') or self.pr_title.startswith('chore'): # TODO chore is bumping up version?
self.major1, self.minor1, self.patch1 = 0, 0, 1
self.change_log_line = '### Fixed'
else:
raise RuntimeError(f'invalid PR Title: {self.pr_title}')

def get_new_version(self, current_version):
# Parse the current version and increment it
major, minor, patch = map(int, current_version.split('.'))
if self.major1 > 0:
return f"{major + 1}.0.0"
if self.minor1 > 0:
return f"{major}.{minor + 1}.0"
return f"{major}.{minor}.{patch + 1}"

def update_version(self, is_release=False):
# Specify the path to your setup.py file
self.setup_py_path = os.path.join(self.root_dir, 'pyproject.toml')
# Read the contents of setup.py
with open(self.setup_py_path, 'r') as setup_file:
setup_contents = setup_file.read()

# Find the current version using the regular expression pattern
current_version = re.search(self.version_pattern, setup_contents).group(1)
print(f'current_version: {current_version}')
if is_release and '.dev' not in current_version:
raise ValueError(f'no development updates to release: {current_version}')

main_version, dev_version = current_version.split('.dev') if '.dev' in current_version else [current_version, '0' *6]
dev_version = '.'.join([dev_version[i:i+2] for i in range(0, 6, 2)])
if is_release:
print('this is a formal release')
self.major1, self.minor1, self.patch1 = [int(k) for k in dev_version.split('.')]
new_version = self.get_new_version(main_version)
else:
print('this is a feature merge')
self.get_new_bumps_from_title()
new_version = ''.join([f'{int(i):02}' for i in self.get_new_version(dev_version).split('.')])
new_version = f'{main_version}.dev{new_version}'
print(f'new_version: {new_version}')

# Replace the old version with the new version in setup.py
updated_setup_contents = re.sub(self.version_pattern, f'version="{new_version}"', setup_contents)

# Write the updated contents back to setup.py
with open(self.setup_py_path, 'w') as setup_file:
setup_file.write(updated_setup_contents)

print(f"Version bumped up from {current_version} to {new_version}")
return new_version

def update_change_log(self):
change_log_path = os.path.join(self.root_dir, 'CHANGELOG.md')
change_log_blob = [
f'## [{new_version_from_setup}] - {datetime.now().strftime("%Y-%m-%d")}',
self.change_log_line,
f'- [#{self.pr_number}](https://github.com/unity-sds/unity-data-services/pull/{self.pr_number}) {self.pr_title}',
''
]
with open(change_log_path, 'r') as change_log_file:
change_logs = change_log_file.read().splitlines()
pattern = r"## \[\d+\.\d+\.\d+.*\] - \d{4}-\d{2}-\d{2}"

inserting_line = 0
for i, each_line in enumerate(change_logs):
if re.search(pattern, each_line):
inserting_line = i
break
# inserting_line = inserting_line - 1 if inserting_line > 0 else inserting_line
for i, each_line in enumerate(change_log_blob):
change_logs.insert(inserting_line, each_line)
inserting_line += 1
change_logs = '\n'.join(change_logs)

with open(change_log_path, 'w') as change_log_file:
change_log_file.write(change_logs)
return


if __name__ == '__main__':
is_releasing = argv[1].strip().upper() == 'RELEASE'
version_update = VersionUpdate()
new_version_from_setup = version_update.update_version(is_releasing)
version_update.update_change_log()
37 changes: 37 additions & 0 deletions .ci/update_version_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
current_branch=`git branch --show-current`
echo "current_branch: ${current_branch}"
#current_branch='develop-2023-10-02'
current_date=$(date +%Y-%m-%dT%H-%M-%S)
temp_branch="chore-version-update--${current_date}"
echo "temp_branch: ${temp_branch}"
commit_message="chore: update version + change log"

env

git stash
git checkout -b ${temp_branch}
git stash pop
git status
echo "setting email and name config"
git config --local user.email "wai.phyo@jpl.nasa.gov"
git config --local user.name ${GITHUB_TRIGGERING_ACTOR}
echo "adding updated files"
git add -u
echo "committing with ${commit_message}"
git commit -m "${commit_message}"
echo "pushing to origin"
git push --force origin $temp_branch
echo "creating PR"
result=`gh pr create --base "${current_branch}" --body "NA" --head "${temp_branch}" --title "${commit_message}"`
echo "PR result $result"
pr_number=`echo $result | grep -oE '[0-9]+$'`
echo "PR number ${pr_number}"
# don't allow auto merge to avoid bad actors using it to merge other code
#gh pr review $pr_number --approve
#echo "merging PR"
#gh pr merge $pr_number --squash --admin
#echo "deleting branch"
#git push origin --delete ${temp_branch}
# mock update
# mock update 9
13 changes: 13 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Artifact generation steps

- Do Nothing in when creating a PR.
- When merging a PR (if title is breaking / feat / bug)
- Bump a version with postfix & create a PR
- When merging a PR with title 'chore: update version'
- Build & upload to PyPi
- Creating Release PR
- Startiwht "Release" + update official version
- When merging a PR to master
- Build & upload to Pypi
- Create a Release
- Add Link to PyPi
28 changes: 28 additions & 0 deletions .github/workflows/feature_pr_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Feature PR Merge
on:
pull_request:
types: [ closed ]
branches: [ develop ]

env:
ARTIFACT_BASE_NAME: mdps-ds-lib
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ github.token }}
jobs:
if_merged:
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.title, 'update version + change log'))
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- run: |
echo "${PR_TITLE} -- ${PR_NUMBER}"
- run: |
python3 "${GITHUB_WORKSPACE}/.ci/update_setup_version.py" FEATURE
- run: |
chmod +x "${GITHUB_WORKSPACE}/.ci/update_version_commit.sh"
"${GITHUB_WORKSPACE}/.ci/update_version_commit.sh"
29 changes: 29 additions & 0 deletions .github/workflows/feature_pr_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Feature PR PYPI
on:
pull_request:
types: [ closed ]
branches: [ develop ]

env:
ARTIFACT_BASE_NAME: mdps-ds-lib
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ github.token }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

jobs:
if_merged:
if: github.event.pull_request.merged == true && (contains(github.event.pull_request.title, 'update version + change log'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- run: |
python3 -m pip install poetry twine
- run: |
python3 -m poetry build
- run: |
python3 -m twine upload --repository pypi dist/*
28 changes: 28 additions & 0 deletions .github/workflows/release_pr_create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release PR Create
on:
pull_request:
types: [ opened ]
branches: [ main ]

env:
ARTIFACT_BASE_NAME: mdps-ds-lib
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ github.token }}
jobs:
if_pr_opened:
if: github.event.pull_request.merged == false && !(contains(github.event.pull_request.title, 'update version + change log'))
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- run: |
echo "${PR_TITLE} -- ${PR_NUMBER}"
- run: |
python3 "${GITHUB_WORKSPACE}/.ci/update_setup_version.py" RELEASE
- run: |
chmod +x "${GITHUB_WORKSPACE}/.ci/update_version_commit.sh"
"${GITHUB_WORKSPACE}/.ci/update_version_commit.sh"
51 changes: 51 additions & 0 deletions .github/workflows/release_pr_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release PR Merge
on:
pull_request:
types: [ closed ]
branches: [ develop ]

env:
ARTIFACT_BASE_NAME: mdps-ds-lib
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ github.token }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

jobs:
if_merged:
if: github.event.pull_request.merged == true && (contains(github.event.pull_request.title, 'update version + change log'))
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- run: |
python3 -m pip python3 -m pip install poetry twine
- run: |
python3 -m poetry build
- run: |
python3 -m twine upload --repository pypi dist/*

- run: |
# make file runnable, might not be necessary
chmod +x "${GITHUB_WORKSPACE}/.ci/store_version.sh"
"${GITHUB_WORKSPACE}/.ci/store_version.sh"

- name: Create Release
id: create_release
if: ${{ contains(github.ref, 'master') }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: "v${{ env.software_version }}"
release_name: "Release v${{ env.software_version }} - ${{ github.ref }}"
body: |
Changes in this release:
${{ github.event.head_commit.message }}
body_path: release.md
draft: false
prerelease: false
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.1.1] - 2024-09-11

- [#16](https://github.com/unity-sds/unity-data-services/pull/16) release

## [0.1.0.dev000005] - 2024-09-10
### Fixed
- [#13](https://github.com/unity-sds/unity-data-services/pull/13) fix: wrong insertion location in changelog

## [0.1.0-D-0.0.1] - 2024-09-09
### Fixed
- [#2](https://github.com/unity-sds/unity-data-services/pull/2) fix: getting it working.

## [0.1.0-D-0.0.2] - 2024-09-09
### Fixed
- [#4](https://github.com/unity-sds/unity-data-services/pull/4) fix: sample feature 2

## [0.1.0.dev003] - 2024-09-10
### Fixed
- [#6](https://github.com/unity-sds/unity-data-services/pull/6) fix: valid pypi version

## [0.1.0.dev000004] - 2024-09-10
### Fixed
- [#11](https://github.com/unity-sds/unity-data-services/pull/11) fix: still version typo

## [0.1.0] - 2024-09-10
### Added
- Copied code form https://github.com/unity-sds/unity-data-services
Loading
Loading