forked from stfc/cloud-deployed-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DaveW-STFC/check_pr_copies
New workflow to detect if charts match
- Loading branch information
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
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
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)' | ||
}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,4 +126,4 @@ spec: | |
selfHeal: true | ||
allowEmpty: true | ||
syncOptions: | ||
- CreateNamespace=true | ||
- CreateNamespace=true |
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
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 |