|
1 |
| -name: Renovate Bump Chart Version |
| 1 | +name: renovate hooks |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | pull_request:
|
|
8 | 8 | - 'charts/**/*'
|
9 | 9 |
|
10 | 10 | jobs:
|
11 |
| - renovate-bump-chart-version: |
| 11 | + renovate-post-run: |
12 | 12 | name: Renovate Bump Chart Version
|
13 | 13 | runs-on: ubuntu-latest
|
14 | 14 | if: github.actor == 'renovate[bot]'
|
@@ -89,49 +89,61 @@ jobs:
|
89 | 89 |
|
90 | 90 | # Fetch added/modified files in the target directory
|
91 | 91 | 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" |
95 | 98 |
|
96 | 99 | # Add deletions
|
97 | 100 | 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" |
99 | 103 | done
|
100 | 104 |
|
101 | 105 | # Add additions (new or modified files)
|
102 | 106 | 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" |
105 | 111 | done
|
106 | 112 |
|
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" |
133 | 142 |
|
134 | 143 | # Call GitHub API
|
135 | 144 | curl https://api.github.com/graphql -f \
|
136 | 145 | -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