Skip to content

chore(deps): update node dependencies #8

chore(deps): update node dependencies

chore(deps): update node dependencies #8

name: renovate hooks
on:
pull_request:
branches:
- main
paths:
- 'package.json'
- 'package-lock.json'
jobs:
renovate-post-run:
name: Renovate Post Upgrade Hook
runs-on: ubuntu-latest
if: github.repository_owner == 'jkroepke' && github.actor == 'renovate[bot]'
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
# Using a GitHub App token, because GitHub Actions doesn't run on commits from github-actions bot
# Used App:
# https://github.com/organizations/prometheus-community/settings/apps/helm-charts-renovate-helper.
# Ref: https://github.com/prometheus-community/helm-charts/issues/5213.
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
id: app-token
with:
app-id: 1248576
private-key: ${{ secrets.APP_RENOVATE_HELPER_PRIVATE_KEY }}
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '22'
- run: |
npm install
npm run all
- name: Commit changes
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
#language=bash
run: |
# Define the target directory
TARGET_DIR="."
# Fetch deleted files in the target directory
DELETED_FILES=$(git diff --diff-filter=D --name-only HEAD -- "$TARGET_DIR")
# Fetch added/modified files in the target directory
MODIFIED_FILES=$(git diff --diff-filter=ACM --name-only HEAD -- "$TARGET_DIR")
# Collect deletions
DELETIONS_FILE=$(mktemp)
echo '[]' > "$DELETIONS_FILE"
git diff --diff-filter=D --name-only HEAD -- "$TARGET_DIR" | while read -r file; do
jq --arg path "$file" '. += [{"path": $path}]' "$DELETIONS_FILE" > "$DELETIONS_FILE.tmp"
mv "$DELETIONS_FILE.tmp" "$DELETIONS_FILE"
done
# Collect additions
ADDITIONS_FILE=$(mktemp)
echo '[]' > "$ADDITIONS_FILE"
git diff --diff-filter=ACM --name-only HEAD -- "$TARGET_DIR" | while read -r file; do
BASE64_CONTENT=$(base64 -w 0 <"$file")
jq --arg path "$file" --arg content "$BASE64_CONTENT" '. += [{"path": $path, "contents": $content}]' "$ADDITIONS_FILE" > "$ADDITIONS_FILE.tmp"
mv "$ADDITIONS_FILE.tmp" "$ADDITIONS_FILE"
done
# Create a temporary file for the final JSON payload
JSON_PAYLOAD_FILE=$(mktemp)
# Construct the final JSON using jq and store it in a file
jq -n \
--slurpfile deletions "$DELETIONS_FILE" \
--slurpfile additions "$ADDITIONS_FILE" \
--arg repo "$GITHUB_REPOSITORY" \
--arg branch "$GITHUB_HEAD_REF" \
--arg message "post upgrade changes from renovate" \
--arg expectedOid "$GITHUB_SHA" \
'{
query: "mutation ($input: CreateCommitOnBranchInput!) {
createCommitOnBranch(input: $input) {
commit {
url
}
}
}",
variables: {
input: {
branch: {
repositoryNameWithOwner: $repo,
branchName: $branch
},
message: { headline: $message },
fileChanges: {
deletions: $deletions[0],
additions: $additions[0]
},
expectedHeadOid: $expectedOid
}
}
}' > "$JSON_PAYLOAD_FILE"
# Call GitHub API
curl https://api.github.com/graphql -f \
-sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
--data "@$JSON_PAYLOAD_FILE"
# Clean up temporary files
rm "$FILE_CHANGES_JSON_FILE" "$JSON_PAYLOAD_FILE"