Update .gitea/workflows/renovate.yaml
This commit is contained in:
parent
806e96043b
commit
f4200013e4
1 changed files with 64 additions and 49 deletions
|
@ -7,19 +7,13 @@ on:
|
|||
push:
|
||||
|
||||
env:
|
||||
# Define Gitea endpoint once
|
||||
GITEA_ENDPOINT: https://git.kjan.de/api/v1
|
||||
# Define the number of parallel jobs you want
|
||||
RENOVATE_PARALLEL_JOBS: 4
|
||||
|
||||
jobs:
|
||||
# ----------------------------------------------------
|
||||
# Job 1: Discover repositories via Gitea API
|
||||
# ----------------------------------------------------
|
||||
discover:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
# Output the list of repositories as a JSON string
|
||||
repositories: ${{ steps.get_repos.outputs.repositories }}
|
||||
steps:
|
||||
- name: Install curl and jq
|
||||
|
@ -31,26 +25,37 @@ jobs:
|
|||
GITEA_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||
run: |
|
||||
set -e # Exit on error
|
||||
all_repos="[]"
|
||||
all_repos="[]" # Default to an empty JSON array
|
||||
page=1
|
||||
limit=50 # Repos per page
|
||||
limit=50
|
||||
|
||||
echo "Fetching repositories from ${{ env.GITEA_ENDPOINT }}"
|
||||
|
||||
while true; do
|
||||
# Fetch a page of repositories (adjust endpoint if needed, e.g., /orgs/{org}/repos)
|
||||
# This assumes the token has access via /user/repos
|
||||
response=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||
# Fetch a page of repositories
|
||||
response=$(curl -s -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" \
|
||||
"${{ env.GITEA_ENDPOINT }}/user/repos?limit=$limit&page=$page")
|
||||
|
||||
# Check if the response is a valid JSON array
|
||||
if ! echo "$response" | jq -e 'type == "array"' > /dev/null; then
|
||||
echo "Error: Invalid response from Gitea API (Page $page):"
|
||||
echo "$response"
|
||||
# Extract body and status code
|
||||
http_code=$(tail -n1 <<< "$response")
|
||||
body=$(sed '$ d' <<< "$response")
|
||||
|
||||
if [ "$http_code" -ne 200 ]; then
|
||||
echo "Error: Received HTTP status $http_code from Gitea API (Page $page):"
|
||||
echo "$body"
|
||||
# Decide if you want to exit or just log and continue with potentially partial list
|
||||
# For now, we exit to prevent processing bad data
|
||||
exit 1
|
||||
fi
|
||||
|
||||
count=$(echo "$response" | jq 'length')
|
||||
# Check if the response body is a valid JSON array
|
||||
if ! echo "$body" | jq -e 'type == "array"' > /dev/null; then
|
||||
echo "Error: Invalid JSON response body from Gitea API (Page $page):"
|
||||
echo "$body"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
count=$(echo "$body" | jq 'length')
|
||||
echo "Fetched $count repositories on page $page."
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
|
@ -58,7 +63,7 @@ jobs:
|
|||
fi
|
||||
|
||||
# Filter for non-archived repos and extract full_name, merge with previous results
|
||||
page_repos=$(echo "$response" | jq '[.[] | select(.archived == false) | .full_name]')
|
||||
page_repos=$(echo "$body" | jq '[.[] | select(.archived == false) | .full_name]')
|
||||
all_repos=$(jq -n --argjson current "$all_repos" --argjson new "$page_repos" '$current + $new')
|
||||
|
||||
if [ "$count" -lt "$limit" ]; then
|
||||
|
@ -71,35 +76,35 @@ jobs:
|
|||
repo_count=$(echo "$all_repos" | jq 'length')
|
||||
echo "Total non-archived repositories found: $repo_count"
|
||||
|
||||
# Output the list as a compact JSON string array
|
||||
echo "repositories=$(echo "$all_repos" | jq -c .)" >> $GITHUB_OUTPUT
|
||||
# Ensure output is always valid JSON, even if empty
|
||||
final_output=$(echo "$all_repos" | jq -c .)
|
||||
echo "Final JSON output: $final_output" # Debugging line
|
||||
echo "repositories=$final_output" >> $GITHUB_OUTPUT
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Job 2: Run Renovate in Parallel using Matrix
|
||||
# ----------------------------------------------------
|
||||
renovate:
|
||||
needs: discover # Run after discovery is complete
|
||||
needs: discover
|
||||
runs-on: ubuntu-latest
|
||||
# Pin to a specific Renovate version
|
||||
container: ghcr.io/renovatebot/renovate:37.290.1
|
||||
|
||||
strategy:
|
||||
fail-fast: false # Prevent other jobs from stopping if one fails
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Create a matrix based on the desired number of parallel jobs
|
||||
partition: ${{ fromJson(format('[{0}]', join(range(0, env.RENOVATE_PARALLEL_JOBS), ','))) }}
|
||||
|
||||
steps:
|
||||
# Checkout the repository containing base config.js (if needed for extends)
|
||||
- name: Checkout Base Config Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Cache Renovate's dependency cache directory between runs
|
||||
# Shared cache key across matrix jobs - Renovate should handle internal locking
|
||||
# --- Debugging Step ---
|
||||
- name: Show Discovered Repositories Output
|
||||
run: |
|
||||
echo "Received repositories output from discover job:"
|
||||
echo '${{ needs.discover.outputs.repositories }}'
|
||||
# --- End Debugging Step ---
|
||||
|
||||
- name: Cache Renovate dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: /tmp/renovate-cache # Renovate's default cache directory
|
||||
path: /tmp/renovate-cache
|
||||
key: ${{ runner.os }}-renovate-${{ hashFiles('config.js') }}-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-renovate-${{ hashFiles('config.js') }}-
|
||||
|
@ -109,46 +114,56 @@ jobs:
|
|||
id: generate_config
|
||||
run: |
|
||||
set -e
|
||||
# Get the full list of repos from the discover job output
|
||||
ALL_REPOS_JSON='${{ needs.discover.outputs.repositories }}'
|
||||
# Get the current job index and total number of jobs
|
||||
JOB_INDEX=${{ matrix.partition }}
|
||||
TOTAL_JOBS=${{ env.RENOVATE_PARALLEL_JOBS }}
|
||||
|
||||
echo "Generating config for partition $JOB_INDEX / $TOTAL_JOBS"
|
||||
|
||||
# --- Add Input Validation ---
|
||||
if ! echo "$ALL_REPOS_JSON" | jq -e 'type == "array"' > /dev/null; then
|
||||
echo "Error: Input from discover job is not a valid JSON array."
|
||||
echo "Received: $ALL_REPOS_JSON"
|
||||
exit 1
|
||||
fi
|
||||
# --- End Input Validation ---
|
||||
|
||||
# Use jq to filter the repository list for this specific partition
|
||||
# Selects repositories where (repo_index % total_jobs) == current_job_index
|
||||
PARTITION_REPOS_JSON=$(echo "$ALL_REPOS_JSON" | jq --argjson idx "$JOB_INDEX" --argjson total "$TOTAL_JOBS" \
|
||||
PARTITION_REPOS_JSON=$(echo "$ALL_REPOS_JSON" | jq -c --argjson idx "$JOB_INDEX" --argjson total "$TOTAL_JOBS" \
|
||||
'[.[range(length) | select(. % $total == $idx)]]')
|
||||
|
||||
# --- Add Partition Validation ---
|
||||
if ! echo "$PARTITION_REPOS_JSON" | jq -e 'type == "array"' > /dev/null; then
|
||||
echo "Error: Calculated partition is not a valid JSON array."
|
||||
echo "Calculated: $PARTITION_REPOS_JSON"
|
||||
exit 1
|
||||
fi
|
||||
# --- End Partition Validation ---
|
||||
|
||||
PARTITION_REPO_COUNT=$(echo "$PARTITION_REPOS_JSON" | jq 'length')
|
||||
echo "Repositories in this partition: $PARTITION_REPO_COUNT"
|
||||
# echo "$PARTITION_REPOS_JSON" # Uncomment for debugging
|
||||
|
||||
# Create a temporary JSON config file for this Renovate run
|
||||
# It includes the base settings from config.js but overrides/sets 'repositories'
|
||||
# and removes 'autodiscover'
|
||||
# Ensure config.js exists and is readable before proceeding
|
||||
if [ ! -f config.js ]; then
|
||||
echo "Error: config.js not found in checkout directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use --argjson repos "$PARTITION_REPOS_JSON" which expects valid JSON
|
||||
jq --argjson repos "$PARTITION_REPOS_JSON" \
|
||||
'.repositories = $repos | del(.autodiscover) | del(.onboardingConfig)' \
|
||||
config.js > renovate-partition-${JOB_INDEX}.json
|
||||
|
||||
echo "Generated config file: renovate-partition-${JOB_INDEX}.json"
|
||||
# Store filename for the next step
|
||||
echo "config_file=renovate-partition-${JOB_INDEX}.json" >> $GITHUB_OUTPUT
|
||||
|
||||
# Run Renovate using the generated partitioned configuration file
|
||||
- name: Run Renovate Partition ${{ matrix.partition }}
|
||||
run: renovate
|
||||
env:
|
||||
# --- Core Configuration ---
|
||||
# Use the generated JSON config file for this partition
|
||||
RENOVATE_CONFIG_FILE: ${{ steps.generate_config.outputs.config_file }}
|
||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} # Token for Gitea
|
||||
GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} # Only if needed
|
||||
|
||||
# --- Performance & Logging ---
|
||||
LOG_LEVEL: "info" # Use 'debug' only when troubleshooting
|
||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||
# GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} # Only if needed
|
||||
LOG_LEVEL: "info"
|
||||
RENOVATE_CACHE_DIR: /tmp/renovate-cache
|
||||
# Optional: Lower concurrency per job if needed, depends on runner resources
|
||||
# RENOVATE_CONCURRENCY: 5
|
||||
# RENOVATE_CONCURRENCY: 5 # Optional: Lower concurrency per job
|
||||
|
|
Loading…
Add table
Reference in a new issue