-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically run renovate on a schedule (#366)
* Run renovate on a schedule * don't even need to check out the repo * Use a GitHub App * Update README.md * add check to access ci script * Make JWT generation more legible
- Loading branch information
Showing
4 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: run renovate | ||
|
||
on: | ||
workflow_dispatch: | ||
# Monday mornings | ||
schedule: | ||
- cron: '15 1 * * 1' | ||
|
||
env: | ||
LOG_LEVEL: debug | ||
RENOVATE_REPOSITORIES: islandora-devops/isle-buildkit | ||
RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: '["bash ci/update-sha.sh \"{{{depName}}}\" \"{{{currentVersion}}}\" \"{{{newVersion}}}\" \"{{{newDigest}}}\""]' | ||
jobs: | ||
run: | ||
runs-on: ubuntu-24.04 | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
||
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: run renovate | ||
run: | | ||
# fetch GitHub App token for this repo | ||
echo "${{ secrets.GH_APP_PRIV_KEY }}" | base64 -d > private-key.pem | ||
export RENOVATE_TOKEN=$(./ci/fetch-app-token.sh ${{ secrets.GH_APP_ID }} ${{ secrets.GH_APP_INSTALLATION_ID }} private-key.pem) | ||
# run renovate with our token | ||
npx renovate --platform=github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eou pipefail | ||
|
||
if [[ $# -ne 3 ]]; then | ||
echo "Usage: $0 <APP_ID> <INSTALL_ID> <PRIVATE_KEY_FILE_PATH>" | ||
echo "e.g. ./ci/fetch-app-token.sh 123 456 /path/to/priv.pem" | ||
exit 1 | ||
fi | ||
|
||
APP_ID="$1" | ||
INSTALL_ID="$2" | ||
PRIVATE_KEY_FILE="$3" | ||
|
||
if [[ ! -f "$PRIVATE_KEY_FILE" ]]; then | ||
echo "Error: Private key file not found: $PRIVATE_KEY_FILE" | ||
exit 1 | ||
fi | ||
|
||
b64url_encode() { | ||
base64 -w 0 | tr -d '=' | tr '/+' '_-' | tr -d '\n' | ||
} | ||
|
||
JWT_HEADER=$(jq -n \ | ||
'{ | ||
"alg": "RS256", | ||
"typ": "JWT" | ||
}' | b64url_encode | ||
) | ||
|
||
NOW=$(date +%s) | ||
EXPIRATION=$((NOW + 300)) # 5m | ||
JWT_PAYLOAD=$(jq -n \ | ||
--argjson iat "$NOW" \ | ||
--argjson exp "$EXPIRATION" \ | ||
--arg iss "$APP_ID" \ | ||
'{ | ||
"iat": $iat, | ||
"exp": $exp, | ||
"iss": $iss | ||
}' | b64url_encode | ||
) | ||
|
||
JWT_SIGNATURE=$(echo -n "${JWT_HEADER}.${JWT_PAYLOAD}" \ | ||
| openssl dgst -sha256 -sign "$PRIVATE_KEY_FILE" \ | ||
| b64url_encode | ||
) | ||
|
||
JWT="${JWT_HEADER}.${JWT_PAYLOAD}.${JWT_SIGNATURE}" | ||
|
||
RESPONSE=$(curl -s -X POST \ | ||
"https://api.github.com/app/installations/${INSTALL_ID}/access_tokens" \ | ||
-H "Authorization: Bearer $JWT" \ | ||
-H "Accept: application/vnd.github+json") | ||
|
||
if echo "$RESPONSE" | jq -e '.token' > /dev/null; then | ||
# this token has a TTL of 60m | ||
# see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token | ||
echo "$RESPONSE" | jq -r '.token' | ||
else | ||
echo "Error:" >&2 | ||
echo "$RESPONSE" | jq >&2 | ||
exit 1 | ||
fi |