Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Cargo.toml as source of truth #11

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
use Cargo.toml as source of truth
  • Loading branch information
magick93 committed Nov 26, 2024
commit 33f3a57cffab9e5378109b5a7899b71d9de6f2b8
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