Install Rust with explicit version

This commit is contained in:
Fabrice Reix 2023-03-12 12:56:43 +01:00
parent f3bfe66863
commit c2010b0168
No known key found for this signature in database
GPG Key ID: BF5213154B2E7155
9 changed files with 68 additions and 23 deletions

View File

@ -43,6 +43,9 @@ jobs:
- name: Install prerequisites
run: bin/check/install_prerequisites.sh
- name: Check Rust version
run: bin/check/rust_version.py 7
- name: Rustfmt
run: bin/check/rustfmt.sh

View File

@ -25,7 +25,7 @@ jobs:
run: bin/install_prerequisites_ubuntu.sh
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Install Grcov
run: bin/install_grcov.sh

View File

@ -29,7 +29,7 @@ jobs:
- name: Install
run: |
bin/install_prerequisites_ubuntu.sh
bin/install_rust_latest.sh
bin/install_rust.sh
- name: Build
run: |
bin/release/release.sh
@ -202,7 +202,7 @@ jobs:
- name: Install
run: |
bin/install_prerequisites_ubuntu.sh
bin/install_rust_latest.sh
bin/install_rust.sh
- name: Environment
run: bin/environment.sh
- name: Build
@ -239,7 +239,7 @@ jobs:
with:
ref: ${{ inputs.branch }}
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Build
run: |
brew install pkg-config

View File

@ -27,7 +27,7 @@ jobs:
- name: Install Prerequisites
run: bin/install_prerequisites_ubuntu.sh
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Build
run: |
bin/release/release.sh
@ -57,7 +57,7 @@ jobs:
- name: Install Prerequisites
run: bin/install_prerequisites_ubuntu.sh
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Test Prerequisites
run: bin/test/test_prerequisites.sh
- name: Tests units
@ -96,7 +96,7 @@ jobs:
- name: Install Prerequisites
run: bin/install_prerequisites_ubuntu.sh
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Test Prerequisites
run: bin/test/test_prerequisites.sh
- name: Tests units
@ -137,7 +137,7 @@ jobs:
bin/environment.sh
echo "::endgroup::"
echo "::group::Install Rust"
bin/install_rust_latest.sh
bin/install_rust.sh
echo "::endgroup::"
echo "::group::Tests"
bin/test/test.sh
@ -171,7 +171,7 @@ jobs:
bin/environment.sh
echo "::endgroup::"
echo "::group::Install Rust"
bin/install_rust_latest.sh
bin/install_rust.sh
echo "::endgroup::"
echo "::group::Tests"
bin/test/test.sh
@ -211,7 +211,7 @@ jobs:
bin/environment.sh
echo "::endgroup::"
echo "::group::Install Rust"
bin/install_rust_latest.sh
bin/install_rust.sh
echo "::endgroup::"
echo "::group::Tests"
bin/test/test.sh
@ -241,7 +241,7 @@ jobs:
- name: Environment
run: bin/environment.sh
- name: Install Rust
run: bin/install_rust_latest.sh
run: bin/install_rust.sh
- name: Test Prerequisites
run: bin/test/test_prerequisites.sh
- name: Tests units

View File

@ -1,7 +1,7 @@
#!/bin/bash
set -Eeuo pipefail
bin/install_rust_latest.sh
bin/install_rust.sh
pip3 install -r bin/requirements-frozen.txt
sudo apt update && sudo apt install -y libxml2-utils

42
bin/check/rust_version.py Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import datetime
import json
import os
import requests
import sys
def get_latest_release():
r = requests.get("https://api.github.com/repos/rust-lang/rust/releases")
releases = json.loads(r.text)
latest_release = releases[0]
version = latest_release["tag_name"]
date_str = latest_release["published_at"]
date = datetime.datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ")
return version, date
def get_current_version():
return os.popen("cargo --version").read().split(" ")[1]
def main():
if len(sys.argv) < 2:
print("Usage: rust_version.py NUM_DAYS_BEFORE_ERROR")
sys.exit(1)
num_days_before_error = int(sys.argv[1])
latest_version, date = get_latest_release()
current_version = get_current_version()
if latest_version != current_version:
sys.stderr.write(
"Rust version must be updated from %s to the latest version %s\n"
% (current_version, latest_version)
)
days_before_now = datetime.datetime.now() - date
if days_before_now > datetime.timedelta(days=num_days_before_error):
sys.exit(1)
if __name__ == "__main__":
main()

10
bin/install_rust.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
set -Eeuo pipefail
rust_version=$(grep '^rust-version' packages/hurl/Cargo.toml | cut -f2 -d'"')
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs >/tmp/rustup.sh
sh /tmp/rustup.sh -y --default-toolchain "$rust_version"
~/.cargo/bin/rustc --version
~/.cargo/bin/cargo --version

View File

@ -1,11 +0,0 @@
#!/bin/bash
set -Eeuo pipefail
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
sh rustup.sh -y
# shellcheck source=/dev/null
PATH="$HOME/.cargo/bin:$PATH"
export PATH
rustc --version
cargo --version

View File

@ -8,6 +8,7 @@ description = "Hurl, run and test HTTP requests"
documentation = "https://hurl.dev"
homepage = "https://hurl.dev"
repository = "https://github.com/Orange-OpenSource/hurl"
rust-version = "1.68"
[lib]
name = "hurl"