philmel: cleanup #1058
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Config Run | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Ansible Config Run | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install dependencies | |
run: sudo apt install python3 | |
- name: Install dependencies | |
run: pip3 install -r requirements.txt --upgrade pip | |
- name: Determine branch name | |
run: | | |
BRANCH="${GITHUB_BASE_REF#refs/heads/}" | |
echo "Building for $BRANCH" | |
echo "BRANCH=$BRANCH" >> "$GITHUB_ENV" | |
- name: Determine changed locations | |
run: | | |
CHANGED_HOSTS=$(git diff --diff-filter=d --name-only "origin/$BRANCH" | grep 'host_vars/' | sed 's/host_vars\/\(.*\)\/.*/\1/' | sort | uniq | sed -z 's/\n/,/g;s/,$//') | |
echo "Building for $CHANGED_HOSTS" | |
echo "CHANGED_HOSTS=$CHANGED_HOSTS" >> "$GITHUB_ENV" | |
CHANGED_LOCATIONS=$(git diff --diff-filter=d --name-only "origin/$BRANCH" | grep 'group_vars/location_' | sed 's/group_vars\/\(.*\)\/.*/\1/' | sort | uniq | sed -z 's/\n/,/g;s/,$//') | |
CHANGED_SINGE_FILE_LOCATIONS=$(git diff --diff-filter=d --name-only "origin/$BRANCH" | grep 'locations/' | sed 's/locations\/\(.*\)\.yml/location_\1/' | sed -z 's/-/_/g;s/\n/,/g;s/,$//') | |
CHANGED_LOCATIONS=${CHANGED_LOCATIONS:+$CHANGED_LOCATIONS,}$CHANGED_SINGE_FILE_LOCATIONS | |
CHANGED_OTHER=$(git diff --diff-filter=d --name-only "origin/$BRANCH" | grep -xP '(inventory|roles)/.+' | sed -z 's/\n/,/g;s/,$//') | |
if [ -z "${CHANGED_LOCATIONS}" ] && [ -n "${CHANGED_OTHER}" ]; then | |
CHANGED_LOCATIONS="sama-core,sama-nord-5ghz,l105-gw" | |
fi | |
echo "Building for $CHANGED_LOCATIONS" | |
echo "CHANGED_LOCATIONS=$CHANGED_LOCATIONS" >> "$GITHUB_ENV" | |
- name: Build changed locations | |
run: | | |
if [ -n "${CHANGED_HOSTS}" ] || [ -n "${CHANGED_LOCATIONS}" ] ; then | |
ansible-playbook play.yml --limit "${CHANGED_HOSTS:+$CHANGED_HOSTS,}$CHANGED_LOCATIONS" | |
fi | |
mkdir -p ./tmp/configs | |
- name: Create tar from configs folder | |
run: | | |
# create a tar containing the configs, as files with colons might be created which are rejected by upload-artifact | |
# upload-artifact rejects all files that might cause issues with file systems that do not support all characters | |
tar -cvf ./tmp/configs.tar ./tmp/configs/ | |
- name: Store build output | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ansibleconfigs | |
path: | | |
./tmp/configs.tar |