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
Initial version at: https://github.com/gbraad-actions/shared-config and test run: https://github.com/gbraad/shared-config/actions/runs/14105730479/job/39511736607