1
0
mirror of https://github.com/Prowlarr/Indexers.git synced 2026-04-25 19:08:06 +01:00

fix: simplify indexer-sync workflow to let script handle git operations

This commit is contained in:
Servarr
2025-08-13 12:30:48 -05:00
parent 2597a83853
commit fa3efc5d15

View File

@@ -13,13 +13,17 @@ on:
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
sync-indexers:
name: Sync Indexers from Jackett
runs-on: ubuntu-latest
if: github.repository == 'Prowlarr/Indexers'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
@@ -45,136 +49,47 @@ jobs:
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for existing sync PR
id: check-pr
- name: Run indexer sync
run: |
# Check if there's already an open PR for indexer sync
EXISTING_PR=$(gh pr list --head "automated-indexer-sync" --state open --json number --jq '.[0].number' || echo "")
if [ -n "$EXISTING_PR" ]; then
echo "existing_pr=$EXISTING_PR" >> $GITHUB_OUTPUT
echo "Found existing PR #$EXISTING_PR"
else
echo "existing_pr=" >> $GITHUB_OUTPUT
echo "No existing PR found"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run indexer sync with -z mode
id: sync
run: |
# Create branch for automated sync
BRANCH_NAME="automated-indexer-sync"
git checkout -B "$BRANCH_NAME"
# Run the sync script with -z mode (skip backporting), automation mode, and push enabled
set +e
./scripts/indexer-sync-v2.sh -z -a -p -b "$BRANCH_NAME" -o origin
SYNC_EXIT_CODE=$?
set -e
echo "sync_exit_code=$SYNC_EXIT_CODE" >> $GITHUB_OUTPUT
case $SYNC_EXIT_CODE in
0)
echo "result=up_to_date" >> $GITHUB_OUTPUT
echo "Indexers are already up to date"
;;
1|2|3|4)
echo "result=error" >> $GITHUB_OUTPUT
echo "Sync script failed with exit code $SYNC_EXIT_CODE"
exit $SYNC_EXIT_CODE
;;
*)
# Check if there are any staged changes
if git diff --cached --quiet; then
echo "result=no_changes" >> $GITHUB_OUTPUT
echo "No changes to commit"
else
echo "result=changes" >> $GITHUB_OUTPUT
echo "Changes detected and committed"
fi
;;
esac
# Run the sync script with -z mode, automation mode, and push enabled
./scripts/indexer-sync-v2.sh -z -a -p -b automated-indexer-sync -o origin
- name: Create or update pull request
if: steps.sync.outputs.result == 'changes' || (steps.sync.outputs.result == 'up_to_date' && github.event.inputs.force_sync == 'true')
run: |
BRANCH_NAME="automated-indexer-sync"
# Get the latest commit message for PR details
LATEST_COMMIT=$(git log -1 --format=%B)
# Extract indexer changes from commit message
ADDED_INDEXERS=$(echo "$LATEST_COMMIT" | grep "^Added Indexers:" | sed 's/Added Indexers: //' || echo "")
MODIFIED_INDEXERS=$(echo "$LATEST_COMMIT" | grep "^Modified Indexers:" | sed 's/Modified Indexers: //' || echo "")
REMOVED_INDEXERS=$(echo "$LATEST_COMMIT" | grep "^Removed Indexers:" | sed 's/Removed Indexers: //' || echo "")
NEW_SCHEMA_INDEXERS=$(echo "$LATEST_COMMIT" | grep "^New Schema Indexers:" | sed 's/New Schema Indexers: //' || echo "")
# Create PR body
PR_BODY="## Automated Indexer Sync
This PR contains automated updates from the Jackett repository.
**⚠️ Backporting was skipped** - Manual review may be required for older schema versions.
### Changes Summary:
"
if [ -n "$ADDED_INDEXERS" ]; then
PR_BODY="$PR_BODY
#### ✅ Added Indexers:
\`\`\`
$ADDED_INDEXERS
\`\`\`
"
fi
if [ -n "$MODIFIED_INDEXERS" ]; then
PR_BODY="$PR_BODY
#### 🔄 Modified Indexers:
\`\`\`
$MODIFIED_INDEXERS
\`\`\`
"
fi
if [ -n "$REMOVED_INDEXERS" ]; then
PR_BODY="$PR_BODY
#### ❌ Removed Indexers:
\`\`\`
$REMOVED_INDEXERS
\`\`\`
"
fi
if [ -n "$NEW_SCHEMA_INDEXERS" ]; then
PR_BODY="$PR_BODY
#### 🆕 New Schema Indexers (Requires Review):
\`\`\`
$NEW_SCHEMA_INDEXERS
\`\`\`
"
fi
PR_BODY="$PR_BODY
### Automation Details:
- Sync performed with \`-z\` flag (backports skipped)
- Triggered by: ${{ github.event_name }}
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Please review the changes carefully before merging, especially any new schema indexers that may require Cardigann updates."
# Check if PR already exists
if [ -n "${{ steps.check-pr.outputs.existing_pr }}" ]; then
echo "Updating existing PR #${{ steps.check-pr.outputs.existing_pr }}"
gh pr edit "${{ steps.check-pr.outputs.existing_pr }}" --body "$PR_BODY"
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$EXISTING_PR" ]; then
echo "Updating existing PR #$EXISTING_PR"
gh pr edit "$EXISTING_PR" --body "## Automated Indexer Sync
This PR contains automated updates from the Jackett repository.
**⚠️ Backporting was skipped** - Manual review may be required for older schema versions.
### Latest Update: $(date --iso-8601=seconds)
- Triggered by: ${{ github.event_name }}
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Please review the changes carefully before merging."
else
echo "Creating new pull request"
gh pr create \
--title "🤖 Automated Indexer Sync ($(date +%Y-%m-%d))" \
--body "$PR_BODY" \
--body "## Automated Indexer Sync
This PR contains automated updates from the Jackett repository.
**⚠️ Backporting was skipped** - Manual review may be required for older schema versions.
### Automation Details:
- Sync performed with \`-z\` flag (backports skipped)
- Triggered by: ${{ github.event_name }}
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Please review the changes carefully before merging." \
--head "$BRANCH_NAME" \
--base master \
--label "automated" \
@@ -183,38 +98,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on failure
if: failure() && steps.sync.outputs.sync_exit_code != '0'
run: |
if [ -n "${{ steps.check-pr.outputs.existing_pr }}" ]; then
gh pr comment "${{ steps.check-pr.outputs.existing_pr }}" --body "❌ **Sync Failed**
The automated indexer sync failed with exit code ${{ steps.sync.outputs.sync_exit_code }}.
Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
case "${{ steps.sync.outputs.result }}" in
"up_to_date")
echo "✅ Indexers are already up to date with Jackett"
;;
"no_changes")
echo " Sync completed but no changes were made"
;;
"changes")
echo "✅ Indexer sync completed successfully with changes"
if [ -n "${{ steps.check-pr.outputs.existing_pr }}" ]; then
echo "📝 Updated existing PR #${{ steps.check-pr.outputs.existing_pr }}"
else
echo "📝 Created new pull request"
fi
;;
"error")
echo "❌ Sync failed - check logs for details"
exit 1
;;
esac
echo "✅ Indexer sync workflow completed"
echo "📝 PR created/updated if changes were found"