Skip to content

Commit 728a7d9

Browse files
committed
Add renovate options
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
1 parent 3850a4d commit 728a7d9

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: renovate hooks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'package.json'
9+
- 'package-lock.json'
10+
11+
jobs:
12+
renovate-post-run:
13+
name: Renovate Post Upgrade Hook
14+
runs-on: ubuntu-latest
15+
if: github.actor == 'renovate[bot]'
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
fetch-depth: 0
20+
21+
# Using a GitHub App token, because GitHub Actions doesn't run on commits from github-actions bot
22+
# Used App:
23+
# https://github.com/organizations/prometheus-community/settings/apps/helm-charts-renovate-helper.
24+
# Ref: https://github.com/prometheus-community/helm-charts/issues/5213.
25+
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
26+
id: app-token
27+
with:
28+
app-id: 1248576
29+
private-key: ${{ secrets.APP_RENOVATE_HELPER_PRIVATE_KEY }}
30+
31+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
32+
with:
33+
node-version: '22'
34+
35+
- run: |
36+
npm install
37+
npm run all
38+
39+
- name: Commit changes
40+
env:
41+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
42+
GITHUB_HEAD_REF: ${{ github.head_ref }}
43+
#language=bash
44+
run: |
45+
# Define the target directory
46+
TARGET_DIR="$CHART"
47+
48+
# Fetch deleted files in the target directory
49+
DELETED_FILES=$(git diff --diff-filter=D --name-only HEAD -- "$TARGET_DIR")
50+
51+
# Fetch added/modified files in the target directory
52+
MODIFIED_FILES=$(git diff --diff-filter=ACM --name-only HEAD -- "$TARGET_DIR")
53+
54+
# Create a temporary file for JSON output
55+
FILE_CHANGES_JSON_FILE=$(mktemp)
56+
57+
# Initialize JSON structure in the file
58+
echo '{ "deletions": [], "additions": [] }' > "$FILE_CHANGES_JSON_FILE"
59+
60+
# Add deletions
61+
for file in $DELETED_FILES; do
62+
jq --arg path "$file" '.deletions += [{"path": $path}]' "$FILE_CHANGES_JSON_FILE" > "$FILE_CHANGES_JSON_FILE.tmp"
63+
mv "$FILE_CHANGES_JSON_FILE.tmp" "$FILE_CHANGES_JSON_FILE"
64+
done
65+
66+
# Add additions (new or modified files)
67+
for file in $MODIFIED_FILES; do
68+
BASE64_CONTENT=$(base64 -w 0 <"$file") # Encode file content
69+
jq --arg path "$file" --arg content "$BASE64_CONTENT" \
70+
'.additions += [{"path": $path, "contents": $content}]' "$FILE_CHANGES_JSON_FILE" > "$FILE_CHANGES_JSON_FILE.tmp"
71+
mv "$FILE_CHANGES_JSON_FILE.tmp" "$FILE_CHANGES_JSON_FILE"
72+
done
73+
74+
# Create a temporary file for the final JSON payload
75+
JSON_PAYLOAD_FILE=$(mktemp)
76+
77+
# Construct the final JSON using jq and store it in a file
78+
jq -n --arg repo "$GITHUB_REPOSITORY" \
79+
--arg branch "$GITHUB_HEAD_REF" \
80+
--arg message "post upgrade changes from renovate" \
81+
--arg expectedOid "$GITHUB_SHA" \
82+
--slurpfile fileChanges "$FILE_CHANGES_JSON_FILE" \
83+
'{
84+
query: "mutation ($input: CreateCommitOnBranchInput!) {
85+
createCommitOnBranch(input: $input) {
86+
commit {
87+
url
88+
}
89+
}
90+
}",
91+
variables: {
92+
input: {
93+
branch: {
94+
repositoryNameWithOwner: $repo,
95+
branchName: $branch
96+
},
97+
message: { headline: $message },
98+
fileChanges: $fileChanges[0],
99+
expectedHeadOid: $expectedOid
100+
}
101+
}
102+
}' > "$JSON_PAYLOAD_FILE"
103+
104+
# Call GitHub API
105+
curl https://api.github.com/graphql -f \
106+
-sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
107+
--data "@$JSON_PAYLOAD_FILE"
108+
109+
# Clean up temporary files
110+
rm "$FILE_CHANGES_JSON_FILE" "$JSON_PAYLOAD_FILE"

renovate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"schedule": ["* 14-17 * * 5"],
77
"automerge": true,
88
"platformAutomerge": true,
9+
"suppressNotifications": ["prEditedNotification"],
910
"packageRules": [
1011
{
1112
"groupName": "golangci-lint",

0 commit comments

Comments
 (0)