Skip to content

Instantly share code, notes, and snippets.

@gbraad
Last active March 27, 2025 11:44
Show Gist options
  • Save gbraad/19bc89449d105069040697484ba8b3d7 to your computer and use it in GitHub Desktop.
Save gbraad/19bc89449d105069040697484ba8b3d7 to your computer and use it in GitHub Desktop.
Test shared configuration
name: 'Shared Configuration'
description: 'Fetch configuration parameters from a shared .ini file and export as environment variables'
author: 'gbraad'
inputs:
  config_repo:
    description: 'URL of the repository containing the configuration file'
    required: true
  config_file:
    description: 'Path to the configuration file in the repository'
    required: true
runs:
  using: 'composite'
  steps:
    - name: Export configuration from configuration repository
      run: |
        git clone ${{ inputs.config_repo }} config-repo
        cd config-repo
        git config --global alias.configini 'config -f ${{ inputs.config_file }}'
        while IFS= read -r line; do
          if [[ $line =~ ^\[.*\]$ ]]; then
            section=$(echo $line | sed 's/\[\(.*\)\]/\1/')
          elif [[ $line =~ ^[^#]*=.*$ ]]; then
            key=$(echo $line | cut -d '=' -f 1 | tr -d ' ')
            value=$(echo $line | cut -d '=' -f 2 | tr -d ' ')
            echo "$(echo ${section}_${key} | tr '[:lower:]' '[:upper:]')=$value" >> $GITHUB_ENV
          fi
        done < ${{ inputs.config_file }}
      shell: bash
name: Build and Test

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Fetch configuration
        uses: gbraad-actions/shared-config-action@v1
        with:
          config_repo: https://github.com/gbraad/shared-config.git
          config_file: fedora.ini

      - name: Use base settings
        run: |
          echo "Using base version $BASE_VERSION"
          echo "Using base image $BASE_IMAGE"
        shell: bash

      - name: Use other settings
        run: |
          echo "Using other setting 1 $OTHER_SETTING1"
          echo "Using other setting 2 $OTHER_SETTING2"
        shell: bash
[base]
VERSION=42
IMAGE=fedora

[other]
SETTING1=value1
SETTING2=value2
@gbraad
Copy link
Author

gbraad commented Mar 27, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment