Skip to content

Commit 72fd953

Browse files
committed
wip
1 parent aef79a9 commit 72fd953

File tree

1 file changed

+4
-213
lines changed

1 file changed

+4
-213
lines changed

.github/workflows/diff.yaml

+4-213
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
pull_request:
3-
branches: [main]
3+
# branches: [main]
44

55
name: Crossplane Dynamic Diff
66

@@ -9,216 +9,7 @@ jobs:
99
name: prepare
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Setup QEMU
13-
uses: docker/setup-qemu-action@v2
12+
- name: diff
13+
uses: pedjak/crossplane-diff-action@action
1414
with:
15-
platforms: all
16-
- name: Check out current commit
17-
uses: actions/checkout@v4
18-
- name: Install Go
19-
uses: actions/setup-go@v4
20-
- name: Install yq
21-
run: |
22-
sudo add-apt-repository ppa:rmescandon/yq
23-
sudo apt-get update
24-
sudo apt-get install yq
25-
- name: Install Crossplane CLI
26-
run: go install github.com/crossplane/crossplane/cmd/crank@latest
27-
28-
# Discover YAML files and their annotations
29-
- name: Discover YAML files
30-
run: |
31-
EXAMPLES_PATH="examples"
32-
YAML_FILES=($(find $EXAMPLES_PATH -type f -name '*.yaml'))
33-
INPUT_FILES=""
34-
for file in "${YAML_FILES[@]}"; do
35-
COMPOSITION=$(yq eval '.metadata.annotations."crossplane.io/render-composition-path"' $file)
36-
FUNCTION=$(yq eval '.metadata.annotations."crossplane.io/render-function-path"' $file)
37-
38-
# Skip files where both annotations are null
39-
if [[ "$COMPOSITION" == "null" && "$FUNCTION" == "null" ]]; then
40-
continue
41-
fi
42-
43-
INPUT_FILES+="$file,$COMPOSITION,$FUNCTION "
44-
done
45-
echo "INPUT_FILES=${INPUT_FILES}" >> $GITHUB_ENV
46-
47-
# Run a dynamic job for each input file
48-
- name: Run Dynamic Jobs
49-
run: |
50-
IFS=' ' read -ra INPUT_FILES <<< "${{ env.INPUT_FILES }}"
51-
for files in "${INPUT_FILES[@]}"; do
52-
IFS=',' read -ra FILE_ARRAY <<< "$files"
53-
FILE="${FILE_ARRAY[0]}"
54-
COMPOSITION="${FILE_ARRAY[1]}"
55-
FUNCTION="${FILE_ARRAY[2]}"
56-
57-
# Skip files where both annotations are null
58-
if [[ "$COMPOSITION" == "null" && "$FUNCTION" == "null" ]]; then
59-
continue
60-
fi
61-
62-
crank beta render $FILE $COMPOSITION $FUNCTION >> diff-pr-${FILE//\//-}.yaml
63-
done
64-
65-
- name: Install Python
66-
uses: actions/setup-python@v4
67-
68-
# Sort YAML files
69-
- name: Sort YAML files
70-
run: |
71-
for file in diff-pr-*.yaml; do
72-
python3 -c "import yaml; data = list(yaml.load_all(open('$file'), Loader=yaml.FullLoader)); data.sort(key=lambda x: (x.get('kind', ''), str(x.get('metadata', {}).get('annotations', '')))); yaml.dump_all(data, open('$file', 'w'), default_flow_style=False)"
73-
done
74-
75-
# Store outputs as artifacts
76-
- name: Store outputs
77-
uses: actions/upload-artifact@v3
78-
with:
79-
name: diff-pr-${{ github.sha }}
80-
path: diff-*.yaml
81-
82-
main:
83-
name: diff
84-
needs: [pr]
85-
runs-on: ubuntu-latest
86-
steps:
87-
- name: Setup QEMU
88-
uses: docker/setup-qemu-action@v2
89-
with:
90-
platforms: all
91-
- name: Install Go
92-
uses: actions/setup-go@v4
93-
- name: Install yq
94-
run: |
95-
sudo add-apt-repository ppa:rmescandon/yq
96-
sudo apt-get update
97-
sudo apt-get install yq
98-
- name: Install Crossplane CLI
99-
run: go install github.com/crossplane/crossplane/cmd/crank@latest
100-
101-
- name: Check out main
102-
uses: actions/checkout@v4
103-
with:
104-
ref: main
105-
106-
# Download artifacts from the dynamic job
107-
- name: Download artifacts
108-
uses: actions/download-artifact@v2
109-
with:
110-
name: diff-pr-${{ github.sha }}
111-
112-
# Discover YAML files and their annotations
113-
- name: Discover YAML files
114-
run: |
115-
EXAMPLES_PATH="examples"
116-
YAML_FILES=($(find $EXAMPLES_PATH -type f -name '*.yaml'))
117-
INPUT_FILES=""
118-
for file in "${YAML_FILES[@]}"; do
119-
COMPOSITION=$(yq eval '.metadata.annotations."crossplane.io/render-composition-path"' $file)
120-
FUNCTION=$(yq eval '.metadata.annotations."crossplane.io/render-function-path"' $file)
121-
122-
# Skip files where both annotations are null
123-
if [[ "$COMPOSITION" == "null" && "$FUNCTION" == "null" ]]; then
124-
continue
125-
fi
126-
127-
INPUT_FILES+="$file,$COMPOSITION,$FUNCTION "
128-
done
129-
echo "INPUT_FILES=${INPUT_FILES}" >> $GITHUB_ENV
130-
131-
# Run a dynamic job for each input file
132-
- name: Run Dynamic Jobs
133-
run: |
134-
IFS=' ' read -ra INPUT_FILES <<< "${{ env.INPUT_FILES }}"
135-
for files in "${INPUT_FILES[@]}"; do
136-
IFS=',' read -ra FILE_ARRAY <<< "$files"
137-
FILE="${FILE_ARRAY[0]}"
138-
COMPOSITION="${FILE_ARRAY[1]}"
139-
FUNCTION="${FILE_ARRAY[2]}"
140-
141-
# Skip files where both annotations are null
142-
if [[ "$COMPOSITION" == "null" && "$FUNCTION" == "null" ]]; then
143-
continue
144-
fi
145-
146-
crank beta render $FILE $COMPOSITION $FUNCTION >> diff-main-${FILE//\//-}.yaml
147-
done
148-
149-
- name: Install Python
150-
uses: actions/setup-python@v4
151-
152-
# Sort YAML files
153-
- name: Sort YAML files
154-
run: |
155-
for file in diff-main-*.yaml; do
156-
python3 -c "import yaml; data = list(yaml.load_all(open('$file'), Loader=yaml.FullLoader)); data.sort(key=lambda x: (x.get('kind', ''), str(x.get('metadata', {}).get('annotations', '')))); yaml.dump_all(data, open('$file', 'w'), default_flow_style=False)"
157-
done
158-
# Store outputs as artifacts
159-
- name: Store outputs
160-
uses: actions/upload-artifact@v2
161-
with:
162-
name: diff-main-${{ github.sha }}
163-
path: diff-main-*.yaml
164-
165-
# Diff the outputs between PR and main
166-
- name: Diff
167-
id: diff_rev
168-
run: |
169-
IFS=',' read -ra INPUT_FILES <<< "$INPUT_FILES"
170-
for FILE in "${INPUT_FILES[@]}"; do
171-
IFS=' ' read -ra FILE_PATHS <<< "$FILE"
172-
for SUB_FILE in "${FILE_PATHS[@]}"; do
173-
MAIN_FILE="diff-main-${SUB_FILE//\//-}.yaml"
174-
PR_FILE="diff-pr-${SUB_FILE//\//-}.yaml"
175-
echo "Checking differences for file: $SUB_FILE"
176-
echo "Main file path: $MAIN_FILE"
177-
echo "PR file path: $PR_FILE"
178-
if [ -f "$MAIN_FILE" ] && [ -f "$PR_FILE" ]; then
179-
DELTA_NAME=$(echo "DELTA_${SUB_FILE//[\./]/_}" | tr '[:upper:]' '[:lower:]' | sed 's/\//_/g')
180-
DELTA_FILE="$DELTA_NAME.diff"
181-
echo "Setting DELTA_NAME: $DELTA_NAME"
182-
DELTA=$(diff -u "$MAIN_FILE" "$PR_FILE" || true)
183-
echo "$DELTA" > "$DELTA_FILE"
184-
echo "Differences found for $SUB_FILE. Diff saved in $DELTA_FILE"
185-
else
186-
echo "Either $MAIN_FILE or $PR_FILE does not exist!"
187-
fi
188-
done
189-
done
190-
191-
- name: Generate Comment
192-
id: generate_comment
193-
run: |
194-
ALL_DELTAS=""
195-
196-
# Iterate over all diff files
197-
for DELTA_FILE in $(find . -name '*.diff'); do
198-
echo "Processing diff file: $DELTA_FILE"
199-
200-
# Debugging statement
201-
cat "$DELTA_FILE"
202-
203-
# Ensure the file exists and is not empty
204-
if [ -s "$DELTA_FILE" ]; then
205-
# Use printf to format newlines properly
206-
ALL_DELTAS="${ALL_DELTAS}$(printf '\n```diff\n%s\n```' "$(cat "$DELTA_FILE")")"
207-
echo "ALL_DELTAS so far: $ALL_DELTAS"
208-
else
209-
echo "Diff file $DELTA_FILE is either empty or not found!"
210-
fi
211-
done
212-
213-
# Debugging statement
214-
echo "Final ALL_DELTAS: $ALL_DELTAS"
215-
216-
# Write the content to a file
217-
echo -e "$ALL_DELTAS" > diff_content.txt
218-
219-
- name: comment PR
220-
uses: machine-learning-apps/pr-comment@master
221-
env:
222-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
223-
with:
224-
path: diff_content.txt
15+
dir: examples

0 commit comments

Comments
 (0)