name: Daily fetch bangs.json from Kagi on: schedule: - cron: "0 0 * * *" workflow_dispatch: jobs: fetch-bangs: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 with: fetch-depth: 1 - name: Install bun uses: oven-sh/setup-bun@v1 - name: Download bangs.json run: | curl -o bangs.json https://raw.githubusercontent.com/kagisearch/bangs/refs/heads/main/data/bangs.json - name: Verify file run: | if [ ! -s bangs.json ]; then echo "Downloaded file is empty" exit 1 fi if ! jq empty bangs.json; then echo "Downloaded file is not valid JSON" exit 1 fi - name: Replace bangs.json run: | mkdir -p src/bangs mv bangs.json src/bangs/bangs.json - name: 🥔 hash run: bun run hash - name: Configure Git run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - name: Check for changes and commit id: check_changes run: | git add src/bangs/bangs.json src/bangs/hashbang.ts # Check if there are changes to commit if git diff --staged --quiet; then echo "No changes to commit" echo "has_changes=false" >> $GITHUB_OUTPUT exit 0 fi echo "Changes detected in bangs files" echo "has_changes=true" >> $GITHUB_OUTPUT # Look for bangs update commits in history git fetch origin main --unshallow # Check if previous commit was a bangs update PREV_COMMIT_MSG=$(git log -1 --pretty=%B) if [[ "$PREV_COMMIT_MSG" == "chore: update bangs.json" ]]; then # Amend the previous commit git commit --amend -m "chore: update bangs.json" else # Create a new commit git commit -m "chore: update bangs.json" fi # Push to main - using force only if we amended if [[ "$PREV_COMMIT_MSG" == "chore: update bangs.json" ]]; then git push --force-with-lease origin main else git push origin main fi # Handle Tangled push only if we have new changes - name: Setup Tailscale if: steps.check_changes.outputs.has_changes == 'true' uses: tailscale/github-action@v3 with: oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} tags: tag:ci - name: Configure SSH if: steps.check_changes.outputs.has_changes == 'true' run: | mkdir -p ~/.ssh echo "StrictHostKeyChecking no" >> ~/.ssh/config - name: Push to Tangled if: steps.check_changes.outputs.has_changes == 'true' run: | git remote add tangled git@ember:did:plc:krxbvxvis5skq7jj6eot23ul/unduckified || true git push tangled main continue-on-error: true