Feat/add rust toolchain (#1235)
* feature: update rust-toolchain * add(ci): action that updates `rust-toolchain` We purposefully keep our version a little behind the newest releases, to give people the time to update. Now this is unambigious and we can use all the features our current toolchain allows.
This commit is contained in:
parent
ccd9a55a9b
commit
effccbfaa3
3 changed files with 107 additions and 1 deletions
38
.github/workflows/update-rust-toolchain.yml
vendored
Normal file
38
.github/workflows/update-rust-toolchain.yml
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
name: update-flake-lock
|
||||||
|
on:
|
||||||
|
workflow_dispatch: # allows manual triggering
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 0' # runs weekly on Sunday at 00:00
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lockfile:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install Nix
|
||||||
|
uses: cachix/install-nix-action@v16
|
||||||
|
with:
|
||||||
|
extra_nix_config: |
|
||||||
|
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: install dependencies
|
||||||
|
run: nix profile install nixpkgs#jq nixpkgs#curl
|
||||||
|
- name: update rust-toolchain
|
||||||
|
run: assets/scripts/update-toolchain.sh
|
||||||
|
- name: Create Pull Request
|
||||||
|
id: cpr
|
||||||
|
uses: peter-evans/create-pull-request@v3
|
||||||
|
with:
|
||||||
|
commit-message: Update `rust-toolchain`
|
||||||
|
committer: GitHub <noreply@github.com>
|
||||||
|
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||||
|
signoff: false
|
||||||
|
branch: update/rust-toolchain
|
||||||
|
delete-branch: true
|
||||||
|
title: '[Update] rust-toolchain'
|
||||||
|
body: |
|
||||||
|
Update rust-toolchain file
|
||||||
|
labels: |
|
||||||
|
dependencies
|
||||||
|
automated
|
||||||
|
rust
|
||||||
68
assets/scripts/update-toolchain.sh
Executable file
68
assets/scripts/update-toolchain.sh
Executable file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
# dependencies: bash, curl, jq
|
||||||
|
#
|
||||||
|
# Updates a rust-toolchain file in relation to the official rust releases.
|
||||||
|
|
||||||
|
# How many minor versions delta there should be,
|
||||||
|
# will automatically advance patch versions.
|
||||||
|
MINOR_DELTA=2
|
||||||
|
RUST_TOOLCHAIN_VERSION=$(grep -oP 'channel = "\K[^"]+' "./rust-toolchain")
|
||||||
|
#RUST_TOOLCHAIN_FILE=../../rust-toolchain
|
||||||
|
RUST_TOOLCHAIN_FILE=./rust-toolchain
|
||||||
|
|
||||||
|
# update with new version number
|
||||||
|
update_channel(){
|
||||||
|
printf \
|
||||||
|
"
|
||||||
|
# This file is updated by \`update-toolchain.sh\`
|
||||||
|
# We aim to be around 1-2 rust releases behind in order
|
||||||
|
# to get people the time to update their toolchains properly.
|
||||||
|
# By enforcing this, we can also make full use of the features
|
||||||
|
# provided by the current channel.
|
||||||
|
|
||||||
|
"
|
||||||
|
sed -e "/channel/s/\".*\"/\"$1\"/" "${RUST_TOOLCHAIN_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_last_no_releases() {
|
||||||
|
curl --silent "https://api.github.com/repos/rust-lang/rust/releases" | \
|
||||||
|
jq '.[range(20)].tag_name' | sed -e 's/\"//g'
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_semver() {
|
||||||
|
local token="$1"
|
||||||
|
local major=0
|
||||||
|
local minor=0
|
||||||
|
local patch=0
|
||||||
|
|
||||||
|
if grep -E '^[0-9]+\.[0-9]+\.[0-9]+' <<<"$token" >/dev/null 2>&1 ; then
|
||||||
|
local n=${token//[!0-9]/ }
|
||||||
|
local a=(${n//\./ })
|
||||||
|
major=${a[0]}
|
||||||
|
minor=${a[1]}
|
||||||
|
patch=${a[2]}
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$major $minor $patch"
|
||||||
|
}
|
||||||
|
function get_string_arrary() {
|
||||||
|
IFS=' ' read -r -a array <<< "$1";
|
||||||
|
echo "${array["${2}"]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
RUST_TOOLCHAIN_VERSION="$(parse_semver $(echo $RUST_TOOLCHAIN_VERSION))"
|
||||||
|
TARGET_TOOLCHAIN_MINOR_VERSION=$(($(get_string_arrary "${RUST_TOOLCHAIN_VERSION}" 1) - MINOR_DELTA))
|
||||||
|
|
||||||
|
LATEST=0
|
||||||
|
for i in $(get_last_no_releases);do
|
||||||
|
SEMVER=($(parse_semver "$i"))
|
||||||
|
if [ "$LATEST" != "${SEMVER[1]}" ];then
|
||||||
|
MINOR_DELTA=$((MINOR_DELTA - 1))
|
||||||
|
fi
|
||||||
|
LATEST="${SEMVER[1]}"
|
||||||
|
if [ -1 == "${MINOR_DELTA}" ];then
|
||||||
|
echo "$(update_channel "$i")"> ${RUST_TOOLCHAIN_FILE}
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "stable"
|
channel = "1.55.0"
|
||||||
components = ["rustfmt", "clippy", "rust-analysis"]
|
components = ["rustfmt", "clippy", "rust-analysis"]
|
||||||
targets = ["wasm32-wasi"]
|
targets = ["wasm32-wasi"]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue