Update .gitea/workflows/renovate.yaml
This commit is contained in:
parent
f4200013e4
commit
df74bbe235
1 changed files with 78 additions and 63 deletions
|
@ -14,7 +14,8 @@ jobs:
|
|||
discover:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
repositories: ${{ steps.get_repos.outputs.repositories }}
|
||||
# Keep outputting count for potential checks later
|
||||
repo_count: ${{ steps.get_repos.outputs.repo_count }}
|
||||
steps:
|
||||
- name: Install curl and jq
|
||||
run: sudo apt-get update && sudo apt-get install -y curl jq
|
||||
|
@ -24,31 +25,23 @@ jobs:
|
|||
env:
|
||||
GITEA_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||
run: |
|
||||
set -e # Exit on error
|
||||
all_repos="[]" # Default to an empty JSON array
|
||||
set -e
|
||||
all_repos="[]"
|
||||
page=1
|
||||
limit=50
|
||||
|
||||
echo "Fetching repositories from ${{ env.GITEA_ENDPOINT }}"
|
||||
|
||||
while true; do
|
||||
# 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")
|
||||
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
|
@ -57,32 +50,34 @@ jobs:
|
|||
|
||||
count=$(echo "$body" | jq 'length')
|
||||
echo "Fetched $count repositories on page $page."
|
||||
if [ "$count" -eq 0 ]; then break; fi
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
break # No more repositories
|
||||
fi
|
||||
|
||||
# Filter for non-archived repos and extract full_name, merge with previous results
|
||||
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
|
||||
break # Last page reached
|
||||
fi
|
||||
|
||||
if [ "$count" -lt "$limit" ]; then break; fi
|
||||
page=$((page + 1))
|
||||
done
|
||||
|
||||
repo_count=$(echo "$all_repos" | jq 'length')
|
||||
echo "Total non-archived repositories found: $repo_count"
|
||||
echo "repo_count=$repo_count" >> $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
|
||||
# Output the final JSON array to a file
|
||||
echo "$all_repos" | jq -c . > repositories.json
|
||||
echo "Saved repository list to repositories.json"
|
||||
|
||||
# Upload the repository list as an artifact
|
||||
- name: Upload repository list artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: repo-list
|
||||
path: repositories.json
|
||||
|
||||
renovate:
|
||||
needs: discover
|
||||
# Optional: Add a condition to skip if no repos were found
|
||||
# if: needs.discover.outputs.repo_count > 0
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/renovatebot/renovate:37.290.1
|
||||
strategy:
|
||||
|
@ -91,79 +86,99 @@ jobs:
|
|||
partition: ${{ fromJson(format('[{0}]', join(range(0, env.RENOVATE_PARALLEL_JOBS), ','))) }}
|
||||
|
||||
steps:
|
||||
- name: Checkout Base Config Repo
|
||||
uses: actions/checkout@v4
|
||||
# No need to checkout base config repo anymore for this step
|
||||
|
||||
# --- Debugging Step ---
|
||||
- name: Show Discovered Repositories Output
|
||||
run: |
|
||||
echo "Received repositories output from discover job:"
|
||||
echo '${{ needs.discover.outputs.repositories }}'
|
||||
# --- End Debugging Step ---
|
||||
# Download the repository list artifact
|
||||
- name: Download repository list artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: repo-list
|
||||
# Download to the current directory
|
||||
|
||||
- name: Cache Renovate dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
# Use a more stable base key if config.js isn't changing often
|
||||
# Or keep hashFiles if you still modify config.js for other reasons (like presets)
|
||||
path: /tmp/renovate-cache
|
||||
key: ${{ runner.os }}-renovate-${{ hashFiles('config.js') }}-${{ github.run_id }}
|
||||
key: ${{ runner.os }}-renovate-base-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-renovate-${{ hashFiles('config.js') }}-
|
||||
${{ runner.os }}-renovate-
|
||||
${{ runner.os }}-renovate-base-
|
||||
|
||||
- name: Generate Partitioned Config
|
||||
- name: Generate Partitioned Config JSON
|
||||
id: generate_config
|
||||
run: |
|
||||
set -e
|
||||
ALL_REPOS_JSON='${{ needs.discover.outputs.repositories }}'
|
||||
# Read the repo list from the downloaded file
|
||||
if [ ! -f repositories.json ]; then
|
||||
echo "Error: repositories.json artifact not found."
|
||||
exit 1
|
||||
fi
|
||||
ALL_REPOS_JSON=$(cat repositories.json)
|
||||
JOB_INDEX=${{ matrix.partition }}
|
||||
TOTAL_JOBS=${{ env.RENOVATE_PARALLEL_JOBS }}
|
||||
|
||||
echo "Generating config for partition $JOB_INDEX / $TOTAL_JOBS"
|
||||
|
||||
# --- Add Input Validation ---
|
||||
# Validate the JSON read from the file
|
||||
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"
|
||||
echo "Error: Content of repositories.json is not a valid JSON array."
|
||||
echo "Content: $ALL_REPOS_JSON"
|
||||
exit 1
|
||||
fi
|
||||
# --- End Input Validation ---
|
||||
|
||||
# Use jq to filter the repository list for this specific partition
|
||||
# Partition the repositories
|
||||
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"
|
||||
|
||||
# Create a temporary JSON config file for this Renovate run
|
||||
# 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
|
||||
# If a partition has no repos, we can optionally skip the renovate run
|
||||
if [ "$PARTITION_REPO_COUNT" -eq 0 ]; then
|
||||
echo "No repositories for this partition, skipping Renovate run."
|
||||
echo "skip_run=true" >> $GITHUB_OUTPUT
|
||||
# Create an empty config file just to satisfy the next step's env var
|
||||
touch renovate-partition-${JOB_INDEX}.json
|
||||
echo "config_file=renovate-partition-${JOB_INDEX}.json" >> $GITHUB_OUTPUT
|
||||
exit 0 # Exit step successfully
|
||||
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
|
||||
# --- Create the JSON config from scratch ---
|
||||
CONFIG_FILE="renovate-partition-${JOB_INDEX}.json"
|
||||
echo "Creating $CONFIG_FILE"
|
||||
|
||||
echo "Generated config file: renovate-partition-${JOB_INDEX}.json"
|
||||
echo "config_file=renovate-partition-${JOB_INDEX}.json" >> $GITHUB_OUTPUT
|
||||
# Use jq to construct the JSON object directly
|
||||
# Add any other essential global config options here if needed
|
||||
jq -n \
|
||||
--arg platform "gitea" \
|
||||
--arg endpoint "${{ env.GITEA_ENDPOINT }}" \
|
||||
--arg gitAuthor "${{ env.RENOVATE_GIT_AUTHOR }}" \
|
||||
--argjson repositories "$PARTITION_REPOS_JSON" \
|
||||
'{
|
||||
platform: $platform,
|
||||
endpoint: $endpoint,
|
||||
repositories: $repositories,
|
||||
gitAuthor: $gitAuthor,
|
||||
persistCache: true
|
||||
# Add other necessary global options like cacheDir if not default
|
||||
# cacheDir: "/tmp/renovate-cache"
|
||||
# DO NOT add autodiscover or onboardingConfig here
|
||||
}' > "$CONFIG_FILE"
|
||||
|
||||
echo "Generated config file: $CONFIG_FILE"
|
||||
cat "$CONFIG_FILE" # Print the generated config for debugging
|
||||
echo "config_file=$CONFIG_FILE" >> $GITHUB_OUTPUT
|
||||
echo "skip_run=false" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Run Renovate Partition ${{ matrix.partition }}
|
||||
# Conditionally skip this step if the partition was empty
|
||||
if: steps.generate_config.outputs.skip_run != 'true'
|
||||
run: renovate
|
||||
env:
|
||||
RENOVATE_CONFIG_FILE: ${{ steps.generate_config.outputs.config_file }}
|
||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||
# GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} # Only if needed
|
||||
GITHUB_COM_TOKEN: ${{ secrets.GH_TOKEN }} # Only if needed
|
||||
LOG_LEVEL: "info"
|
||||
RENOVATE_CACHE_DIR: /tmp/renovate-cache
|
||||
# RENOVATE_CONCURRENCY: 5 # Optional: Lower concurrency per job
|
||||
# RENOVATE_CONCURRENCY: 5 # Optional
|
||||
|
|
Loading…
Add table
Reference in a new issue