generated from openziti/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a test workflow for spec vers vs next tag version
This commit adds workflow to check: - that the version in the spec files is consistent between all files (generated spec files and source files) - the version used in those files is the next patch, minor, or major version number of the most recent tag This also bumps the version number of the repo to pass the above tests and re-sync the repo tag versions w/ spec versions.
- Loading branch information
1 parent
79f609d
commit 4be2ec4
Showing
12 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# !/usr/bin/env python3 | ||
import yaml | ||
import semver | ||
import subprocess | ||
|
||
# Define the file paths | ||
files = ['client.yml', 'management.yml', 'source/client.yml', 'source/management.yml'] | ||
|
||
|
||
# Function to extract version from YAML | ||
def extract_version(file_path): | ||
with open(file_path, 'r') as f: | ||
content = yaml.safe_load(f) | ||
return content.get('info', {}).get('version') | ||
|
||
|
||
# Extract versions from all files | ||
versions = [extract_version(file) for file in files] | ||
|
||
# Check if all versions are the same | ||
if len(set(versions)) != 1: | ||
raise ValueError(f"Versions do not match across files: {versions}: please make sure all files {files} have the same version") | ||
|
||
# Get the current version | ||
current_version = versions[0] | ||
|
||
# Check that current version is a valid semver | ||
if not semver.VersionInfo.is_valid(current_version): | ||
raise ValueError(f"Current version '{current_version}' is not a valid semver.") | ||
|
||
# Parse current version | ||
current_version_info = semver.VersionInfo.parse(current_version) | ||
|
||
# Get the latest git tag | ||
result = subprocess.run(['git', 'describe', '--tags', '--abbrev=0', 'origin/main'], capture_output=True, text=True) | ||
latest_tag = result.stdout.strip() | ||
print(f"Latest tag: {latest_tag}") | ||
latest_tag = latest_tag.lstrip('v') | ||
print(f"Latest tag stripped of leading v: {latest_tag}") | ||
# Parse the latest tag as a semver | ||
if not semver.VersionInfo.is_valid(latest_tag): | ||
raise ValueError(f"Latest git tag '{latest_tag}' is not a valid semver.") | ||
|
||
latest_version_info = semver.VersionInfo.parse(latest_tag) | ||
|
||
# Calculate possible next versions | ||
next_patch_version = str(latest_version_info.bump_patch()) | ||
next_minor_version = str(latest_version_info.bump_minor()) | ||
next_major_version = str(latest_version_info.bump_major()) | ||
|
||
# Check if the current version matches one of the expected next versions | ||
if current_version not in [next_patch_version, next_minor_version, next_major_version]: | ||
raise ValueError( | ||
f"Current version '{current_version}' does not match the next expected versions: " | ||
f"patch '{next_patch_version}', minor '{next_minor_version}', or major '{next_major_version}'." | ||
) | ||
|
||
print(f"All versions match and are valid. Current version '{current_version}' matches one of the next possible versions.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Check Version Consistency and Git Tag Match | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-versions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Fetch all tags | ||
run: git fetch --tags | ||
|
||
- name: List latest tag | ||
run: git describe --tags --abbrev=0 origin/main | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' # specify the Python version you want to use | ||
|
||
- name: Install dependencies | ||
run: pip install pyyaml semver | ||
|
||
- name: Parse and check versions | ||
run: python .github/workflows/check_versions.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters