Skip to content

Commit

Permalink
ci: add check-builder-rust-version job in release and change release-…
Browse files Browse the repository at this point in the history
…dev-builder-images trigger condition
  • Loading branch information
zyy17 committed Aug 26, 2024
1 parent 3973d6b commit 1cc7d10
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release-dev-builder-images.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
32 changes: 32 additions & 0 deletions scripts/check-builder-rust-version.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cc7d10

Please sign in to comment.