A fast, local-first "redirection engine" for !bang users with a few extra features ^-^
1name: Daily fetch bangs.json from Kagi
2on:
3 schedule:
4 - cron: "0 0 * * *"
5 workflow_dispatch:
6
7jobs:
8 fetch-bangs:
9 runs-on: ubuntu-latest
10 steps:
11 - name: Checkout repository
12 uses: actions/checkout@v3
13 with:
14 fetch-depth: 1
15
16 - name: Install bun
17 uses: oven-sh/setup-bun@v1
18
19 - name: Download bangs.json
20 run: |
21 curl -o bangs.json https://raw.githubusercontent.com/kagisearch/bangs/refs/heads/main/data/bangs.json
22
23 - name: Verify file
24 run: |
25 if [ ! -s bangs.json ]; then
26 echo "Downloaded file is empty"
27 exit 1
28 fi
29 if ! jq empty bangs.json; then
30 echo "Downloaded file is not valid JSON"
31 exit 1
32 fi
33
34 - name: Replace bangs.json
35 run: |
36 mkdir -p src/bangs
37 mv bangs.json src/bangs/bangs.json
38
39 - name: 🥔 hash
40 run: bun run hash
41
42 - name: Configure Git
43 run: |
44 git config --local user.email "github-actions[bot]@users.noreply.github.com"
45 git config --local user.name "github-actions[bot]"
46
47 - name: Check for changes and commit
48 id: check_changes
49 run: |
50 git add src/bangs/bangs.json src/bangs/hashbang.ts
51
52 # Check if there are changes to commit
53 if git diff --staged --quiet; then
54 echo "No changes to commit"
55 echo "has_changes=false" >> $GITHUB_OUTPUT
56 exit 0
57 fi
58
59 echo "Changes detected in bangs files"
60 echo "has_changes=true" >> $GITHUB_OUTPUT
61
62 # Look for bangs update commits in history
63 git fetch origin main --unshallow
64
65 # Check if previous commit was a bangs update
66 PREV_COMMIT_MSG=$(git log -1 --pretty=%B)
67 if [[ "$PREV_COMMIT_MSG" == "chore: update bangs.json" ]]; then
68 # Amend the previous commit
69 git commit --amend -m "chore: update bangs.json"
70 else
71 # Create a new commit
72 git commit -m "chore: update bangs.json"
73 fi
74
75 # Push to main - using force only if we amended
76 if [[ "$PREV_COMMIT_MSG" == "chore: update bangs.json" ]]; then
77 git push --force-with-lease origin main
78 else
79 git push origin main
80 fi
81
82 # Handle Tangled push only if we have new changes
83 - name: Setup Tailscale
84 if: steps.check_changes.outputs.has_changes == 'true'
85 uses: tailscale/github-action@v3
86 with:
87 oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
88 oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
89 tags: tag:ci
90
91 - name: Configure SSH
92 if: steps.check_changes.outputs.has_changes == 'true'
93 run: |
94 mkdir -p ~/.ssh
95 echo "StrictHostKeyChecking no" >> ~/.ssh/config
96
97 - name: Push to Tangled
98 if: steps.check_changes.outputs.has_changes == 'true'
99 run: |
100 git remote add tangled git@ember:did:plc:krxbvxvis5skq7jj6eot23ul/unduckified || true
101 git push tangled main
102 continue-on-error: true