Skip to content

Merge branch 'main' of https://github.com/QudsLab/tor-versions #7

Merge branch 'main' of https://github.com/QudsLab/tor-versions

Merge branch 'main' of https://github.com/QudsLab/tor-versions #7

name: "Daemon Version Check"
description: |
For each file in the latest export versions, download and extract the binary, run it with '--version',
extract the daemon version using regex, and update the JSON with the daemon version. Each file is processed in its own job.
on:
workflow_run:
workflows: ["Daily Tor Expert Bundle Version Update"]
types:
- completed
permissions:
contents: write
jobs:
build-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
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: Generate matrix from JSON
id: set-matrix
run: |
python3 <<EOF
import json

Check failure on line 35 in .github/workflows/daemon_version_check.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/daemon_version_check.yml

Invalid workflow file

You have an error in your yaml syntax on line 35
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")
EOF
daemon-version:
needs: build-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
file: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- 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
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
# Find the tor binary (common for expert bundles)
BIN_PATH=$(find extracted -type f -name 'tor' | head -n 1)
if [ -z "$BIN_PATH" ]; then
echo "No tor binary found in $FILE_NAME"
exit 1
fi
echo "bin_path=$BIN_PATH" >> $GITHUB_OUTPUT
- name: Extract daemon version
id: daemon
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 "daemon_version=$DAEMON_VERSION" >> $GITHUB_OUTPUT
- name: Update JSON with 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
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 version for ${{ matrix.file.file_name }} - $(date)"
git push
fi