Skip to content

feat: auto increase version + update Changelog #224

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

Merged
merged 30 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26bd530
pr merge testing
wphyojpl Sep 21, 2023
b8219d8
using existing workflow
wphyojpl Sep 21, 2023
f09bd59
Merge pull request #208 from unity-sds/git-hook
wphyojpl Sep 21, 2023
1f7d678
next step
wphyojpl Sep 21, 2023
69cb24d
next step (#209)
wphyojpl Sep 21, 2023
2dbb38d
python bug
wphyojpl Sep 21, 2023
35a3a1b
Merge branch 'develop-temp' into git-hook
wphyojpl Sep 21, 2023
773b5aa
chore: dummy commit
wphyojpl Sep 21, 2023
d242b67
Merge pull request #210 from unity-sds/git-hook
wphyojpl Sep 21, 2023
09120d9
fix: add debug statement (#211)
wphyojpl Sep 21, 2023
dbb7182
fix: still fixing env bug (#212)
wphyojpl Sep 21, 2023
fe0aebd
fix: cannot use >> in yaml (#213)
wphyojpl Sep 21, 2023
5a33b38
fix: yaml format error (#214)
wphyojpl Sep 21, 2023
b0c249f
fix: yaml error still (#215)
wphyojpl Sep 21, 2023
97d719c
fix: still yaml error (#216)
wphyojpl Sep 21, 2023
27dae93
fix: env bug now (#217)
wphyojpl Sep 21, 2023
4795fae
feat: merge version update to git (#218)
wphyojpl Sep 21, 2023
69bb50a
fix: git bot user to push changes (#219)
wphyojpl Sep 21, 2023
13cfee6
chore: update version + change log
github-actions[bot] Sep 21, 2023
733d906
fix:version increment does not work directly (#220)
wphyojpl Sep 21, 2023
d89d1ac
chore: update version + change log
github-actions[bot] Sep 21, 2023
b8d2441
fix: remove print statements (#221)
wphyojpl Sep 21, 2023
94538fa
chore: update version + change log
github-actions[bot] Sep 21, 2023
2cb1f05
feat: wrong insertion point for changelog (#222)
wphyojpl Sep 21, 2023
1bd4ed3
chore: update version + change log
github-actions[bot] Sep 21, 2023
b2adc7e
breaking: formatting changelog file (#223)
wphyojpl Sep 21, 2023
4e1120f
chore: update version + change log
github-actions[bot] Sep 21, 2023
d6a7214
chore: reset versions
wphyojpl Sep 21, 2023
3e101f2
fix: revert some changes to keep it the same as develop
wphyojpl Sep 21, 2023
a0402a9
Merge branch 'develop' into develop-temp
wphyojpl Sep 28, 2023
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
32 changes: 32 additions & 0 deletions .github/workflows/pr_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build PR Merge
on:
pull_request:
types: [closed]

env:
ARTIFACT_BASE_NAME: cumulus_lambda_functions
PR_NUMBER: ${{ github.event.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- run: |
# make file runnable, might not be necessary
chmod +x "${GITHUB_WORKSPACE}/ci.cd/store_version.sh"
echo "what the ..."
"${GITHUB_WORKSPACE}/ci.cd/store_version.sh"
- run: |
artifact_file_name="${{ env.ARTIFACT_BASE_NAME }}-${{ env.software_version }}.zip"
echo "${PR_TITLE} -- ${PR_NUMBER}"
- run: |
python3 "${GITHUB_WORKSPACE}/ci.cd/update_setup_version.py" install
- run: |
chmod +x "${GITHUB_WORKSPACE}/ci.cd/update_version_commit.sh"
"${GITHUB_WORKSPACE}/ci.cd/update_version_commit.sh"
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added lambda for parsing metadata from Sounder SIPS L0 metadata files [#14](https://github.com/unity-sds/unity-data-services/issues/14)
### Fixed
- Pushed docker image to ghcr.io
- Pushed docker image to ghcr.io
2 changes: 1 addition & 1 deletion ci.cd/store_version.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
software_version=`python3 ${GITHUB_WORKSPACE}/setup.py --version`
echo $software_version
echo "software_version=${software_version}" >> ${GITHUB_ENV}
echo "software_version=${software_version}" >> ${GITHUB_ENV}
87 changes: 87 additions & 0 deletions ci.cd/update_setup_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import re
from datetime import datetime
# 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 }}
pr_title = os.environ.get('PR_TITLE')
pr_number = os.environ.get('PR_NUMBER')
root_dir = os.environ.get('GITHUB_WORKSPACE')
pr_title = pr_title.strip().lower()

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

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

def update_version():
# Specify the path to your setup.py file
setup_py_path = os.path.join(root_dir, 'setup.py')
# Define a regular expression pattern to match the version
version_pattern = r"version\s*=\s*['\"](.*?)['\"]"

# Read the contents of setup.py
with open(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(version_pattern, setup_contents).group(1)
new_version = get_new_version(current_version)

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

# Write the updated contents back to setup.py
with open(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


new_version_from_setup = update_version()
def update_change_log():
change_log_path = os.path.join(root_dir, 'CHANGELOG.md')
change_log_blob = [
f'## [{new_version_from_setup}] - {datetime.now().strftime("%Y-%m-%d")}',
change_log_line,
f'- [#{pr_number}](https://github.com/unity-sds/unity-data-services/pull/{pr_number}) {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
update_change_log()
9 changes: 9 additions & 0 deletions ci.cd/update_version_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
git status
git diff
current_branch=`git branch --show-current`
git add -u
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m 'chore: update version + change log'
git push origin $current_branch