|
| 1 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +# Please write our copyright if you use this file. |
| 6 | +# © 2023 Floorp Projects & Contributors |
| 7 | + |
| 8 | +name: "(U) 🧰 User-Agent Scrape" |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + schedule: |
| 13 | + - cron: "0 15 * * *" |
| 14 | + |
| 15 | +jobs: |
| 16 | + linux: |
| 17 | + if: (github.event_name == 'schedule' && github.repository_owner == 'Floorp-Projects') || (github.event_name != 'schedule') |
| 18 | + |
| 19 | + name: Linux |
| 20 | + runs-on: ubuntu-22.04 |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Clone User-Agent_Scraper 🧬 |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + repository: Floorp-Projects/User-Agent_Scraper |
| 27 | + path: User-Agent_Scraper |
| 28 | + |
| 29 | + - name: Setup 🪛 |
| 30 | + run: | |
| 31 | + cd User-Agent_Scraper |
| 32 | + sudo apt update |
| 33 | + sudo apt install nodejs npm xvfb |
| 34 | + npm install |
| 35 | +
|
| 36 | + - name: Install browsers 🌐 |
| 37 | + run: | |
| 38 | + cd ~ |
| 39 | +
|
| 40 | + # Firefox |
| 41 | + aria2c -o firefox.tar.bz2 "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64&lang=en-US" |
| 42 | + tar -xvf firefox.tar.bz2 |
| 43 | + rm firefox.tar.bz2 |
| 44 | +
|
| 45 | + # Chrome |
| 46 | + aria2c -o chrome.deb "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" |
| 47 | + mkdir chrome_tmp |
| 48 | + cd chrome_tmp |
| 49 | + ar vx ../chrome.deb |
| 50 | + tar -xvf data.tar.xz |
| 51 | + mv ./opt/google/chrome ../chrome |
| 52 | + cd ../ |
| 53 | + rm -rf chrome_tmp |
| 54 | + rm chrome.deb |
| 55 | +
|
| 56 | + # Edge |
| 57 | + aria2c -o msedge.deb "https://go.microsoft.com/fwlink?linkid=2149051&brand=M102" |
| 58 | + mkdir msedge_tmp |
| 59 | + cd msedge_tmp |
| 60 | + ar vx ../msedge.deb |
| 61 | + tar -xvf data.tar.xz |
| 62 | + mv ./opt/microsoft/msedge ../msedge |
| 63 | + cd ../ |
| 64 | + rm -rf msedge_tmp |
| 65 | + rm msedge.deb |
| 66 | +
|
| 67 | + - name: Scrape |
| 68 | + id: scrape |
| 69 | + run: | |
| 70 | + cd User-Agent_Scraper |
| 71 | +
|
| 72 | + Xvfb :2 -screen 0 1024x768x24 & |
| 73 | + export DISPLAY=:2 |
| 74 | +
|
| 75 | + # Firefox |
| 76 | + npm run --silent start ~/firefox/firefox > user_agent.txt |
| 77 | + export firefox_stable_ua=`cat user_agent.txt` |
| 78 | + echo $firefox_stable_ua |
| 79 | +
|
| 80 | + # Chrome |
| 81 | + ~/chrome/chrome & |
| 82 | + sleep 5 |
| 83 | + pkill -KILL -f chrome |
| 84 | + sleep 5 |
| 85 | + npm run --silent start ~/chrome/chrome > user_agent.txt |
| 86 | + export chrome_stable_ua=`cat user_agent.txt` |
| 87 | + echo $chrome_stable_ua |
| 88 | +
|
| 89 | + # Edge |
| 90 | + npm run --silent start ~/msedge/msedge > user_agent.txt |
| 91 | + export msedge_stable_ua=`cat user_agent.txt` |
| 92 | + echo $msedge_stable_ua |
| 93 | +
|
| 94 | + echo "firefox_stable_ua=${firefox_stable_ua}" >> $GITHUB_OUTPUT |
| 95 | + echo "chrome_stable_ua=${chrome_stable_ua}" >> $GITHUB_OUTPUT |
| 96 | + echo "msedge_stable_ua=${msedge_stable_ua}" >> $GITHUB_OUTPUT |
| 97 | +
|
| 98 | + outputs: |
| 99 | + firefox_stable_ua: ${{ steps.scrape.outputs.firefox_stable_ua }} |
| 100 | + chrome_stable_ua: ${{ steps.scrape.outputs.chrome_stable_ua }} |
| 101 | + msedge_stable_ua: ${{ steps.scrape.outputs.msedge_stable_ua }} |
| 102 | + |
| 103 | + output: |
| 104 | + if: (github.event_name == 'schedule' && github.repository_owner == 'Floorp-Projects') || (github.event_name != 'schedule') |
| 105 | + needs: [linux] |
| 106 | + |
| 107 | + name: Generate JSONP |
| 108 | + runs-on: ubuntu-22.04 |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: Generate |
| 112 | + run: | |
| 113 | + firefox_stable_ua_jsonp_text=( |
| 114 | + 'const FIREFOX_STABLE_UA = {' |
| 115 | + " \"win\": \"$(echo "${{ needs.linux.outputs.firefox_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\"," |
| 116 | + ' "linux": "${{ needs.linux.outputs.firefox_stable_ua }}",' |
| 117 | + " \"mac\": \"$(echo "${{ needs.linux.outputs.firefox_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10.15/")\"," |
| 118 | + '};' |
| 119 | + ) |
| 120 | + for line in "${firefox_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done |
| 121 | +
|
| 122 | + chrome_stable_ua_jsonp_text=( |
| 123 | + 'const CHROME_STABLE_UA = {' |
| 124 | + " \"win\": \"$(echo "${{ needs.linux.outputs.chrome_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\"," |
| 125 | + ' "linux": "${{ needs.linux.outputs.chrome_stable_ua }}",' |
| 126 | + " \"mac\": \"$(echo "${{ needs.linux.outputs.chrome_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10_15_7/")\"," |
| 127 | + '};' |
| 128 | + ) |
| 129 | + for line in "${chrome_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done |
| 130 | +
|
| 131 | + msedge_stable_ua_jsonp_text=( |
| 132 | + 'const MSEDGE_STABLE_UA = {' |
| 133 | + " \"win\": \"$(echo "${{ needs.linux.outputs.msedge_stable_ua }}" | sed "s/X11; Linux x86_64/Windows NT 10.0; Win64; x64/")\"," |
| 134 | + ' "linux": "${{ needs.linux.outputs.msedge_stable_ua }}",' |
| 135 | + " \"mac\": \"$(echo "${{ needs.linux.outputs.msedge_stable_ua }}" | sed "s/X11; Linux x86_64/Macintosh; Intel Mac OS X 10_15_7/")\"," |
| 136 | + '};' |
| 137 | + ) |
| 138 | + for line in "${msedge_stable_ua_jsonp_text[@]}" ; do echo $line >> ~/ua_data.js ; done |
| 139 | +
|
| 140 | + - name: Upload |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: ua_data |
| 144 | + path: ~/ua_data.js |
| 145 | + |
| 146 | + - uses: actions/checkout@v4 |
| 147 | + name: Clone 🧬 |
| 148 | + |
| 149 | + - name: Commit & Push |
| 150 | + run: | |
| 151 | + cp ~/ua_data.js browser/extensions/webextensions/floorp-system/shared/ua_data.js |
| 152 | + cp ~/ua_data.js browser/base/content/ua_data.js |
| 153 | + if [ "$(git diff HEAD)" != "" ]; then |
| 154 | + git config --global user.name "github-actions[bot]" |
| 155 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 156 | + git add . |
| 157 | + git commit -m "[FB] Floorp System | Update User-Agent" |
| 158 | + git push origin |
| 159 | + fi |
0 commit comments