Skip to content

Commit

Permalink
Merge pull request #159 from input-output-hk/dev
Browse files Browse the repository at this point in the history
Improvement of CI script for versioning bundle of Cargo workspace crates/packages
  • Loading branch information
andrcmdr committed Apr 17, 2021
2 parents e0b31e9 + 18e5ad4 commit 4cbeacd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -27,7 +27,7 @@ jobs:

- id: release_info
name: Get release information
run: python3 ci/release-info.py "$GITHUB_EVENT_NAME"
run: python3 ./ci/release-info.py "$GITHUB_EVENT_NAME"

- id: create_release
name: Create a draft release
Expand Down
65 changes: 48 additions & 17 deletions ci/release-info.py
Expand Up @@ -5,25 +5,47 @@
from datetime import date
from subprocess import Popen, PIPE

def check_version(crate):
# Checks package version for matching with the current tag reference
if ref is not None and ref != 'refs/tags/v' + str(crate[0]):
return 0
else:
return 1

def read_version(manifest_path, ref=None):
"""
Reads the package version from the manifest file,
and optionally validates it against the given tag reference.
"""
p = Popen(
['cargo', 'read-manifest', '--manifest-path', manifest_path],
stdout=PIPE
)
d = json.load(p.stdout)
version = d['version']
if ref is not None and ref != 'refs/tags/v' + version:
def print_error(crate, match):
# Print errors for packages which versions didn't match tag reference
if not match:
print(
'::error file={path}::version {0} does not match release tag {1}'
.format(version, ref, path=manifest_path)
'::error file={path}::version {version} does not match release tag {tag}'
.format(tag = ref, version = str(crate[0]), path = str(crate[1]))
)

def bundle_version(crates):
# Reads package versions from workspace manifest file
channel = Popen(
['cargo', 'metadata', '--format-version=1', '--no-deps'],
stdout=PIPE
)

# parse json data
data = json.load(channel.stdout).get('packages')

# read, map and assign workspace crates versions to bundle package versions
for package, _ in enumerate(data):
if data[package]['name'] in crates:
crates[data[package]['name']].append(data[package]['version'])
crates[data[package]['name']].append(data[package]['manifest_path'])

# Checks package versions of the crates bundle for consistency with the given tag reference
consistency = list(map(check_version, list(crates.values())))

# Print errors for packages which versions didn't match tag reference
if not all(consistency):
list(map(print_error, list(crates.values()), consistency))
sys.exit(1)
return version
elif all(consistency):
version = list(crates.values())[0][0]
return version


event_name = sys.argv[1]
Expand All @@ -46,10 +68,18 @@ def read_version(manifest_path, ref=None):
else:
raise ValueError('unexpected event name ' + event_name)

version = read_version('vit-servicing-station-server/Cargo.toml', ref)

# Cargo workspace crates/packages for versioning bundle
crates = {
'vit-servicing-station-cli':[],
'vit-servicing-station-lib':[],
'vit-servicing-station-server':[],
'vit-servicing-station-tests':[]
}

version = bundle_version(crates)
release_flags = ''
if release_type == 'tagged':
read_version('vit-servicing-station-cli/Cargo.toml', ref)
tag = 'v' + version
elif release_type == 'nightly':
version = re.sub(
Expand All @@ -62,3 +92,4 @@ def read_version(manifest_path, ref=None):

for name in 'version', 'date', 'tag', 'release_type', 'release_flags':
print('::set-output name={0}::{1}'.format(name, globals()[name]))

0 comments on commit 4cbeacd

Please sign in to comment.