A fast, local-first "redirection engine" for !bang users with a few extra features ^-^

feat: hopefully avoid repo squashing

dunkirk.sh 3b1e4106 5acf9235

verified
+49 -20
+49 -20
.github/workflows/update-bangs.yaml
··· 8 8 fetch-bangs: 9 9 runs-on: ubuntu-latest 10 10 steps: 11 - - uses: actions/checkout@v3 11 + - name: Checkout repository 12 + uses: actions/checkout@v3 13 + with: 14 + fetch-depth: 1 12 15 13 16 - name: Install bun 14 17 uses: oven-sh/setup-bun@v1 ··· 30 33 31 34 - name: Replace bangs.json 32 35 run: | 33 - mkdir -p src 36 + mkdir -p src/bangs 34 37 mv bangs.json src/bangs/bangs.json 35 38 36 39 - name: 🥔 hash 37 40 run: bun run hash 38 41 39 - - name: Commit changes 42 + - name: Configure Git 40 43 run: | 41 44 git config --local user.email "github-actions[bot]@users.noreply.github.com" 42 45 git config --local user.name "github-actions[bot]" 46 + 47 + - name: Check for changes and commit 48 + id: check_changes 49 + run: | 43 50 git add src/bangs/bangs.json src/bangs/hashbang.ts 44 - 45 - # Check if the last commit was a bangs update 46 - LAST_COMMIT_MSG=$(git log -1 --pretty=%B) 47 - if [[ "$LAST_COMMIT_MSG" == "chore: update bangs.json" ]]; then 48 - # If it was, amend the commit 49 - git commit --amend -m "chore: update bangs.json" || exit 0 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 50 78 else 51 - # Otherwise, create a new commit 52 - git commit -m "chore: update bangs.json" || exit 0 79 + git push origin main 53 80 fi 54 81 55 - git push --force-with-lease 56 - 57 - - name: Tailscale 82 + # Handle Tangled push only if we have new changes 83 + - name: Setup Tailscale 84 + if: steps.check_changes.outputs.has_changes == 'true' 58 85 uses: tailscale/github-action@v3 59 86 with: 60 87 oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} 61 88 oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} 62 89 tags: tag:ci 63 90 64 - - name: Add remote 65 - run: git remote add tangled git@ember:did:plc:krxbvxvis5skq7jj6eot23ul/unduckified 66 - 67 - - name: Configure ssh 91 + - name: Configure SSH 92 + if: steps.check_changes.outputs.has_changes == 'true' 68 93 run: | 69 94 mkdir -p ~/.ssh 70 95 echo "StrictHostKeyChecking no" >> ~/.ssh/config 71 96 72 - - name: Push to tangled 73 - run: git push tangled main 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