-
Notifications
You must be signed in to change notification settings - Fork 67
138 lines (115 loc) · 5.27 KB
/
instances.yml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: instances
on:
push:
branches:
- develop
workflow_dispatch:
jobs:
instances:
name: Instances
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Query Instances
run: |
# Query the list of instances
curl -H 'Content-Type: application/json' -X POST \
-d '{"query": "query {nodes(softwarename: \"lemmy\") {domain active_users_monthly}}"}' https://api.fediverse.observer 2> /dev/null | \
jq -r '.data.nodes | .[] | select(.active_users_monthly > 50) | .domain' > lemmy-instances.txt.tmp
# Combine the output with the existing instances.txt file.
sort lemmy-instances.txt lemmy-instances.txt.tmp | uniq -i > lemmy-instances.txt
# Delete the temp file
rm lemmy-instances.txt.tmp
# Convert the text file to a dart file
cat << EOF > lib/instances.dart
const List<String> instances = [
$(awk '{ print " \047"$0"\047," }' lemmy-instances.txt)
];
EOF
# Put the instances in the Android manifest file
manifestInstances="$(awk '{ print " <data android:host=\""$0"\" />" }' lemmy-instances.txt)"
inSection=false
while IFS= read -r line; do
if [[ $line == *"#AUTO_GEN_INSTANCE_LIST_DO_NOT_TOUCH#"* ]]; then
inSection=true
fi
if [[ $line == *"#INSTANCE_LIST_END#"* ]]; then
echo "$manifestInstances" >> android/app/src/main/AndroidManifest-new.xml
inSection=false
fi
if [[ $line == *"android:host"* ]]; then
if [ "$inSection" = true ]; then
continue
fi
fi
echo "$line" >> android/app/src/main/AndroidManifest-new.xml
done < android/app/src/main/AndroidManifest.xml
mv android/app/src/main/AndroidManifest-new.xml android/app/src/main/AndroidManifest.xml
# ---------- Safari Extension ----------
totalLines=$(wc -l < lemmy-instances.txt)
currentLine=0
safariManifestInstances=""
safariContentInstances=""
# Generate the Safari extension domains used in manifest.json and content.js
# It ignores the last comma in the list to generate proper json
while IFS= read -r instance; do
currentLine=$((currentLine + 1))
if [ "$currentLine" -eq 1 ]; then
# First line
safariManifestInstances=" \"*://$instance/*\""
safariContentInstances=" \"$instance\""
elif [ "$currentLine" -eq "$totalLines" ]; then
# Last line
safariManifestInstances="$safariManifestInstances,\n \"*://$instance/*\"\n"
safariContentInstances="$safariContentInstances,\n \"$instance\"\n"
else
safariManifestInstances="$safariManifestInstances,\n \"*://$instance/*\""
safariContentInstances="$safariContentInstances,\n \"$instance\""
fi
done < lemmy-instances.txt
# Generates the new manifest.json with the updated instances
inSection=false
while IFS= read -r line; do
if [[ $line == *"matches\": ["* ]]; then
inSection=true
fi
if [[ $line == " ]" ]]; then
printf "$safariManifestInstances" >> "ios/Open In Thunder/Resources/manifest-new.json"
inSection=false
fi
if [[ $line == *"*://"* ]]; then
if [ "$inSection" = true ]; then
continue
fi
fi
echo "$line" >> "ios/Open In Thunder/Resources/manifest-new.json"
done < "ios/Open In Thunder/Resources/manifest.json"
mv "ios/Open In Thunder/Resources/manifest-new.json" "ios/Open In Thunder/Resources/manifest.json"
# Generates the new content.js with the updated instances
inSection=false
while IFS= read -r line; do
if [[ $line == *"let instances = ["* ]]; then
inSection=true
fi
if [[ $line == "];" ]]; then
printf "$safariContentInstances" >> "ios/Open In Thunder/Resources/content-new.js"
inSection=false
fi
if [[ $line == *" \""* ]]; then
if [ "$inSection" = true ]; then
continue
fi
fi
echo "$line" >> "ios/Open In Thunder/Resources/content-new.js"
done < "ios/Open In Thunder/Resources/content.js"
mv "ios/Open In Thunder/Resources/content-new.js" "ios/Open In Thunder/Resources/content.js"
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
commit-message: Update instances
title: Update instances
body: This PR is updating `lemmy-instances.txt`, `instances.dart`, `AndroidManifest.xml`, `manifest.json` and `content.js` with the latest list of instances retrieved from fediverse.observer.
branch: update-instances
delete-branch: true
author: GitHub <[email protected]>