Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 131 additions & 56 deletions .github/workflows/extension-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ jobs:
import json
import os
import pathlib
import re
import subprocess
import tomllib

SEMVER_RE = re.compile(
r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-(alpha|beta|rc)\.([1-9][0-9]*))?$"
)
STAGE_RANK = {"alpha": 0, "beta": 1, "rc": 2, None: 3}

def run(args, **kwargs):
return subprocess.run(args, text=True, check=True, **kwargs)

Expand All @@ -55,13 +61,16 @@ jobs:
def package_meta(path):
data = tomllib.loads(pathlib.Path(path).read_text())
package = data["package"]
return package["name"], str(package["version"])
return package["name"], package["version"]

def semver(value):
parts = value.split("-", 1)[0].split(".")
if len(parts) != 3 or not all(part.isdigit() for part in parts):
raise ValueError(f"official extension versions must use x.y.z: {value}")
return tuple(int(part) for part in parts)
if not isinstance(value, str):
raise ValueError(f"official extension versions must be strings: {value!r}")
match = SEMVER_RE.fullmatch(value)
if not match:
raise ValueError(f"official extension versions must use strict SemVer: {value}")
major, minor, patch, stage, num = match.groups()
return (int(major), int(minor), int(patch), STAGE_RANK[stage], int(num or 0))

base = os.environ["BASE_SHA"]
changed = output(["git", "diff", "--name-only", base, "HEAD"]).splitlines()
Expand All @@ -80,17 +89,23 @@ jobs:
if not cargo_toml.exists():
continue
package, version = package_meta(cargo_toml)
try:
current_semver = semver(version)
except ValueError as err:
print(f"::error::{package} {err}")
failed = True
continue
try:
base_text = output(["git", "show", f"{base}:{directory}/Cargo.toml"])
base_data = tomllib.loads(base_text)
base_version = str(base_data["package"]["version"])
base_version = base_data["package"]["version"]
except subprocess.CalledProcessError:
base_version = None

version_changed = base_version != version
print(f"{package} {version} version_changed={str(version_changed).lower()}")
if version_changed:
if base_version is not None and semver(version) <= semver(base_version):
if base_version is not None and current_semver <= semver(base_version):
print(f"::error::{package} version must increase: {base_version} -> {version}")
failed = True
tag = f"{package}-v{version}"
Expand Down Expand Up @@ -147,14 +162,21 @@ jobs:
run: |
python3 <<'PY'
import pathlib
import re
import subprocess
import tomllib

SEMVER_RE = re.compile(
r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-(alpha|beta|rc)\.([1-9][0-9]*))?$"
)

rows = []
for cargo_toml in sorted(pathlib.Path("extensions").glob("recall-*/Cargo.toml")):
data = tomllib.loads(cargo_toml.read_text())
package = data["package"]["name"]
version = str(data["package"]["version"])
version = data["package"]["version"]
if not isinstance(version, str) or not SEMVER_RE.fullmatch(version):
raise SystemExit(f"invalid SemVer version for {package}: {version!r}")
tag = f"{package}-v{version}"
exists = subprocess.run(
["git", "rev-parse", "-q", "--verify", f"refs/tags/{tag}"],
Expand Down Expand Up @@ -190,8 +212,70 @@ jobs:
gh workflow run extension-release.yml --ref main -f tag="$tag"
done < extension-tags.txt

verify:
if: startsWith(github.ref, 'refs/tags/recall-') || (github.event_name == 'workflow_dispatch' && inputs.tag != '')
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
package: ${{ steps.meta.outputs.package }}
version: ${{ steps.meta.outputs.version }}
is_prerelease: ${{ steps.meta.outputs.is_prerelease }}
sha: ${{ steps.meta.outputs.sha }}
steps:
- uses: actions/checkout@v6
with:
ref: refs/tags/${{ inputs.tag || github.ref_name }}
- name: Validate extension release tag
id: meta
shell: bash
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
run: |
set -euo pipefail
if [[ ! "$RELEASE_TAG" =~ ^recall-[a-z0-9]+(-[a-z0-9]+)*-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((alpha|beta|rc)\.[1-9][0-9]*))?$ ]]; then
echo "::error::invalid SemVer extension release tag: $RELEASE_TAG"
exit 1
fi
python3 <<'PY'
import os
import pathlib
import re
import subprocess
import tomllib

tag = os.environ["RELEASE_TAG"]
match = re.fullmatch(
r"^(recall-[a-z0-9]+(?:-[a-z0-9]+)*)-v((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-(?:alpha|beta|rc)\.[1-9][0-9]*)?)$",
tag,
)
if not match:
raise SystemExit(f"invalid SemVer extension release tag: {tag}")
package, version = match.groups()
cargo_toml = pathlib.Path("extensions") / package / "Cargo.toml"
if not cargo_toml.is_file():
raise SystemExit(f"missing extension manifest: {cargo_toml}")
data = tomllib.loads(cargo_toml.read_text())
pkg = data.get("package", {})
if pkg.get("name") != package:
raise SystemExit(f"package name mismatch: expected {package}, got {pkg.get('name')!r}")
actual = pkg.get("version")
if not isinstance(actual, str) or actual != version:
raise SystemExit(f"{package} version mismatch: tag={version} Cargo.toml={actual!r}")
head_sha = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip()
tag_sha = subprocess.check_output(["git", "rev-parse", f"refs/tags/{tag}^{{commit}}"], text=True).strip()
if head_sha != tag_sha:
raise SystemExit(f"checked out commit {head_sha} does not match tag {tag} ({tag_sha})")
is_prerelease = "true" if "-" in version else "false"
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as handle:
handle.write(f"package={package}\n")
handle.write(f"version={version}\n")
handle.write(f"is_prerelease={is_prerelease}\n")
handle.write(f"sha={head_sha}\n")
PY

