diff --git a/.github/create-pr-comment-file.sh b/.github/create-pr-comment-file.sh new file mode 100644 index 00000000..ace73468 --- /dev/null +++ b/.github/create-pr-comment-file.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +mkdir -p out/pr +mkdir -p out/target +mkdir -p out-default-values/pr +mkdir -p out-default-values/target +mkdir -p comment-files +for env in pr target; do + cd ${env}/platform-apps/charts + for chart in $( ls ); do + echo ${chart} + helm dependency update ${chart} + for value in $( find ${chart} -type f -name "values-*" ); do + valuefile=$( basename ${value} ) + helm template ${chart} -f ${value} > ../../../out/${env}/${chart}_${valuefile}.out + done + # get default values of subchart + helm show values ${chart}/charts/* > ../../../out-default-values/${env}/${chart}_default-values.out || true + done + cd - +done +diff -U 7 -r out-default-values/target out-default-values/pr > out/default-values-diff.txt || true +diff -U 7 -r out/target out/pr > out/diff.txt || true +csplit -f comment-files/comment out/diff.txt --elide-empty-files /^diff\ \-U/ '{*}' + +comment_files_csplit=$( find comment-files -type f | sort ) + +# Define the maximum size in bytes +MAX_SIZE=131072 + +# Initialize output file counter and base name +OUTPUT_BASE_NAME="combined_file" +output_file_count=1 +OUTPUT_FILE="${OUTPUT_BASE_NAME}_${output_file_count}.txt" + +# Remove existing files with the same base name to start fresh +rm -f "${OUTPUT_BASE_NAME}_*.txt" + +# Current size of the output file +current_size=0 + +# Loop through all the files passed as arguments to the script +for file in ${comment_files_csplit}; do + if [ -f "$file" ]; then # Check if the argument is a valid file + # Get the size of the file to be added + file_size=$(stat -c %s "$file") + + # Check if adding this file will exceed the limit + if (( current_size + file_size > MAX_SIZE )); then + # Start a new output file + output_file_count=$((output_file_count + 1)) + OUTPUT_FILE="${OUTPUT_BASE_NAME}_${output_file_count}.txt" + current_size=0 # Reset current size for the new output file + + echo "Reached size limit. Creating new output file: $OUTPUT_FILE." + fi + + # Concatenate the file to the current output file + cat "$file" >> "$OUTPUT_FILE" + + # Update the current size + current_size=$((current_size + file_size)) + + echo "Added '$file' to '$OUTPUT_FILE'. Current size: $current_size bytes." + else + echo "'$file' is not a valid file. Skipping." + fi +done + +echo "Concatenation completed. Total output files: $output_file_count." + +combined_files=$( ls combined_file* ) +for combined_file in ${combined_files} ; do + sed 's/DESCRIPTION_HERE/Changes Rendered Chart/g' pr/.github/pr-diff-template.txt > out/comment-diff-${combined_file} + sed -e "/DIFF_HERE/{r ${combined_file}" -e "d}" out/comment-diff-${combined_file} > comment-files/comment-result-${combined_file} +done + +# default values comparison (we assume they will not be bigger than comment size limit) +sed 's/DESCRIPTION_HERE/Changes Default Values/g' pr/.github/pr-diff-template.txt > out/comment-diff-default-values.txt +sed -e "/DIFF_HERE/{r out/default-values-diff.txt" -e "d}" out/comment-diff-default-values.txt > comment-files/comment-default-values-result.txt + + +# output for matrix build +echo "matrix={\"comment-files\": $( jq -n '$ARGS.positional' --args $( ls comment-files/comment-result-* ) | tr "\n" " ")}" >> $GITHUB_OUTPUT + diff --git a/.github/Pr-diff-template.txt b/.github/pr-diff-template.txt similarity index 100% rename from .github/Pr-diff-template.txt rename to .github/pr-diff-template.txt diff --git a/.github/workflows/gitops-diff.yaml b/.github/workflows/gitops-diff.yaml index 2aa2699a..eb84e0cf 100644 --- a/.github/workflows/gitops-diff.yaml +++ b/.github/workflows/gitops-diff.yaml @@ -11,6 +11,8 @@ name: Diff GitOps jobs: diff: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.diffStep.outputs.matrix }} steps: - name: Checkout PR uses: actions/checkout@v4 @@ -23,45 +25,49 @@ jobs: ref: ${{ github.event.pull_request.base.ref }} - name: diff charts + id: diffStep shell: bash run: | - wget https://raw.githubusercontent.com/suxess-it/sx-cnp-oss/main/.github/Pr-diff-template.txt - mkdir -p out/pr - mkdir -p out/target - mkdir -p out-default-values/pr - mkdir -p out-default-values/target - for env in pr target; do - cd ${env}/platform-apps/charts - for chart in $( ls ); do - echo ${chart} - helm dependency update ${chart} - for value in $( find ${chart} -type f -name "values*" ); do - valuefile=$( basename ${value} ) - helm template ${chart} -f ${value} > ../../../out/${env}/${chart}_${valuefile}.out - done - # get default values of subchart - helm show values ${chart}/charts/* > ../../../out-default-values/${env}/${chart}_default-values.out || true - done - cd - - done - diff -U 7 -r out-default-values/target out-default-values/pr > out/default-values-diff.txt || true - diff -U 7 -r out/target out/pr > out/diff.txt || true - sed 's/DESCRIPTION_HERE/Changes Rendered Chart/g' Pr-diff-template.txt > out/comment-diff.txt - sed -e "/DIFF_HERE/{r out/diff.txt" -e "d}" out/comment-diff.txt > out/comment-result.txt - sed 's/DESCRIPTION_HERE/Changes Default Values/g' Pr-diff-template.txt > out/comment-diff-default-values.txt - sed -e "/DIFF_HERE/{r out/default-values-diff.txt" -e "d}" out/comment-diff-default-values.txt > out/comment-default-values-result.txt + bash pr/.github/create-pr-comment-file.sh - - name: PR comment rendered chart with file - uses: thollander/actions-comment-pull-request@v2 + - uses: actions/upload-artifact@v4 + with: + name: comment-files-artifact + path: comment-files/ + + create-template-render-diff-comment: + needs: diff + runs-on: ubuntu-latest + strategy: + matrix: ${{fromJSON(needs.diff.outputs.matrix)}} + max-parallel: 1 + steps: + + - uses: actions/download-artifact@v4 + with: + name: comment-files-artifact + path: comment-files/ + + - uses: thollander/actions-comment-pull-request@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - filePath: out/comment-result.txt + filePath: ${{matrix.comment-files}} + + + create-default-value-diff-comment: + needs: create-template-render-diff-comment + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: comment-files-artifact + path: comment-files/ - name: PR comment default values with file uses: thollander/actions-comment-pull-request@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - filePath: out/comment-default-values-result.txt + filePath: comment-files/comment-default-values-result.txt diff --git a/platform-apps/charts/argocd/Chart.lock b/platform-apps/charts/argocd/Chart.lock index 1b1d680a..74419a3c 100644 --- a/platform-apps/charts/argocd/Chart.lock +++ b/platform-apps/charts/argocd/Chart.lock @@ -1,6 +1,6 @@ dependencies: - name: argo-cd repository: https://argoproj.github.io/argo-helm - version: 6.7.18 -digest: sha256:b6f661f88a3ea5d69f67e91bd9b3e538dea7d85d79abd486ed04e65b35f20ab3 -generated: "2024-04-30T17:44:02.308037142Z" + version: 6.8.0 +digest: sha256:6a6ad8cb1e483618b6756d8d4813530e7c1d83c3b23c885fd068bbac73195021 +generated: "2024-05-08T08:26:21.980977019Z" diff --git a/platform-apps/charts/argocd/Chart.yaml b/platform-apps/charts/argocd/Chart.yaml index e7d3a608..453f8dda 100644 --- a/platform-apps/charts/argocd/Chart.yaml +++ b/platform-apps/charts/argocd/Chart.yaml @@ -25,5 +25,5 @@ appVersion: "1.0.0" dependencies: - name: argo-cd - version: 6.7.18 + version: 6.8.0 repository: https://argoproj.github.io/argo-helm