Skip to content

Commit

Permalink
Merge pull request #2 from DaveW-STFC/check_pr_copies
Browse files Browse the repository at this point in the history
New workflow to detect if charts match
  • Loading branch information
DaveW-STFC authored Sep 27, 2024
2 parents cbc29fe + 23e935f commit eec0b37
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/pr_copied_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI Copied Files Check

on:
pull_request:
branches:
- main

jobs:
changed_files:
runs-on: ubuntu-latest
name: Test changed-files
outputs:
check_result: ${{ steps.step1.outputs.result }}
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
ref: check_pr_copies
- name: Get changed files in specific repo folders
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
charts/staging/**
charts/prod/**
# clusters/staging/**
# clusters/prod/**
# secrets/staging/**
# secrets/prod**

- name: Run step if any file(s) in the folder change
id: step1
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "One or more files in the folder has changed."
echo "Files that have changed: $ALL_CHANGED_FILES"
echo "result=true" >> "$GITHUB_OUTPUT"
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
res=$( sudo ./scripts/pr_check_copies.sh "$file" )
echo $res
if [ "$res" -eq 1 ]; then
echo "result=false" >> "$GITHUB_OUTPUT"
break;
fi
done
comment_pr:
needs: changed_files
if: ${{ contains(needs.changed_files.outputs.any_changed, 'true') }}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
if: contains(needs.changed_files.outputs.check_result, 'true')
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 All files are an exact match to previous environment(s)'
})
2 changes: 1 addition & 1 deletion clusters/staging/management/apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ spec:
selfHeal: true
allowEmpty: true
syncOptions:
- CreateNamespace=true
- CreateNamespace=true
39 changes: 39 additions & 0 deletions scripts/pr_check_copies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Script to check if the changed files to promote are a direct copy of earlier environment

devEnv="dev"
stagingEnv="staging"


# Function to compare the files, file1 is our original file passed to the script followed by two possible further files
compare_files() {
file1=$1
file2=$2
file3=$3

# Check the number of arguments passed to the function for comparison
if [ "$#" -eq 2 ]; then
if cmp -s "$file1" "$file2" ; then
echo $((0))
else
echo $((1))
fi
else
if cmp -s "$file1" "$file2" && cmp -s "$file1" "$file3"; then
echo $((0))
else
echo $((1))
fi
fi
}

# Check the file path to determine if it's from staging or prod folder
# If it's staging we pass it along with a url to the file in dev folder.
# If it's from prod we pass both the staging and dev file also for comparison
path=$1
if [[ $1 == *"staging"* ]] ; then
compare_files "$1" "${path/staging/"$devEnv"}"
else
compare_files "$1" "${path/prod/"$stagingEnv"}" "${path/prod/"$devEnv"}"
fi

0 comments on commit eec0b37

Please sign in to comment.