build:
if: startsWith(github.ref, 'refs/tags/recall-') || (github.event_name == 'workflow_dispatch' && inputs.tag != '')
needs: verify
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
Expand All @@ -209,42 +293,29 @@ jobs:
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.tag || github.ref }}
ref: refs/tags/${{ inputs.tag || github.ref_name }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: extension-${{ matrix.target }}
- name: Parse tag
- name: Verify release commit
shell: bash
env:
PACKAGE: ${{ needs.verify.outputs.package }}
VERSION: ${{ needs.verify.outputs.version }}
VALIDATED_SHA: ${{ needs.verify.outputs.sha }}
run: |
tag="${{ inputs.tag }}"
if [ -z "$tag" ]; then
tag="${GITHUB_REF_NAME}"
set -euo pipefail
if [[ "$(git rev-parse HEAD)" != "$VALIDATED_SHA" ]]; then
echo "::error::extension release tag moved after validation"
exit 1
fi
version="${tag##*-v}"
package="${tag:0:${#tag}-${#version}-2}"
{
echo "PACKAGE=$package"
echo "VERSION=$version"
echo "PACKAGE=$PACKAGE"
echo "VERSION=$VERSION"
} >> "$GITHUB_ENV"
- name: Validate tag
shell: bash
run: |
test -f "extensions/$PACKAGE/Cargo.toml"
python3 <<'PY'
import os
import pathlib
import tomllib

package = os.environ["PACKAGE"]
version = os.environ["VERSION"]
data = tomllib.loads(pathlib.Path(f"extensions/{package}/Cargo.toml").read_text())
actual = str(data["package"]["version"])
if actual != version:
raise SystemExit(f"{package} version mismatch: tag={version} Cargo.toml={actual}")
PY
- name: Build
run: cargo build -p "$PACKAGE" --release --target ${{ matrix.target }}
shell: bash
Expand All @@ -270,7 +341,7 @@ jobs:

release:
if: startsWith(github.ref, 'refs/tags/recall-') || (github.event_name == 'workflow_dispatch' && inputs.tag != '')
needs: build
needs: [verify, build]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -281,34 +352,38 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
PACKAGE: ${{ needs.verify.outputs.package }}
VERSION: ${{ needs.verify.outputs.version }}
IS_PRERELEASE: ${{ needs.verify.outputs.is_prerelease }}
run: |
tag="${{ inputs.tag }}"
if [ -z "$tag" ]; then
tag="${GITHUB_REF_NAME}"
fi
version="${tag##*-v}"
package="${tag:0:${#tag}-${#version}-2}"
set -euo pipefail
assets=( ./*.tar.gz ./*.zip )
sha256sum "${assets[@]}" | sort > checksums.txt
cat > release-notes.md <<EOF
Official Recall extension release for \`$package\` v$version.
Official Recall extension release for \`$PACKAGE\` v$VERSION.

Assets are published for supported target triples. Checksums are available in \`checksums.txt\`.
EOF
if gh release view "$tag" >/dev/null 2>&1; then
gh release edit "$tag" --notes-file release-notes.md
gh release upload "$tag" --clobber "${assets[@]}" checksums.txt
release_flags=(--latest=false)
if [[ "$IS_PRERELEASE" == "true" ]]; then
release_flags+=(--prerelease)
fi
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release edit "$RELEASE_TAG" "${release_flags[@]}" --notes-file release-notes.md
gh release upload "$RELEASE_TAG" --clobber "${assets[@]}" checksums.txt
else
gh release create "$tag" \
--title "$tag" \
--latest=false \
gh release create "$RELEASE_TAG" \
--verify-tag \
--title "$RELEASE_TAG" \
"${release_flags[@]}" \
--notes-file release-notes.md \
"${assets[@]}" checksums.txt
fi

catalog:
if: startsWith(github.ref, 'refs/tags/recall-') || (github.event_name == 'workflow_dispatch' && inputs.tag != '')
needs: release
if: (startsWith(github.ref, 'refs/tags/recall-') || (github.event_name == 'workflow_dispatch' && inputs.tag != '')) && needs.verify.outputs.is_prerelease != 'true'
needs: [verify, release]
runs-on: ubuntu-latest
timeout-minutes: 20
concurrency:
Expand All @@ -331,6 +406,8 @@ jobs:
env:
REPOSITORY: ${{ github.repository }}
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
PACKAGE: ${{ needs.verify.outputs.package }}
VERSION: ${{ needs.verify.outputs.version }}
run: |
python3 <<'PY'
import hashlib
Expand All @@ -341,8 +418,8 @@ jobs:
import tomllib

tag = os.environ["RELEASE_TAG"]
version = tag.rsplit("-v", 1)[1]
package = tag[: -(len(version) + 2)]
package = os.environ["PACKAGE"]
version = os.environ["VERSION"]
manifest = json.loads(subprocess.check_output([
"cargo",
"run",
Expand Down Expand Up @@ -399,7 +476,8 @@ jobs:
- name: Commit catalog
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
PACKAGE: ${{ needs.verify.outputs.package }}
VERSION: ${{ needs.verify.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
Expand All @@ -408,10 +486,7 @@ jobs:
echo "Catalog already up to date."
exit 0
fi
tag="${RELEASE_TAG}"
version="${tag##*-v}"
package="${tag:0:${#tag}-${#version}-2}"
git commit -m "chore(extensions): publish $package v$version"
git commit -m "chore(extensions): publish $PACKAGE v$VERSION"
git push origin HEAD:main
expected_sha="$(git rev-parse HEAD)"
for _ in $(seq 1 20); do
Expand Down
Loading