diff --git a/.github/scripts/toml_reader.sh b/.github/scripts/toml_reader.sh new file mode 100755 index 00000000..ce2ec831 --- /dev/null +++ b/.github/scripts/toml_reader.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# TOML Reader - A script to read values from simple TOML files +# Usage: ./toml_reader.sh
+ +get_section() { + # Function to get the section from a TOML file + # Parameters: + # $1 - TOML file path + # $2 - section name + local file="$1" + local section="$2" + + sed -n "/^\[$section\]/,/^\[/p" "$file" | sed '$d' +} + +get_toml_value() { + # Function to get a value from a TOML file + # Parameters: + # $1 - TOML file path + # $2 - section + # $3 - key + local file="$1" + local section="$2" + local key="$3" + + get_section "$file" "$section" | grep "^$key " | cut -d "=" -f2- | tr -d ' "' +} + +# Show usage if script is called directly +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + if [ "$#" -ne 3 ]; then + echo "Error: Incorrect number of arguments" + echo "Usage: $0
" + echo "Example: $0 ./config.toml server_b domain" + exit 1 + fi + + # Check if file exists + if [ ! -f "$1" ]; then + echo "Error: File '$1' does not exist" + exit 1 + fi + + # Get the value + result=$(get_toml_value "$1" "$2" "$3") + + # Check if value was found + if [ -z "$result" ]; then + echo "Error: No value found for section '[$2]' and key '$3'" + exit 1 + fi + + echo "$result" +fi diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8502cd2c..a21d4786 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,13 +14,19 @@ concurrency: env: # Enable self-hosted runners for the sigp repo only. SELF_HOSTED_RUNNERS: ${{ github.repository == 'sigp/anchor' }} + RUST_VERSION: 'abc' jobs: + # Extract the rust-version from the Cargo.toml file. # Extract the VERSION which is either `latest` or `vX.Y.Z`, and the VERSION_SUFFIX # which is either empty or `-unstable`. extract-version: runs-on: ubuntu-22.04 steps: + - name: Get rust-version + id: get-rust-version + run: RUST_VERSION=$(./.github/scripts/toml_reader.sh ./anchor/Cargo.toml package rust-version) + - name: Extract version (if stable) if: github.event.ref == 'refs/heads/stable' run: | @@ -96,3 +102,5 @@ jobs: push: true tags: | hughestech/${{ matrix.binary }}:${{ env.VERSION }}${{ env.VERSION_SUFFIX }} + build-args: | + RUST_VERSION=${{ env.RUST_VERSION }} diff --git a/anchor/Dockerfile b/anchor/Dockerfile index 2e34f160..3d318971 100644 --- a/anchor/Dockerfile +++ b/anchor/Dockerfile @@ -1,4 +1,5 @@ -FROM rust:1.80.0-bullseye AS builder +ARG RUST_VERSION=1.80.0 +FROM rust:${RUST_VERSION}-bullseye AS builder RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev COPY . anchor ARG FEATURES