Skip to content

Commit dbf42e8

Browse files
authored
[ci] renovate post upgrade hooks: use local files instead shell variables (#5496)
Signed-off-by: Jan-Otto Kröpke <[email protected]>
1 parent 8a725fb commit dbf42e8

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

Diff for: .github/workflows/renovate-bump-chart-version.yaml renamed to .github/workflows/renovate-custom-hooks.yaml

+47-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Renovate Bump Chart Version
1+
name: renovate hooks
22

33
on:
44
pull_request:
@@ -8,7 +8,7 @@ on:
88
- 'charts/**/*'
99

1010
jobs:
11-
renovate-bump-chart-version:
11+
renovate-post-run:
1212
name: Renovate Bump Chart Version
1313
runs-on: ubuntu-latest
1414
if: github.actor == 'renovate[bot]'
@@ -89,49 +89,61 @@ jobs:
8989
9090
# Fetch added/modified files in the target directory
9191
MODIFIED_FILES=$(git diff --diff-filter=ACM --name-only HEAD -- "$TARGET_DIR")
92-
93-
# Initialize JSON structure
94-
FILE_CHANGES_JSON='{ "deletions": [], "additions": [] }'
92+
93+
# Create a temporary file for JSON output
94+
FILE_CHANGES_JSON_FILE=$(mktemp)
95+
96+
# Initialize JSON structure in the file
97+
echo '{ "deletions": [], "additions": [] }' > "$FILE_CHANGES_JSON_FILE"
9598
9699
# Add deletions
97100
for file in $DELETED_FILES; do
98-
FILE_CHANGES_JSON=$(echo "$FILE_CHANGES_JSON" | jq --arg path "$file" '.deletions += [{"path": $path}]')
101+
jq --arg path "$file" '.deletions += [{"path": $path}]' "$FILE_CHANGES_JSON_FILE" > "$FILE_CHANGES_JSON_FILE.tmp"
102+
mv "$FILE_CHANGES_JSON_FILE.tmp" "$FILE_CHANGES_JSON_FILE"
99103
done
100104
101105
# Add additions (new or modified files)
102106
for file in $MODIFIED_FILES; do
103-
BASE64_CONTENT=$(base64 -w 0 <"$file")
104-
FILE_CHANGES_JSON=$(echo "$FILE_CHANGES_JSON" | jq --arg path "$file" --arg content "$BASE64_CONTENT" '.additions += [{"path": $path, "contents": $content}]')
107+
BASE64_CONTENT=$(base64 -w 0 <"$file") # Encode file content
108+
jq --arg path "$file" --arg content "$BASE64_CONTENT" \
109+
'.additions += [{"path": $path, "contents": $content}]' "$FILE_CHANGES_JSON_FILE" > "$FILE_CHANGES_JSON_FILE.tmp"
110+
mv "$FILE_CHANGES_JSON_FILE.tmp" "$FILE_CHANGES_JSON_FILE"
105111
done
106112
107-
# Construct final JSON using jq
108-
JSON_PAYLOAD=$(jq -n --arg repo "$GITHUB_REPOSITORY" \
109-
--arg branch "$GITHUB_HEAD_REF" \
110-
--arg message "post upgrade changes from renovate" \
111-
--arg expectedOid "$GITHUB_SHA" \
112-
--argjson fileChanges "$FILE_CHANGES_JSON" \
113-
'{
114-
query: "mutation ($input: CreateCommitOnBranchInput!) {
115-
createCommitOnBranch(input: $input) {
116-
commit {
117-
url
118-
}
119-
}
120-
}",
121-
variables: {
122-
input: {
123-
branch: {
124-
repositoryNameWithOwner: $repo,
125-
branchName: $branch
126-
},
127-
message: { headline: $message },
128-
fileChanges: $fileChanges,
129-
expectedHeadOid: $expectedOid
130-
}
131-
}
132-
}')
113+
# Create a temporary file for the final JSON payload
114+
JSON_PAYLOAD_FILE=$(mktemp)
115+
116+
# Construct the final JSON using jq and store it in a file
117+
jq -n --arg repo "$GITHUB_REPOSITORY" \
118+
--arg branch "$GITHUB_HEAD_REF" \
119+
--arg message "post upgrade changes from renovate" \
120+
--arg expectedOid "$GITHUB_SHA" \
121+
--slurpfile fileChanges "$FILE_CHANGES_JSON_FILE" \
122+
'{
123+
query: "mutation ($input: CreateCommitOnBranchInput!) {
124+
createCommitOnBranch(input: $input) {
125+
commit {
126+
url
127+
}
128+
}
129+
}",
130+
variables: {
131+
input: {
132+
branch: {
133+
repositoryNameWithOwner: $repo,
134+
branchName: $branch
135+
},
136+
message: { headline: $message },
137+
fileChanges: $fileChanges[0],
138+
expectedHeadOid: $expectedOid
139+
}
140+
}
141+
}' > "$JSON_PAYLOAD_FILE"
133142
134143
# Call GitHub API
135144
curl https://api.github.com/graphql -f \
136145
-sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
137-
--data "$JSON_PAYLOAD"
146+
--data "@$JSON_PAYLOAD_FILE"
147+
148+
# Clean up temporary files
149+
rm "$FILE_CHANGES_JSON_FILE" "$JSON_PAYLOAD_FILE"

0 commit comments

Comments
 (0)