Skip to content

Rebuild indexes

Rebuild indexes #2397

name: Rebuild indexes
# Hybrid trigger: event-driven on relevant pushes + scheduled safety net.
# The concurrency group ensures only one rebuild runs at a time. When multiple
# PRs merge in quick succession, earlier runs are cancelled and only the latest
# (which sees ALL merged changes) actually executes — no wasted compute.
#
# Because main requires a PR to merge, the workflow creates a temporary branch,
# opens a PR, and auto-merges it. Merges performed via GITHUB_TOKEN do not
# trigger further workflow runs, so there is no infinite-loop risk.
on:
push:
branches: [main]
paths:
- 'apis/openapi/**/apis.json'
- 'apis/openapi/**/scorecard.json'
schedule:
# Safety net: rebuild every 6 hours in case a push-triggered run failed
# or files were modified without matching the paths filter.
- cron: '15 */6 * * *'
workflow_dispatch: {}
concurrency:
group: rebuild-indexes
cancel-in-progress: true
jobs:
rebuild:
if: github.event_name != 'push' || github.actor != 'jentic-public-apis-automation[bot]'
runs-on: ubuntu-latest
permissions: {}
env:
GITHUB_REPO_URL: "https://github.com/${{ github.repository }}"
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.JENTIC_PUBLIC_APIS_AUTOMATION_CLIENT_ID }}
private-key: ${{ secrets.JENTIC_PUBLIC_APIS_AUTOMATION_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- name: Sparse checkout (apis.json + scorecard.json only)
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git clone --no-checkout --depth 1 --filter=blob:none \
"https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" .
git sparse-checkout set --no-cone \
'apis/openapi/**/apis.json' \
'apis/openapi/**/scorecard.json' \
'apis/openapi/apis.json' \
'apis/openapi/scores.json' \
'.github/scripts/*' \
'index/apis/openapi/**'
git checkout main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install jentic-apitools-cli
run: pip install --quiet jentic-apitools-cli
- name: Rebuild apis.json
run: |
jentic-apitools rebuild-apis-json . \
--base-dir apis/openapi \
--github-repo-url "$GITHUB_REPO_URL" \
--github-repo-branch main
- name: Rebuild scores.json
run: |
jentic-apitools rebuild-scores-json . \
--base-dir apis/openapi
- name: Rebuild API browsing index
run: ./.github/scripts/generate-apis-index.sh
- name: Create PR and merge
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
run: |
APP_USER_ID="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
git config user.name "${APP_SLUG}[bot]"
git config user.email "${APP_USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
git add apis/openapi/apis.json apis/openapi/scores.json index/apis/openapi/
# Safety guard: only generated index paths may be changed.
git diff --cached --name-only > changed-files.txt
if grep -Ev '^(apis/openapi/apis\.json|apis/openapi/scores\.json|index/apis/openapi/)' changed-files.txt; then
echo "Unexpected files changed:"
cat changed-files.txt
exit 1
fi
# Exit early if nothing actually changed (idempotent rebuild).
if git diff --cached --quiet; then
echo "Index files are already up to date — nothing to commit."
exit 0
fi
BRANCH="auto/rebuild-indexes-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH"
git commit -m "Rebuild apis.json, scores.json, and API browsing indexes"
git push origin "$BRANCH"
PR_URL=$(gh pr create \
--base main \
--head "$BRANCH" \
--title "Rebuild apis.json, scores.json, and API browsing indexes" \
--body "Automated rebuild of index files triggered by changes in \`apis/openapi/\`.")
echo "Created PR: $PR_URL"
gh pr merge "$PR_URL" --squash --auto --delete-branch
echo "Auto-merge enabled on $PR_URL"