Skip to content

Commit

Permalink
use Cargo.toml as source of truth
Browse files Browse the repository at this point in the history
  • Loading branch information
magick93 committed Nov 26, 2024
1 parent eb2d461 commit 33f3a57
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .github/scripts/toml_reader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# TOML Reader - A script to read values from simple TOML files
# Usage: ./toml_reader.sh <file_path> <section> <key>

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 <file_path> <section> <key>"
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
8 changes: 8 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -96,3 +102,5 @@ jobs:
push: true
tags: |
hughestech/${{ matrix.binary }}:${{ env.VERSION }}${{ env.VERSION_SUFFIX }}
build-args: |
RUST_VERSION=${{ env.RUST_VERSION }}
3 changes: 2 additions & 1 deletion anchor/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 33f3a57

Please sign in to comment.