-
Notifications
You must be signed in to change notification settings - Fork 25
59 lines (51 loc) · 2.25 KB
/
configrun.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
name: Config Run
on:
push:
branches:
- master
pull_request:
branches:
- master
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: Store build output
uses: actions/upload-artifact@v1
with:
name: ansibleconfigs
path: ./tmp/configs