From 4eb86aba194659d471fdacd8a4c036284680aff7 Mon Sep 17 00:00:00 2001 From: "thomas g. lopes" Date: Mon, 9 Mar 2026 15:30:02 +0000 Subject: [PATCH] helium auto update --- .gitea/workflows/helium-update.yml | 116 +++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .gitea/workflows/helium-update.yml diff --git a/.gitea/workflows/helium-update.yml b/.gitea/workflows/helium-update.yml new file mode 100644 index 0000000..19bd54b --- /dev/null +++ b/.gitea/workflows/helium-update.yml @@ -0,0 +1,116 @@ +name: helium update + +on: + schedule: + - cron: "0 6 * * *" + workflow_dispatch: + +jobs: + update-helium: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: check latest helium release and update file + id: update + shell: bash + run: | + set -euo pipefail + + FILE="modules/pkgs/helium.nix" + + current_version=$(python - <<'PY' + import re + p='modules/pkgs/helium.nix' + s=open(p).read() + m=re.search(r'version\s*=\s*"([^"]+)";', s) + print(m.group(1) if m else "") + PY + ) + + latest_version=$(python - <<'PY' + import json, urllib.request + url='https://api.github.com/repos/imputnet/helium-linux/releases/latest' + with urllib.request.urlopen(url) as r: + data=json.load(r) + tag=data.get('tag_name','').lstrip('v') + print(tag) + PY + ) + + echo "current=$current_version" + echo "latest=$latest_version" + + if [ -z "$latest_version" ] || [ "$latest_version" = "$current_version" ]; then + echo "updated=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + url="https://github.com/imputnet/helium-linux/releases/download/${latest_version}/helium-${latest_version}-x86_64.AppImage" + new_hash=$(nix store prefetch-file --json "$url" | python -c 'import json,sys; print(json.load(sys.stdin)["hash"])') + + python - <> "$GITHUB_OUTPUT" + echo "version=$latest_version" >> "$GITHUB_OUTPUT" + + - name: create branch and commit + if: steps.update.outputs.updated == 'true' + shell: bash + run: | + set -euo pipefail + branch="bot/helium-${{ steps.update.outputs.version }}" + + git config user.name "gitea actions" + git config user.email "actions@localhost" + + git checkout -B "$branch" + git add modules/pkgs/helium.nix + git commit -m "update helium to ${{ steps.update.outputs.version }}" + git push --force origin "$branch" + + - name: open pull request + if: steps.update.outputs.updated == 'true' + env: + GITEA_TOKEN: ${{ gitea.token }} + shell: bash + run: | + set -euo pipefail + + api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}" + branch="bot/helium-${{ steps.update.outputs.version }}" + + # Skip if PR for this branch already exists + existing=$(curl -fsS \ + -H "Authorization: token ${GITEA_TOKEN}" \ + "${api}/pulls?state=open" \ + | python -c 'import json,sys; d=json.load(sys.stdin); b="'"$branch"'"; print(next((str(pr["number"]) for pr in d if pr.get("head",{}).get("ref")==b), ""))') + + if [ -n "$existing" ]; then + echo "PR already exists: #$existing" + exit 0 + fi + + curl -fsS -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + "${api}/pulls" \ + -d "$(cat <