Sync with Cloud Hypervisor #44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync with Cloud Hypervisor | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 6 * * *" # daily at 6am UTC | |
| workflow_dispatch: # allow manual trigger | |
| jobs: | |
| sync: | |
| name: Check and sync with latest Cloud Hypervisor release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch latest Cloud Hypervisor release tag | |
| id: ch_latest | |
| run: | | |
| LATEST=$(curl -sSL "https://api.github.com/repos/cloud-hypervisor/cloud-hypervisor/releases/latest" \ | |
| | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/') | |
| if [ -z "$LATEST" ]; then | |
| echo "ERROR: Could not fetch latest Cloud Hypervisor release tag" | |
| exit 1 | |
| fi | |
| echo "tag=$LATEST" >> "$GITHUB_OUTPUT" | |
| echo "Latest Cloud Hypervisor release: $LATEST" | |
| - name: Read current tracked version | |
| id: current | |
| run: | | |
| if [ -f ".cloud-hypervisor-version" ]; then | |
| CURRENT=$(cat .cloud-hypervisor-version) | |
| else | |
| CURRENT="none" | |
| fi | |
| echo "tag=$CURRENT" >> "$GITHUB_OUTPUT" | |
| echo "Current tracked version: $CURRENT" | |
| - name: Check if update is needed | |
| id: needs_update | |
| run: | | |
| CH_TAG="${{ steps.ch_latest.outputs.tag }}" | |
| CURRENT_TAG="${{ steps.current.outputs.tag }}" | |
| # Derive what the SDK tag would be for the current CH release (vX.Y -> vX.Y.0) | |
| SDK_TAG="v$(echo "$CH_TAG" | sed 's/^v//' | sed 's/$/.0/')" | |
| # Check if the SDK tag already exists in the repo | |
| if git ls-remote --tags origin "refs/tags/${SDK_TAG}" | grep -q .; then | |
| TAG_EXISTS=true | |
| else | |
| TAG_EXISTS=false | |
| fi | |
| if [ "$CH_TAG" = "$CURRENT_TAG" ] && [ "$TAG_EXISTS" = "true" ]; then | |
| echo "needed=false" >> "$GITHUB_OUTPUT" | |
| echo "Already up to date with ${CH_TAG} and tag ${SDK_TAG} exists, nothing to do." | |
| else | |
| echo "needed=true" >> "$GITHUB_OUTPUT" | |
| if [ "$CH_TAG" != "$CURRENT_TAG" ]; then | |
| echo "Update needed: CH version changed ${CURRENT_TAG} -> ${CH_TAG}" | |
| else | |
| echo "Update needed: SDK tag ${SDK_TAG} does not exist yet" | |
| fi | |
| fi | |
| - name: Install Java | |
| if: steps.needs_update.outputs.needed == 'true' | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| - name: Install Rust toolchain | |
| if: steps.needs_update.outputs.needed == 'true' | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt | |
| - name: Cache Rust dependencies | |
| if: steps.needs_update.outputs.needed == 'true' | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Run regenerate.sh | |
| if: steps.needs_update.outputs.needed == 'true' | |
| run: | | |
| chmod +x regenerate.sh | |
| ./regenerate.sh | |
| - name: Derive SDK version from Cloud Hypervisor tag | |
| if: steps.needs_update.outputs.needed == 'true' | |
| id: sdk_version | |
| run: | | |
| # Convert vX.Y -> X.Y.0 (e.g. v51.0 -> 51.0.0) | |
| CH_TAG="${{ steps.ch_latest.outputs.tag }}" | |
| SEMVER=$(echo "$CH_TAG" | sed 's/^v//' | sed 's/$/\.0/') | |
| echo "version=$SEMVER" >> "$GITHUB_OUTPUT" | |
| echo "Derived SDK version: $SEMVER" | |
| - name: Bump version in Cargo.toml | |
| if: steps.needs_update.outputs.needed == 'true' | |
| run: | | |
| sed -i 's/^version = ".*"/version = "${{ steps.sdk_version.outputs.version }}"/' Cargo.toml | |
| - name: Update README | |
| if: steps.needs_update.outputs.needed == 'true' | |
| run: | | |
| CH_TAG="${{ steps.ch_latest.outputs.tag }}" | |
| SDK_TAG="v${{ steps.sdk_version.outputs.version }}" | |
| REPO="${{ github.repository }}" | |
| # Update the shields.io badge | |
| sed -i "s|cloud--hypervisor-v[^-]*-blue|cloud--hypervisor-${SDK_TAG}-blue|g" README.md | |
| sed -i "s|/releases/tag/v[0-9.]*)|/releases/tag/${CH_TAG})|g" README.md | |
| # Replace everything between the install markers | |
| NEW_INSTALL="**Pin to the latest release (Cloud Hypervisor ${CH_TAG}):**\n\`\`\`toml\n[dependencies]\ncloud-hypervisor-sdk = { git = \"https://github.com/${REPO}\", tag = \"${SDK_TAG}\" }\n\`\`\`\n\n**Always use latest main:**\n\`\`\`toml\n[dependencies]\ncloud-hypervisor-sdk = { git = \"https://github.com/${REPO}\", branch = \"main\" }\n\`\`\`" | |
| perl -i -0pe "s|(?<=<!-- BEGIN INSTALL -->\n).*(?=\n<!-- END INSTALL -->)|${NEW_INSTALL}|s" README.md | |
| - name: Commit and push changes | |
| if: steps.needs_update.outputs.needed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore: sync with Cloud Hypervisor ${{ steps.ch_latest.outputs.tag }}" | |
| git push origin main | |
| - name: Create and push tag | |
| if: steps.needs_update.outputs.needed == 'true' | |
| run: | | |
| TAG="v${{ steps.sdk_version.outputs.version }}" | |
| git tag -a "$TAG" -m "Release $TAG (Cloud Hypervisor ${{ steps.ch_latest.outputs.tag }})" | |
| git push origin "$TAG" | |
| - name: Create GitHub Release | |
| if: steps.needs_update.outputs.needed == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.sdk_version.outputs.version }} | |
| name: v${{ steps.sdk_version.outputs.version }} | |
| generate_release_notes: true | |
| body: | | |
| ## cloud-hypervisor-sdk v${{ steps.sdk_version.outputs.version }} | |
| Automatically synced with **Cloud Hypervisor ${{ steps.ch_latest.outputs.tag }}**. | |
| ### Usage | |
| **Pin to this release:** | |
| ```toml | |
| cloud-hypervisor-sdk = { git = "https://github.com/${{ github.repository }}", tag = "v${{ steps.sdk_version.outputs.version }}" } | |
| ``` | |
| **Always use latest main:** | |
| ```toml | |
| cloud-hypervisor-sdk = { git = "https://github.com/${{ github.repository }}", branch = "main" } | |
| ``` |