Skip to content

Commit

Permalink
feat: OBS-392 - server release CI - generate servers matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Fiedorowicz <[email protected]>
  • Loading branch information
mfiedorowicz committed Feb 14, 2024
1 parent c5f73ca commit 2b87e22
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/generate_changed_servers_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e

changed_files=$1
if [ -z "$changed_files" ]; then
echo "Please provide a list of changed files as the first argument."
exit 1
fi

distributor_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/distributor/" "diode-server/distributor/" "diode-server/server/")
ingester_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/ingester" "diode-server/ingester/" "diode-server/server/")
reconciler_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/reconciler/" "diode-server/reconciler/" "diode-server/server/")

repo_root_dir=$(git rev-parse --show-toplevel)

declare -A changed_servers

IFS=';'

check_deps() {
local -n deps=$1
local file_path=$2
file_dir="$( dirname "$file_path" )/"

for dep in "${deps[@]}"; do
if [[ "$dep" == "$file_path" ]]; then
return 0
fi
if [[ "$file_dir" =~ ^$dep ]]; then
return 0
fi
done
return 1
}

read -ra changed_files_arr <<< "$changed_files"

for file in "${changed_files_arr[@]}"; do
if [[ ! -f "$repo_root_dir/$file" ]]; then
echo "File $repo_root_dir/$file does not exist, skipping"
continue
fi

if check_deps distributor_deps "$file" && [[ ! -v changed_servers["distributor"] ]]; then
changed_servers["distributor"]=1
fi

if check_deps ingester_deps "$file" && [[ ! -v changed_servers["ingester"] ]]; then
changed_servers["ingester"]=1
fi

if check_deps reconciler_deps "$file" && [[ ! -v changed_servers["reconciler"] ]]; then
changed_servers["reconciler"]=1
fi
done

changed_servers_num=${#changed_servers[@]}

matrix_json="{\"include\":["

item_num=0
for server in "${!changed_servers[@]}"; do
matrix_json+="{"
matrix_json+="\"server\":\"${server}\""
matrix_json+="}"
if [[ $item_num -lt $changed_servers_num-1 ]]; then
matrix_json+=","
fi
item_num=$((item_num+1))
done

matrix_json+="]}"

echo "matrix_json=$matrix_json"
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
15 changes: 11 additions & 4 deletions .github/workflows/server-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ env:
APP_DIR: diode-server

jobs:
changed-dirs:
name: Changed dirs
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
short_sha: ${{ steps.set-sha.outputs.short_sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -27,7 +30,11 @@ jobs:
- name: Get changed dirs
id: get-changed-dirs
run: |
echo "changed-dirs=$(git diff --name-only origin/${{ github.base_ref }} ${{ steps.short-sha.outputs.short_sha }} | xargs dirname | sort -u | tr '\n' ';')" >> $GITHUB_OUTPUT
- name: Echo changed dirs
echo "changed-dirs=$(git diff --name-only origin/${{ github.base_ref }} ${{ steps.short-sha.outputs.short_sha }} | sort -u | tr '\n' ';')" >> $GITHUB_OUTPUT
- name: Generate servers matrix
id: generate-matrix
run: ./generate_changed_servers_matrix.sh "${{ steps.get-changed-dirs.outputs.changed-dirs }}"
- name: Echo test
run: |
echo "changed-dirs: ${{ steps.get-changed-dirs.outputs.changed-dirs }}"
echo "matrix: ${{ steps.generate-matrix.outputs.matrix }}"

0 comments on commit 2b87e22

Please sign in to comment.