Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small release workflow fixes #3926

Merged
merged 11 commits into from
Oct 24, 2023
18 changes: 12 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ jobs:
run: |
python3 -m pip install -r ./scripts/ci/requirements-crates.txt

# for `taplo fmt` done in `crates.py version --bump`
- name: Install taplo-cli
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -127,6 +126,9 @@ jobs:
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "final=$final" >> "$GITHUB_OUTPUT"

- name: "Taplo fmt"
run: taplo fmt

- name: Commit new version
id: commit
if: steps.versioning.outputs.previous != steps.versioning.outputs.current
Expand Down Expand Up @@ -253,7 +255,6 @@ jobs:
run: |
python3 -m pip install -r scripts/ci/requirements-crates.txt

# for `taplo fmt` done in `crates.py version --bump`
- name: Install taplo-cli
uses: taiki-e/install-action@v2
with:
Expand All @@ -262,17 +263,22 @@ jobs:
- name: Update version
id: update-version
run: |
if [ ${{ inputs.release-type }} = "final" ]; then
# After a final release, we bump the minor version and append `+dev`.
latest=$(python3 scripts/ci/crates.py get-version --from=cio)
latest_finalized=$(python3 scripts/ci/crates.py get-version --from=cio --finalize)
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
if [ $latest_published = $latest_finalized ]; then
# Latest published is a non-prerelease (e.g. 0.9.1), bump minor and add alpha+dev
python3 scripts/ci/crates.py version --bump minor
python3 scripts/ci/crates.py version --bump prerelease --dev --pre-id=alpha
echo "version=$(python3 scripts/ci/crates.py get-version)" >> "$GITHUB_OUTPUT"
else
# After an alpha release, we bump the prerelease version and append `+dev`.
python3 scripts/ci/crates.py version --bump minor
# Latest published is a pre-release (e.g. 0.10.0-alpha.5), bump prerelease
python3 scripts/ci/crates.py version --bump prerelease --dev --pre-id=alpha
echo "version=$(python3 scripts/ci/crates.py get-version)" >> "$GITHUB_OUTPUT"
fi
jprochazk marked this conversation as resolved.
Show resolved Hide resolved

- name: "Taplo fmt"
run: taplo fmt

- name: Commit new version
run: |
git config --global user.name "rerun-bot"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/reusable_build_and_publish_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ jobs:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
with:
version: ">= 363.0.0"

- name: Set up Rust
uses: ./.github/actions/setup-rust
with:
Expand Down
48 changes: 42 additions & 6 deletions scripts/ci/crates.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,45 @@ def publish(dry_run: bool, token: str) -> None:
publish_unpublished_crates_in_parallel(crates, version, token)


def get_version(finalize: bool, from_git: bool, pre_id: bool) -> None:
if from_git:
def get_latest_published_version(crate_name: str) -> str | None:
resp = requests.get(
f"https://crates.io/api/v1/crates/{crate_name}",
headers={"user-agent": "rerun-publishing-script (rerun.io)"},
)
body = resp.json()

if not resp.ok:
raise Exception(f"failed to get crate {crate_name}: {body['errors'][0]['detail']}")

if "versions" not in body:
return None

# response orders versions by semver
return body["versions"][0]["num"]


class Target(Enum):
Git = "git"
CratesIo = "cio"
jprochazk marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self) -> str:
return self.value


def get_version(finalize: bool, target: Target | None, pre_id: bool) -> None:
if target is Target.Git:
branch_name = git.Repo().active_branch.name.lstrip("release-")
try:
current_version = VersionInfo.parse(branch_name) # ensures that it is a valid version
except ValueError:
print(f"the current branch `{branch_name}` does not specify a valid version.")
print("this script expects the format `release-x.y.z-meta.N`")
exit(1)
elif target is Target.CratesIo:
latest_published_version = get_latest_published_version("rerun")
if not latest_published_version:
raise Exception("Failed to get latest published version for `rerun` crate")
current_version = VersionInfo.parse(latest_published_version)
else:
root: dict[str, Any] = tomlkit.parse(Path("Cargo.toml").read_text())
current_version = VersionInfo.parse(root["workspace"]["package"]["version"])
Expand All @@ -491,8 +521,11 @@ def main() -> None:

version_parser = cmds_parser.add_parser("version", help="Bump the crate versions")
target_version_parser = version_parser.add_mutually_exclusive_group()
target_version_parser.add_argument("--bump", type=Bump, choices=list(Bump), help="Bump version according to semver")
target_version_parser.add_argument("--exact", type=str, help="Update version to an exact value")
target_version_update_group = target_version_parser.add_mutually_exclusive_group()
target_version_update_group.add_argument(
"--bump", type=Bump, choices=list(Bump), help="Bump version according to semver"
)
target_version_update_group.add_argument("--exact", type=str, help="Update version to an exact value")
dev_parser = version_parser.add_mutually_exclusive_group()
dev_parser.add_argument("--dev", default=None, action="store_true", help="Set build metadata to `+dev`")
dev_parser.add_argument(
Expand All @@ -516,12 +549,15 @@ def main() -> None:
get_version_parser.add_argument(
"--finalize", action="store_true", help="Return version finalized if it is a pre-release"
)
get_version_parser.add_argument("--from-git", action="store_true", help="Get version from branch name")
get_version_parser.add_argument("--pre-id", action="store_true", help="Retrieve only the prerelease identifier")
get_version_parser.add_argument(
"--from", type=Target, choices=list(Target), help="Get version from git or crates.io", dest="target"
)

args = parser.parse_args()

if args.cmd == "get-version":
get_version(args.finalize, args.from_git, args.pre_id)
get_version(args.finalize, args.target, args.pre_id)
if args.cmd == "version":
if args.dev and args.pre_id != "alpha":
parser.error("`--pre-id` must be set to `alpha` when `--dev` is set")
Expand Down
Loading