diff --git a/.github/workflows/release-dev-builder-images.yaml b/.github/workflows/release-dev-builder-images.yaml index aa3da561dbed..8752f0fd96ad 100644 --- a/.github/workflows/release-dev-builder-images.yaml +++ b/.github/workflows/release-dev-builder-images.yaml @@ -1,6 +1,11 @@ name: Release dev-builder images on: + push: + branches: + - main + paths: + - rust-toolchain.toml workflow_dispatch: # Allows you to run this workflow manually. inputs: version: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c9ee999385d..645bde936cf0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,6 +99,16 @@ permissions: contents: write # Allows the action to create a release. jobs: + check-builder-rust-version: + name: Check rust version in builder + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Check Rust toolchain version + shell: bash + run: | + ./scripts/check-builder-rust-version.sh + allocate-runners: name: Allocate runners if: ${{ github.repository == 'GreptimeTeam/greptimedb' }} diff --git a/scripts/check-builder-rust-version.sh b/scripts/check-builder-rust-version.sh new file mode 100755 index 000000000000..53c245ef79fb --- /dev/null +++ b/scripts/check-builder-rust-version.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +RUST_TOOLCHAIN_VERSION_FILE="rust-toolchain.toml" +DEV_BUILDER_UBUNTU="greptime/dev-builder-ubuntu:latest" + +function check_rust_toolchain_version() { + CURRENT_VERSION=$(cat "$RUST_TOOLCHAIN_VERSION_FILE" | grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}') + if [ -z "$CURRENT_VERSION" ]; then + echo "Error: No rust toolchain version found in $RUST_TOOLCHAIN_VERSION_FILE" + exit 1 + fi + + RUST_TOOLCHAIN_VERSION_IN_BUILDER=$(docker run $DEV_BUILDER_UBUNTU rustc --version | grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}') + if [ -z "$RUST_TOOLCHAIN_VERSION_IN_BUILDER" ]; then + echo "Error: No rustc version found in $DEV_BUILDER_UBUNTU" + exit 1 + fi + + # Compare the version and the difference should be less than 1 day. + current_rust_toolchain_seconds=$(date -d "$CURRENT_VERSION" +%s) + rust_toolchain_in_dev_builder_ubuntu_seconds=$(date -d "$RUST_TOOLCHAIN_VERSION_IN_BUILDER" +%s) + date_diff=$(( (current_rust_toolchain_seconds - rust_toolchain_in_dev_builder_ubuntu_seconds) / 86400 )) + + if [ $date_diff -gt 1 ]; then + echo "Error: The rust toolchain $RUST_TOOLCHAIN_VERSION_IN_BUILDER in builder $DEV_BUILDER_UBUNTU maybe outdated, please update it to $CURRENT_VERSION" + exit 1 + fi +} + +check_rust_toolchain_version