Skip to content

Commit 7818aeb

Browse files
committed
release: change release process
Consolidate version information in the Cargo.toml file. Also moving forward we will bump version following a release by using -dev suffixes. Add a new bump-version.sh tool to help with this task Resolves GitHub issue #3057 Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent b79306d commit 7818aeb

File tree

10 files changed

+123
-123
lines changed

10 files changed

+123
-123
lines changed

build.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::process::Command;
5-
64
// this build script is called on en every `devtool build`,
75
// embedding the FIRECRACKER_VERSION directly in the resulting binary
86
fn main() {
9-
let firecracker_version = Command::new("git")
10-
.args(["describe", "--dirty"])
11-
.output()
12-
.ok()
13-
.and_then(|output| {
14-
if output.status.success() {
15-
return Some(output.stdout);
16-
}
17-
None
18-
})
19-
.and_then(|version_bytes| String::from_utf8(version_bytes).ok())
20-
.map(|version_string| version_string.trim_start_matches('v').to_string())
21-
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
22-
7+
let firecracker_version = env!("CARGO_PKG_VERSION").to_string();
238
println!(
249
"cargo:rustc-env=FIRECRACKER_VERSION={}",
2510
firecracker_version

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ def firecracker_id(fc):
463463

464464
def firecracker_artifacts(*args, **kwargs):
465465
"""Return all supported firecracker binaries."""
466-
max_version = [int(x) for x in get_firecracker_version_from_toml().split(".")]
466+
version = get_firecracker_version_from_toml()
467467
# until the next minor version (but not including)
468-
max_version[1] += 1
468+
max_version = (version.major, version.minor + 1, 0)
469469
params = {
470470
"min_version": "1.2.0",
471471
"max_version_open": ".".join(str(x) for x in max_version),

tests/framework/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pathlib import Path
1818
from typing import Dict
1919

20+
import packaging.version
2021
import psutil
2122
from retry import retry
2223
from retry.api import retry_call
@@ -607,11 +608,9 @@ def get_firecracker_version_from_toml():
607608
the code has not been released.
608609
"""
609610
cmd = "cd ../src/firecracker && cargo pkgid | cut -d# -f2 | cut -d: -f2"
610-
611-
rc, stdout, _ = run_cmd(cmd)
612-
assert rc == 0
613-
614-
return stdout
611+
rc, stdout, stderr = run_cmd(cmd)
612+
assert rc == 0, stderr
613+
return packaging.version.parse(stdout)
615614

616615

617616
def compare_versions(first, second):

tests/integration_tests/functional/test_api.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
import os
88
import platform
99
import resource
10-
import subprocess
1110
import time
1211

12+
import packaging.version
1313
import pytest
1414

15-
import framework.utils_cpuid as utils
1615
import host_tools.drive as drive_tools
1716
import host_tools.network as net_tools
17+
from framework import utils_cpuid
1818
from framework.artifacts import NetIfaceConfig, SnapshotType
1919
from framework.builder import MicrovmBuilder, SnapshotBuilder
20-
from framework.utils import is_io_uring_supported
20+
from framework.utils import get_firecracker_version_from_toml, is_io_uring_supported
2121

2222
MEM_LIMIT = 1000000000
2323

@@ -469,7 +469,7 @@ def test_api_machine_config(test_microvm_with_api):
469469
assert test_microvm.api_session.is_status_no_content(response.status_code)
470470

471471
response = test_microvm.actions.put(action_type="InstanceStart")
472-
if utils.get_cpu_vendor() == utils.CpuVendor.AMD:
472+
if utils_cpuid.get_cpu_vendor() == utils_cpuid.CpuVendor.AMD:
473473
# We shouldn't be able to apply Intel templates on AMD hosts
474474
fail_msg = "CPU vendor mismatched between actual CPU and CPU template"
475475
assert test_microvm.api_session.is_status_bad_request(response.status_code)
@@ -1008,20 +1008,14 @@ def test_api_version(test_microvm_with_api):
10081008
# Validate VM version post-boot is the same as pre-boot.
10091009
assert preboot_response.json() == postboot_response.json()
10101010

1011-
# Check that the version is the same as `git describe --dirty`.
1012-
# Abbreviated to post-tag commit metadata
1013-
out = subprocess.check_output(["git", "describe", "--dirty"]).decode()
1014-
1015-
# Skip the "v" at the start
1016-
tag_version = out[1:].strip()
1017-
1018-
# Git tag should match FC API version
1019-
assert (
1020-
tag_version == preboot_response.json()["firecracker_version"]
1021-
), "Expected [{}], Actual [{}]".format(
1022-
preboot_response.json()["firecracker_version"], tag_version
1011+
cargo_version = get_firecracker_version_from_toml()
1012+
api_version = packaging.version.parse(
1013+
preboot_response.json()["firecracker_version"]
10231014
)
10241015

1016+
# Cargo version should match FC API version
1017+
assert cargo_version == api_version
1018+
10251019

10261020
def test_api_vsock(bin_cloner_path):
10271021
"""
@@ -1163,7 +1157,7 @@ def test_get_full_config_after_restoring_snapshot(bin_cloner_path):
11631157
test_microvm = vm_instance.vm
11641158
root_disk = vm_instance.disks[0]
11651159
ssh_key = vm_instance.ssh_key
1166-
cpu_vendor = utils.get_cpu_vendor()
1160+
cpu_vendor = utils_cpuid.get_cpu_vendor()
11671161

11681162
setup_cfg = {}
11691163

@@ -1175,10 +1169,10 @@ def test_get_full_config_after_restoring_snapshot(bin_cloner_path):
11751169
"track_dirty_pages": False,
11761170
}
11771171

1178-
if cpu_vendor == utils.CpuVendor.ARM:
1172+
if cpu_vendor == utils_cpuid.CpuVendor.ARM:
11791173
setup_cfg["machine-config"]["smt"] = False
11801174

1181-
if cpu_vendor == utils.CpuVendor.INTEL:
1175+
if cpu_vendor == utils_cpuid.CpuVendor.INTEL:
11821176
setup_cfg["machine-config"]["cpu_template"] = "C3"
11831177

11841178
test_microvm.machine_cfg.patch(**setup_cfg["machine-config"])

tests/integration_tests/functional/test_snapshot_version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ def test_snapshot_current_version(bin_cloner_path):
136136

137137
version = get_firecracker_version_from_toml()
138138
# normalize to a snapshot version
139-
(major, minor, _) = version.split(".", maxsplit=3)
140-
target_version = f"{major}.{minor}.0"
139+
target_version = f"{version.major}.{version.minor}.0"
141140
# Create a snapshot builder from a microvm.
142141
snapshot_builder = SnapshotBuilder(vm)
143142
disks = [vm_instance.disks[0].local_path()]

tools/bump-version.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -eu -o pipefail
7+
shopt -s lastpipe
8+
9+
FC_TOOLS_DIR=$(dirname $(realpath $0))
10+
source "$FC_TOOLS_DIR/functions"
11+
FC_ROOT_DIR=$FC_TOOLS_DIR/..
12+
13+
14+
if [ $# -ne 1 ]; then
15+
cat <<EOF
16+
$0 <version>
17+
18+
Example: $0 1.4.0-dev
19+
20+
Bump Firecracker release version:
21+
1. Updates Cargo.toml / Cargo.lock
22+
2. Runs 'cargo update'
23+
EOF
24+
exit 1
25+
fi
26+
version=$1
27+
28+
29+
function check_snapshot_version {
30+
local version=$1
31+
local snap_version=$(echo $version |cut -f-2 -d. |tr . _)
32+
if ! grep -s FC_V${snap_version}_SNAP_VERSION src/vmm/src/version_map.rs; then
33+
die "I couldn't find FC_V${snap_version}_SNAP_VERSION in src/vmm/src/version_map.rs"
34+
fi
35+
}
36+
37+
check_snapshot_version "$version"
38+
39+
40+
# Get current version from the swagger spec.
41+
prev_ver=$(get_swagger_version)
42+
43+
say "Updating from $prev_ver to $version ..."
44+
# Update version in files.
45+
files_to_change=(
46+
"$FC_ROOT_DIR/src/api_server/swagger/firecracker.yaml"
47+
"$FC_ROOT_DIR/src/firecracker/Cargo.toml"
48+
"$FC_ROOT_DIR/src/jailer/Cargo.toml"
49+
"$FC_ROOT_DIR/src/rebase-snap/Cargo.toml"
50+
"$FC_ROOT_DIR/src/seccompiler/Cargo.toml"
51+
"$FC_ROOT_DIR/src/cpu-template-helper/Cargo.toml"
52+
)
53+
say "Updating source files:"
54+
for file in "${files_to_change[@]}"; do
55+
say "- $file"
56+
if [[ "$file" =~ .+\.toml$ ]]; then
57+
# For TOML
58+
sed -i "s/^version = \"$prev_ver\"/version = \"$version\"/" "$file"
59+
elif [[ "$file" =~ .+\.yaml$ ]]; then
60+
# For YAML
61+
sed -i "s/version: $prev_ver/version: $version/" "$file"
62+
else
63+
echo "ERROR: Unrecognized file '$file'"
64+
exit 1
65+
fi
66+
done
67+
68+
# Run `cargo check` to update firecracker and jailer versions in all
69+
# `Cargo.lock`.
70+
# NOTE: This will break if it finds paths with spaces in them
71+
find . -path ./build -prune -o -name Cargo.lock -print |while read -r cargo_lock; do
72+
say "Updating $cargo_lock ..."
73+
(cd "$(dirname "$cargo_lock")"; cargo check; cargo update)
74+
done

tools/release-notes.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,28 @@ FC_TOOLS_DIR=$(dirname $(realpath $0))
99
FC_ROOT_DIR=$FC_TOOLS_DIR/..
1010

1111

12-
if [ $# -ne 2 ]; then
12+
if [ $# -ne 1 ]; then
1313
cat <<EOF
1414
Compose the text for a new release using the information in the changelog,
1515
between the two specified releases.
1616
17-
$0 <previous_version> <version>
17+
$0 <version>
1818
19-
Example: $0 1.1.1 1.1.2
19+
Example: $0 1.1.2
2020
EOF
2121
exit 1;
2222
fi
2323

24-
prev_ver="$1"
25-
curr_ver="$2"
24+
curr_ver="$1"
2625
changelog="$FC_ROOT_DIR/CHANGELOG.md"
2726

28-
if [[ ! $prev_ver < $curr_ver ]]; then
29-
echo "$prev_ver >= $curr_ver. Did you switch the argument order?"
30-
exit 1
31-
fi
32-
3327
# Patterns for the sections in the changelog corresponding to the versions.
34-
pat_curr="^##\s\[$curr_ver\]"
35-
pat_prev="^##\s\[$prev_ver\]"
28+
pat_curr="/^##\s\[$curr_ver\]/"
29+
pat_prev="/^##\s\[.+]/ && NR>3"
3630
# Extract the section enclosed between the 2 headers and strip off the first
3731
# 2 and last 2 lines (one is blank and one contains the header `## [A.B.C]`).
3832
# Then, replace `-` with `*` and remove section headers.
39-
sed "/$pat_curr/,/$pat_prev/!d" "$changelog" \
33+
awk "$pat_curr,$pat_prev" "$changelog" \
4034
| sed '1,2d;$d' \
4135
| sed "s/^-/*/g" \
4236
| sed "s/^###\s//g"

tools/release-prepare.sh

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
set -eu -o pipefail
77
shopt -s lastpipe
88

9-
function check_snapshot_version {
10-
local version=$1
11-
local snap_version=$(echo $version |cut -f-2 -d. |tr . _)
12-
if ! grep -s FC_V${snap_version}_SNAP_VERSION src/vmm/src/version_map.rs; then
13-
die "I couldn't find FC_V${snap_version}_SNAP_VERSION in src/vmm/src/version_map.rs"
14-
fi
15-
}
16-
179
FC_TOOLS_DIR=$(dirname $(realpath $0))
1810
source "$FC_TOOLS_DIR/functions"
1911
FC_ROOT_DIR=$FC_TOOLS_DIR/..
@@ -26,18 +18,16 @@ $0 <version>
2618
2719
Prepare a new Firecracker release:
2820
1. Update the version number
29-
2. Update Crate dependencies
30-
3. Generate CREDITS.md and CHANGELOG.md
31-
4. Commit the result
32-
5. Create a link to PR the changes
21+
2. Generate CREDITS.md and CHANGELOG.md
22+
3. Commit the result
23+
4. Create a link to PR the changes
3324
EOF
3425
exit 1
3526
fi
3627
version=$1
3728
validate_version "$version"
3829

3930
check_local_branch_is_release_branch
40-
check_snapshot_version "$version"
4131

4232
# Create GitHub PR link
4333
ORIGIN_URL=$(git config --get remote.origin.url)
@@ -55,49 +45,19 @@ if [ "$PATCH" -gt 0 ]; then
5545
fi
5646
PR_URL="https://github.com/firecracker-microvm/$REPO/compare/$TARGET_BRANCH...$GH_USER:$REPO:$LOCAL_BRANCH?expand=1"
5747

58-
# Get current version from the swagger spec.
59-
prev_ver=$(get_swagger_version)
60-
61-
say "Updating from $prev_ver to $version ..."
62-
# Update version in files.
63-
files_to_change=(
64-
"$FC_ROOT_DIR/src/api_server/swagger/firecracker.yaml"
65-
"$FC_ROOT_DIR/src/cpu-template-helper/Cargo.toml"
66-
"$FC_ROOT_DIR/src/firecracker/Cargo.toml"
67-
"$FC_ROOT_DIR/src/jailer/Cargo.toml"
68-
"$FC_ROOT_DIR/src/rebase-snap/Cargo.toml"
69-
"$FC_ROOT_DIR/src/seccompiler/Cargo.toml"
70-
)
71-
say "Updating source files:"
72-
for file in "${files_to_change[@]}"; do
73-
say "- $file"
74-
# Dirty hack to make this work on both macOS/BSD and Linux.
75-
# FIXME This is very hacky and can unintentionally bump other versions, so
76-
# only do the replacement *once*.
77-
sed -i "s/$prev_ver/$version/" "$file"
78-
done
79-
80-
CHANGED=()
81-
# Run `cargo check` to update firecracker and jailer versions in all
82-
# `Cargo.lock`.
83-
# NOTE: This will break if it finds paths with spaces in them
84-
find . -path ./build -prune -o -name Cargo.lock -print |while read -r cargo_lock; do
85-
say "Updating $cargo_lock ..."
86-
(cd "$(dirname "$cargo_lock")"; cargo check)
87-
CHANGED+=("$cargo_lock")
88-
done
48+
# Update version
49+
$FC_TOOLS_DIR/bump-version.sh "$version"
8950

9051
# Update credits.
9152
say "Updating credits..."
9253
$FC_TOOLS_DIR/update-credits.sh
93-
CHANGED+=(CREDITS.md)
9454

9555
# Update changelog.
9656
say "Updating changelog..."
9757
sed -i "s/\[Unreleased\]/\[$version\]/g" "$FC_ROOT_DIR/CHANGELOG.md"
98-
CHANGED+=(CHANGELOG.md)
9958

100-
git add "${files_to_change[@]}" "${CHANGED[@]}"
59+
# Add all changed files
60+
git add -u
10161
git commit -s -m "chore: release v$version"
10262

10363

@@ -123,7 +83,7 @@ $(pp-li 1. Check the changes made to the repo:)
12383
12484
$(pp-li 2. Preview the release notes)
12585
126-
$(pp-code ./tools/release-notes.sh "$prev_ver" "$version")
86+
$(pp-code ./tools/release-notes.sh "$version")
12787
12888
$(pp-li 3. If you want to undo the changes, run)
12989
@@ -135,5 +95,5 @@ $(pp-li 4. Review and merge this change)
13595
$PR_URL
13696
13797
$(pp-li 5. Once it is reviewed and merged, run the tag script)
138-
$(pp-code ./tools/release-tag.sh $prev_ver $version)
98+
$(pp-code ./tools/release-tag.sh $version)
13999
EOF

0 commit comments

Comments
 (0)