Skip to content

Commit

Permalink
Merge pull request #131 from openziti/add.version.checking.workflow
Browse files Browse the repository at this point in the history
adds a test workflow for spec vers vs next tag version
  • Loading branch information
andrewpmartinez authored Sep 4, 2024
2 parents 79f609d + 4be2ec4 commit 32d7967
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 13 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/check_versions.py
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.")
30 changes: 30 additions & 0 deletions .github/workflows/version-check.yml
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
2 changes: 1 addition & 1 deletion client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ info:
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 0.26.28
version: 0.26.30
host: demo.ziti.dev
basePath: /edge/client/v1
paths:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ require (
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/sys v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ info:
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
version: 0.26.28
version: 0.26.30
host: demo.ziti.dev
basePath: /edge/management/v1
paths:
Expand Down
2 changes: 1 addition & 1 deletion rest_client_api_server/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rest_client_api_server/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rest_management_api_server/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rest_management_api_server/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source/client.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
swagger: '2.0'
info:
version: 0.26.28
version: 0.26.30
title: Ziti Edge Client
description: OpenZiti Edge Client API
contact:
Expand Down
2 changes: 1 addition & 1 deletion source/management.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
swagger: '2.0'
info:
version: 0.26.28
version: 0.26.30
title: Ziti Edge Management
description: OpenZiti Edge Management API
contact:
Expand Down

0 comments on commit 32d7967

Please sign in to comment.