-
-
Notifications
You must be signed in to change notification settings - Fork 22
163 lines (137 loc) · 5.84 KB
/
user-agent_scrape.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Please write our copyright if you use this file.
# © 2023 Floorp Projects & Contributors
name: "(U) 🧰 User-Agent Scrape"
on:
workflow_dispatch:
schedule:
- cron: "0 15 * * *"
jobs:
linux:
if: (github.event_name == 'schedule' && github.repository_owner == 'Floorp-Projects') || (github.event_name != 'schedule')
name: Linux
runs-on: ubuntu-22.04
steps:
- name: Clone User-Agent_Scraper 🧬
uses: actions/checkout@v4
with:
repository: Floorp-Projects/User-Agent_Scraper
path: User-Agent_Scraper
- name: Setup 🪛
run: |
cd User-Agent_Scraper
sudo apt update
sudo apt install nodejs npm xvfb
npm install
- name: Install browsers 🌐
run: |
cd ~
# Firefox
aria2c -o firefox.tar.bz2 "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=en-US"
tar -xvf firefox.tar.bz2
rm firefox.tar.bz2
# Chrome
aria2c -o chrome.deb "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
mkdir chrome_tmp
cd chrome_tmp
ar vx ../chrome.deb
tar -xvf data.tar.xz
mv ./opt/google/chrome ../chrome
cd ../
rm -rf chrome_tmp
rm chrome.deb
# Edge
aria2c -o msedge.deb "https://go.microsoft.com/fwlink?linkid=2149051&brand=M102"
mkdir msedge_tmp
cd msedge_tmp
ar vx ../msedge.deb
tar -xvf data.tar.xz
mv ./opt/microsoft/msedge ../msedge
cd ../
rm -rf msedge_tmp
rm msedge.deb
- name: Scrape
id: scrape
run: |
cd User-Agent_Scraper
Xvfb :2 -screen 0 1024x768x24 &
export DISPLAY=:2
# Firefox
npm run --silent start ~/firefox/firefox > user_agent.txt
export firefox_stable_ua=`cat user_agent.txt`
echo $firefox_stable_ua
# Chrome
~/chrome/chrome &
sleep 5
pkill -KILL -f chrome
sleep 5
npm run --silent start ~/chrome/chrome > user_agent.txt
export chrome_stable_ua=`cat user_agent.txt`
echo $chrome_stable_ua
# Edge
npm run --silent start ~/msedge/msedge > user_agent.txt
export msedge_stable_ua=`cat user_agent.txt`
echo $msedge_stable_ua
echo "firefox_stable_ua=${firefox_stable_ua}" >> $GITHUB_OUTPUT
echo "chrome_stable_ua=${chrome_stable_ua}" >> $GITHUB_OUTPUT
echo "msedge_stable_ua=${msedge_stable_ua}" >> $GITHUB_OUTPUT
outputs:
firefox_stable_ua: ${{ steps.scrape.outputs.firefox_stable_ua }}
chrome_stable_ua: ${{ steps.scrape.outputs.chrome_stable_ua }}
msedge_stable_ua: ${{ steps.scrape.outputs.msedge_stable_ua }}
output:
if: (github.event_name == 'schedule' && github.repository_owner == 'Floorp-Projects') || (github.event_name != 'schedule')
needs: [linux]
name: Generate JSONP
runs-on: ubuntu-22.04
steps:
- name: Generate
run: |
firefox_stable_ua_jsonp_text=(
'const FIREFOX_STABLE_UA = {'
" \"win\": \"$(echo "${{ needs.linux.outputs.firefox_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\","
' "linux": "${{ needs.linux.outputs.firefox_stable_ua }}",'
" \"mac\": \"$(echo "${{ needs.linux.outputs.firefox_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10.15/")\","
'};'
)
for line in "${firefox_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done
chrome_stable_ua_jsonp_text=(
'const CHROME_STABLE_UA = {'
" \"win\": \"$(echo "${{ needs.linux.outputs.chrome_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\","
' "linux": "${{ needs.linux.outputs.chrome_stable_ua }}",'
" \"mac\": \"$(echo "${{ needs.linux.outputs.chrome_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10_15_7/")\","
'};'
)
for line in "${chrome_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done
msedge_stable_ua_jsonp_text=(
'const MSEDGE_STABLE_UA = {'
" \"win\": \"$(echo "${{ needs.linux.outputs.msedge_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\","
' "linux": "${{ needs.linux.outputs.msedge_stable_ua }}",'
" \"mac\": \"$(echo "${{ needs.linux.outputs.msedge_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10_15_7/")\","
'};'
"// ESM Migration"
"window.FIREFOX_STABLE_UA = FIREFOX_STABLE_UA;"
"window.CHROME_STABLE_UA = CHROME_STABLE_UA;"
"window.MSEDGE_STABLE_UA = MSEDGE_STABLE_UA;"
)
for line in "${msedge_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ua_data
path: ~/ua_data.js
- uses: actions/checkout@v4
name: Clone 🧬
- name: Commit & Push
run: |
cp ~/ua_data.js browser/extensions/webextensions/floorp-system/shared/ua_data.js
cp ~/ua_data.js browser/base/content/browser-ua-data.mjs
if [ "$(git diff HEAD)" != "" ]; then
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "[FB] Floorp System | Update User-Agent"
git push origin
fi