From 34fc8d7ac3dbd9b1363569ae085357ab92e9d526 Mon Sep 17 00:00:00 2001 From: Chaoyi Yuan Date: Tue, 9 Apr 2024 14:25:15 +0800 Subject: [PATCH] build: move update version logic to workflow --- .github/workflows/CD.yml | 32 +++++++++++++++++++++++++++-- .github/workflows/update_version.py | 27 ------------------------ 2 files changed, 30 insertions(+), 29 deletions(-) delete mode 100644 .github/workflows/update_version.py diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index a672bafb24c..e89ea0fc210 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -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 + 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: | diff --git a/.github/workflows/update_version.py b/.github/workflows/update_version.py deleted file mode 100644 index 7af12f43303..00000000000 --- a/.github/workflows/update_version.py +++ /dev/null @@ -1,27 +0,0 @@ -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) \ No newline at end of file