Merge branch 'main' of https://github.com/QudsLab/tor-versions #5
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: "Daemon Version Check" | ||
| on: | ||
| workflow_run: | ||
| workflows: ["Daily Tor Expert Bundle Version Update"] | ||
| types: | ||
| - completed | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| prepare: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Parse JSON and create matrix | ||
| id: parse_json | ||
| run: | | ||
| python -c " | ||
| import json | ||
| import os | ||
| data_path = 'data/json/latest_export_versions.json' | ||
| with open(data_path, 'r') as f: | ||
| data = json.load(f) | ||
| matrix = [{'file_name': file['file_name'], 'url': file['url']} for file in data['files']] | ||
| print(f'::set-output name=matrix::{json.dumps(matrix)}') | ||
| " | ||
| process: | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| file: ${{ fromJson(needs.prepare.outputs.matrix) }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
| - name: Make deamons.sh executable | ||
| run: chmod +x deamons.sh | ||
| - name: Process binary | ||
| run: | | ||
| FILE_NAME=${{ matrix.file.file_name }} | ||
| URL=${{ matrix.file.url }} | ||
| # Download the binary | ||
| wget "$URL" -O binary_file | ||
| # Run the binary with deamons.sh to extract the daemon version | ||
| DAEMON_VERSION=$(./deamons.sh binary_file) | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Failed to extract daemon version for $FILE_NAME" | ||
| exit 1 | ||
| fi | ||
| # Update the JSON with the 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: ${{ always() }} | ||
| run: | | ||
| git add data/json/latest_export_versions.json | ||
| if git diff --staged --quiet; then | ||
| echo "No changes to commit" | ||
| else | ||
| git config --local user.email "action@github.com" | ||
| git config --local user.name "GitHub Action" | ||
| git commit -m "[Auto] Update daemon versions - $(date)" | ||
| git push | ||
| fi | ||