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

build: move update version logic to workflow #8

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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
32 changes: 30 additions & 2 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,37 @@ jobs:
azdev extension add apic-extension

# Append commit hash to the version. E.g. 1.0.0b4+abc1234
- name: Generate and update version
- name: Update version
run: |
python ./github/workflows/update_version.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe .github/workflows/update_version.py not ./github/...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's another problem. But since I'm not checking out new branch from main, feature branch won't have this .py file under .github. Seems it's better to put the python code to workflow file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be all right, you can take any way to run python code.

python -c "
import re
import os

# Open the file
with open('src/apic-extension/setup.py', 'r') as f:
content = f.read()

# Find the version string
version_match = re.search(r'VERSION = \'(.*?)\'', content)
if version_match is None:
raise ValueError('Could not find version string in setup.py')

# Extract the original version
original_version = version_match.group(1)

# Get the commit hash
commit_hash = os.getenv('GITHUB_SHA', 'daily')[:7]

# Create the new version string
new_version = original_version + '+' + commit_hash

# Replace the old version string with the new one
content_new = re.sub(r'VERSION = \'(.*?)\'', f'VERSION = \'{new_version}\'', content)

# Write the updated content back to the file
with open('src/apic-extension/setup.py', 'w') as f:
f.write(content_new)
"

- name: Build binary
run: |
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/update_version.py

This file was deleted.

Loading