summaryrefslogtreecommitdiff
path: root/.github/workflows/update-instances.yml
blob: d16bdddd1cec7d87b6854c6ec69595e21f1208f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
on:
  schedule:
    - cron: '0 0 * * *'
    
jobs:
  update-instances:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: sudo apt-get install -y jq
    - name: Fetch instances
      run: |
        function apply_update() {
          mv services-tmp.json services.json
          rm -f *-tmp.json

          # Ensure no trailing slashes for any instance
          sed -i '' 's/\/"/"/g' services.json
        }
        
        # ==============================================================
        # Git config
        # ==============================================================
        git config --global user.name github-actions
        git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
        git remote set-url origin git@github.com:benbusby/farside.git
        git checkout main
        
        # ==============================================================
        # Searx update
        # ==============================================================
        curl -s https://searx.space/data/instances.json | \
          jq '[
            .instances |
            to_entries[] |
            select(.value.network_type == "normal") |
            select(.value.version | . != null) |
            select(.value.version | startswith("1.0.0")) |
            select(.value.network.asn_privacy == 0) |
            select(.value.http.error == null) |
            select(.value.tls.grade == "A+" or .value.tls.grade == "A") |
            select(.value.http.grade == "A+" or .value.http.grade == "A") |
            select(.value.html.grade == "V" or .value.html.grade == "F") |
            .key
          ] | sort' > searx-tmp.json

        jq --slurpfile searx searx-tmp.json \
          '( .[] | select(.type == "searx") )
          .instances |= $searx[0]' services.json > services-tmp.json

        apply_update
        
        # ==============================================================
        # TODO: Update instances for other services
        # ==============================================================
        
        # ==============================================================
        # Push changes
        # ==============================================================
        if [[ $(git diff-index --quiet HEAD) ]]; then
          echo "No updates"
        else
          git add services.json
          git commit -m '[CI] Auto update instances'
          git push
        fi