Daily Tor Expert Bundle Version Update #74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Daily Tor Expert Bundle Version Update" | |
| # Schedule the workflow to run every 30 minutes | |
| on: | |
| schedule: | |
| # Runs every 12 hours | |
| - cron: '0 */12 * * *' | |
| # Allows you to manually trigger the workflow from the GitHub UI | |
| workflow_dispatch: | |
| # Grant write permissions to the workflow | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-tor-versions: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| # Use GITHUB_TOKEN with proper permissions | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Tor version scraper | |
| run: python main.py | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Commit and push changes | |
| run: | | |
| git add . | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "[Auto] Update Tor versions data - $(date)" | |
| git push | |
| fi | |
| build-matrix: | |
| needs: update-tor-versions | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: Pull latest changes | |
| run: git pull origin main | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Generate matrix from JSON | |
| id: set-matrix | |
| run: | | |
| python3 -c " | |
| import json | |
| import os | |
| with open('data/json/latest_export_versions.json') as f: | |
| data = json.load(f) | |
| files = data.get('files', []) | |
| matrix = [{'file_name': f['file_name'], 'url': f['url']} for f in files] | |
| with open(os.environ['GITHUB_OUTPUT'], 'a') as out: | |
| out.write(f'matrix={json.dumps(matrix)}\n') | |
| " | |
| daemon-version: | |
| needs: build-matrix | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| max-parallel: 1 | |
| matrix: | |
| file: ${{ fromJson(needs.build-matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: main | |
| - name: Pull latest changes | |
| run: git pull origin main | |
| - name: Install tools | |
| run: sudo apt-get update && sudo apt-get install -y jq tar gzip | |
| - name: Make deamons.sh executable | |
| run: chmod +x deamons.sh | |
| - name: Download and extract binary | |
| id: extract | |
| continue-on-error: true | |
| run: | | |
| FILE_NAME="${{ matrix.file.file_name }}" | |
| URL="${{ matrix.file.url }}" | |
| wget "$URL" -O bundle.tar.gz | |
| mkdir extracted | |
| tar -xzf bundle.tar.gz -C extracted || true | |
| BIN_PATH=$(find extracted -type f -name 'tor' -o -name 'tor.exe' | head -n 1) | |
| if [ -z "$BIN_PATH" ]; then | |
| echo "No tor binary found in $FILE_NAME" | |
| echo "bin_path=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "bin_path=$BIN_PATH" >> $GITHUB_OUTPUT | |
| - name: Extract daemon version | |
| id: daemon | |
| if: steps.extract.outputs.bin_path != '' | |
| continue-on-error: true | |
| run: | | |
| BIN_PATH="${{ steps.extract.outputs.bin_path }}" | |
| if [ ! -x "$BIN_PATH" ]; then chmod +x "$BIN_PATH"; fi | |
| DAEMON_VERSION=$(./deamons.sh "$BIN_PATH" || echo "") | |
| echo "daemon_version=$DAEMON_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update JSON with daemon version | |
| if: steps.daemon.outputs.daemon_version != '' | |
| run: | | |
| FILE_NAME="${{ matrix.file.file_name }}" | |
| DAEMON_VERSION="${{ steps.daemon.outputs.daemon_version }}" | |
| jq --arg file_name "$FILE_NAME" --arg daemon_version "$DAEMON_VERSION" '(.files[] | select(.file_name == $file_name)).daemon_version = $daemon_version' data/json/latest_export_versions.json > tmp.json && mv tmp.json data/json/latest_export_versions.json | |
| - name: Commit and push changes | |
| if: steps.daemon.outputs.daemon_version != '' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add data/json/latest_export_versions.json | |
| git diff --staged --quiet || git commit -m "[Auto] Update daemon version for ${{ matrix.file.file_name }}" | |
| git pull --rebase origin main | |
| git push origin main |