Skip to content

Commit

Permalink
ci: change version on dependabot branches
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Jan 29, 2024
1 parent 8b2e191 commit f17fab5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ jobs:
echo 'no main, no push'
fi
dependabot:
docker:
- image: python
steps:
- checkout
- run:
name: change version of csproj changed files
command: python .github/change-version.py

workflows:
version: 2.1
all:
Expand All @@ -329,3 +338,12 @@ workflows:
- tfa
- xml
- eml

dependency:
jobs:
- dependabot:
filters:
branches:
only:
- /^dependabot/.+$/

53 changes: 53 additions & 0 deletions .github/change-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from os import system
from subprocess import PIPE, run
from re import search, sub
from sys import argv


def terminal(command):
process = run(command.split(' '), stdout=PIPE)
return process.stdout.decode('utf-8').split('\n')


commits = terminal('git log origin/main.. --pretty=format:%s')
diff_files = terminal('git diff origin/main --stat')

commit_acronyms = {
'Eml': 'eml',
'MVC': 'mvc',
'NHibernate': 'nh',
'TwoFactorAuth': 'tfa',
'Util': 'util',
'XML': 'xml',
}

for diff_file in diff_files:
if '.csproj' not in diff_file:
continue

file_path = diff_file.split(' ')[1]
project = file_path.split('/')[1]
acronym = commit_acronyms[project]

commit_message = f'{acronym}: update version'

if commit_message in commits:
print(f'Already committed for project {project}')

else:
with open(file_path) as file:
content = file.read()

pattern = r'(<Version>\d+\.\d+\.)(\d+)(</Version>)'
version = search(pattern, content)

current = int(version.group(2))
new = current + 1
content = sub(pattern, rf'\g<1>{new}\g<3>', content)

with open(file_path, 'w') as file:
file.write(content)

system(f'git add {file_path}')
system(f'git commit -m "{commit_message}"')
system(f'git push')

0 comments on commit f17fab5

Please sign in to comment.