Skip to content

chore: adding workflow for updating geosite-cn list automatically - #13

Open
WendelHime wants to merge 1 commit into
mainfrom
feat/adding-workflow-for-auto-updating-geosite-cn
Open

chore: adding workflow for updating geosite-cn list automatically#13
WendelHime wants to merge 1 commit into
mainfrom
feat/adding-workflow-for-auto-updating-geosite-cn

Conversation

@WendelHime

@WendelHime WendelHime commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Chores
    • Added automated scheduled and on-demand updates for the China website rule set.
    • Added validation to detect unsupported upstream rules and unexpectedly small updates.
    • Automatically regenerates the published rule files and commits changes when updates are available.
    • Added workflow summaries showing rule counts, update status, and commit details.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a scheduled and manually triggered GitHub Actions workflow that downloads and validates upstream geosite-cn rules, generates CSV and SRS artifacts, commits changes, and reports the update summary.

Changes

geosite-cn update automation

Layer / File(s) Summary
Workflow triggers and runner setup
.github/workflows/update_geosite_cn.yml
Defines scheduled and manual execution, concurrency, pinned environment values, repository checkout, and sing-box installation.
Upstream rule conversion and validation
.github/workflows/update_geosite_cn.yml
Downloads and decompiles cn.srs, validates supported fields, filters domain suffixes into CSV, and enforces a minimum rule count.
SRS generation and update reporting
.github/workflows/update_geosite_cn.yml
Runs csv_to_srs, commits the generated CSV and SRS files, and records rule count, change status, and commit hash in the step summary.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant Upstream
  participant SingBox
  participant CsvToSrs
  participant GitRepository
  GitHubActions->>Upstream: download cn.srs
  GitHubActions->>SingBox: decompile cn.srs to cn.json
  SingBox-->>GitHubActions: return decompiled rules
  GitHubActions->>GitHubActions: validate and write geosite-cn.csv
  GitHubActions->>CsvToSrs: generate geosite-cn.srs
  CsvToSrs-->>GitHubActions: return generated artifact
  GitHubActions->>GitRepository: commit CSV and SRS changes
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an automated workflow to update the geosite-cn list.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/adding-workflow-for-auto-updating-geosite-cn

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/update_geosite_cn.yml:
- Around line 86-87: Update the csv_to_srs generator entrypoint in
cmd/csv_to_srs/main.go so filepath.Walk and SRS parse/write errors are
propagated to main and terminate with a nonzero exit status. Ensure the
“Generating SRS files” workflow step cannot succeed or commit changes when
generation fails.
- Line 89: Update the stefanzweifel/git-auto-commit-action reference in the
workflow to a full immutable commit SHA instead of the mutable v7 tag, selecting
the SHA for the intended action version and preserving the existing workflow
behavior.
- Around line 38-42: Update the workflow step before extracting sing-box.tar.gz
to validate the downloaded archive using the official release checksum manifest
or signature, and fail the job when verification fails. Keep tar extraction,
installation, and sing-box version execution after successful verification,
using the existing SING_BOX_VERSION and archive values to select the matching
trusted artifact.
- Line 31: Update the workflow’s actions/checkout@v5 step to set
persist-credentials to false, and remove the contents: write permission unless
it is explicitly required by git-auto-commit-action. Keep the commit step
functional while ensuring later untrusted download and execution steps cannot
access the repository write token.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5cb4f37a-10b9-46b1-892e-34bafa09fbcb

📥 Commits

Reviewing files that changed from the base of the PR and between 681577d and 64992ca.

📒 Files selected for processing (1)
  • .github/workflows/update_geosite_cn.yml

runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow files =="
git ls-files .github/workflows || true

echo "== target workflow excerpt =="
if [ -f ".github/workflows/update_geosite_cn.yml" ]; then
  nl -ba .github/workflows/update_geosite_cn.yml | sed -n '1,140p'
fi

echo "== all uses in target workflow =="
rg -n "uses:|pulls token|GITHUB_TOKEN|env:|permissions:|git push|curl|sing-box|go run" .github/workflows/update_geosite_cn.yml || true

Repository: getlantern/rulesets

Length of output: 329


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target workflow excerpt =="
if [ -f ".github/workflows/update_geosite_cn.yml" ]; then
  awk '{printf "%4d\t%s\n", NR, $0}' .github/workflows/update_geosite_cn.yml | sed -n '1,160p'
fi

echo "== relevant usages =="
awk '{printf "%4d\t%s\n", NR, $0}' .github/workflows/update_geosite_cn.yml | grep -nEi "uses:|github-token|pulls token|github_token|GITHUB_TOKEN|permissions:|persist-credentials|git push|curl|sing-box|go run|commit" || true

Repository: getlantern/rulesets

Length of output: 5608


🌐 Web query:

actions/checkout persist-credentials default true saves GITHUB_TOKEN .git/config

💡 Result:

As of version 6.0.0 of actions/checkout, the behavior of the persist-credentials input has been updated to improve credential security [1][2][3]. While previous versions (v2 through v5) stored the GITHUB_TOKEN directly within the local.git/config file, v6 and later versions store these credentials in a separate file under the $RUNNER_TEMP directory [4][1][3]. The action then uses Git configuration (such as include.path) to reference this temporary file [1]. Despite this change in storage location, the overall functionality remains the same: when persist-credentials is set to true (which is the default), the GITHUB_TOKEN is configured to allow subsequent steps in the workflow to perform authenticated Git commands [4][5][3]. The token is still automatically removed during post-job cleanup [4][5]. If you wish to opt out of this behavior, you can set persist-credentials to false in your workflow file: - uses: actions/checkout@v6 with: persist-credentials: false Setting this to false prevents the action from configuring Git with the GITHUB_TOKEN, which is often recommended for security purposes to follow the principle of least privilege [6][7].

Citations:


🌐 Web query:

stefanzweifel git-auto-commit-action v7 authentication github-token input

💡 Result:

In the stefanzweifel/git-auto-commit-action (version 7), authentication is handled automatically by the GITHUB_TOKEN provided by the GitHub Actions runner, and there is no direct github-token input parameter for the action itself [1][2]. Key details regarding authentication and configuration: 1. Authentication Mechanism: The action uses the GITHUB_TOKEN to authenticate with GitHub's APIs to push commits [2]. To enable this, you must set the permissions of your workflow job to allow write access to contents [1]: permissions: contents: write 2. Personal Access Tokens (PATs): If you need to use a Personal Access Token instead of the default GITHUB_TOKEN (e.g., to trigger other workflows or bypass specific restrictions), you should pass the token to the actions/checkout step at the beginning of your job, rather than to the git-auto-commit-action itself [1]. - Ensure persist-credentials is set to true in the actions/checkout step [1]. - Example configuration: - uses: actions/checkout@v5 with: token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} 3. Repository Input: Regarding your query about the repository input, the action does include a repository input parameter [3][4]. This is an optional string that defines the relative file path (under $GITHUB_WORKSPACE) to the git repository you want to target [3]. It defaults to the current directory (.), meaning the action operates in the root of the workspace by default [3]. In summary, do not look for a github-token input on the git-auto-commit-action; authentication is managed via the environment's credentials, which are typically established during the preceding checkout step [1].

Citations:


🌐 Web query:

actions/checkout v5 persist-credentials default true configures local git remote

💡 Result:

In actions/checkout v5, the persist-credentials input defaults to true [1][2][3]. When enabled, this setting configures the repository to use the provided GitHub Actions token (or SSH key) for subsequent Git operations during the workflow [2][4][5]. In v5, this is achieved by writing the credentials directly into the local Git configuration of the checked-out repository [2][6]. The token is subsequently removed during the post-job cleanup step [2][5]. It is important to note that this behavior changed in v6 [7][6]. In actions/checkout v6 and later, persist-credentials still defaults to true, but the mechanism for storing credentials was updated to improve security; instead of writing directly to the local.git/config, credentials are now stored in a separate file within $RUNNER_TEMP and accessed using Git's includeIf mechanism [7][8][6].

Citations:


Keep the write token out of untrusted workspace steps.

In this workflow, actions/checkout@v5 persisted the repository write token for git operations until post-job cleanup, and later steps (curl, sing-box downloads/execution, and go run) execute before git-auto-commit-action. Set persist-credentials: false on checkout and remove unnecessary contents: write permission unless the commit step needs it.

🧰 Tools
🪛 zizmor (1.28.0)

[warning] 31-31: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/update_geosite_cn.yml at line 31, Update the workflow’s
actions/checkout@v5 step to set persist-credentials to false, and remove the
contents: write permission unless it is explicitly required by
git-auto-commit-action. Keep the commit step functional while ensuring later
untrusted download and execution steps cannot access the repository write token.

Source: Linters/SAST tools

Comment on lines +38 to +42
curl -fsSL -o sing-box.tar.gz \
"https://github.com/SagerNet/sing-box/releases/download/v${SING_BOX_VERSION}/${archive}.tar.gz"
tar -xzf sing-box.tar.gz
sudo install "${archive}/sing-box" /usr/local/bin/sing-box
sing-box version

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Git files of interest:"
git ls-files | rg '(^|/)\.github/workflows/update_geosite_cn\.yml$|sing-box|SING_BOX_VERSION|checksum|sha|signature' || true

echo
echo "Workflow excerpt:"
if [ -f .github/workflows/update_geosite_cn.yml ]; then
  nl -ba .github/workflows/update_geosite_cn.yml | sed -n '1,120p'
fi

echo
echo "Search for checksum/signature/checksum-related terms in workflows:"
rg -n "sha(?:256|512)?|checksum|sign|gpg|cosign|verify|SING_BOX_VERSION|sing-box" .github/workflows || true

Repository: getlantern/rulesets

Length of output: 280


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Workflow excerpt:"
if [ -f .github/workflows/update_geosite_cn.yml ]; then
  awk '{printf "%6d\t%s\n", NR, $0}' .github/workflows/update_geosite_cn.yml | sed -n '1,120p'
fi

echo
echo "Search for sing-box, SING_BOX_VERSION, checksum/signature in workflows:"
rg -n "sha(256|512)?|checksum|sign|gpg|cosign|verify|SING_BOX_VERSION|sing-box" .github/workflows || true

echo
echo "Relevant git status summary:"
git status --short .github/workflows/update_geosite_cn.yml || true

Repository: getlantern/rulesets

Length of output: 5523


🌐 Web query:

SagerNet sing-box GitHub releases checksums signature v1.12.12

💡 Result:

The sing-box project, managed by SagerNet, generally does not provide explicit, publicly documented standalone checksum (.sha256) or GPG signature (.sig) files for individual release assets directly on their GitHub releases page [1][2]. Verification of sing-box releases is typically handled through the following mechanisms: 1. Package Manager Signatures: For Linux distributions using RPM or DEB packages, signatures are managed by the release process (e.g., via GoReleaser) [3]. Users have reported that signature verification can sometimes fail if the GPG key is not correctly configured or if the key ID mismatch occurs [4]. The official GPG key used for repository verification is hosted at https://sing-box.app/gpg.key [4]. 2. Installer Manifests: For Windows, the Microsoft Winget package manager maintains manifests that include the SHA256 checksums for specific release versions [5]. These manifests serve as an authoritative source for verifying the integrity of the official Windows binaries [5]. 3. Release Automation: Releases are typically built via GitHub Actions, and integrity is managed within the ecosystem of the build pipeline [2][6]. If you are attempting to verify a specific file manually, it is recommended to compare its hash against the values documented in the relevant Winget manifest [5] or check the project's official communication channels if you suspect file corruption, as the project has previously addressed issues where release assets were incorrectly triggered and required re-uploading [7]. There is no standard, per-file detached signature provided for general users on the GitHub releases page for version 1.12.12 [1][2].

Citations:


Validate the sing-box artifact before executing it.

This workflow runs with contents: write and installs a release asset from an untrusted download path. Compare the downloaded archive against a trusted checksum manifest or verify an official signature before tar -xzf sing-box.tar.gz.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/update_geosite_cn.yml around lines 38 - 42, Update the
workflow step before extracting sing-box.tar.gz to validate the downloaded
archive using the official release checksum manifest or signature, and fail the
job when verification fails. Keep tar extraction, installation, and sing-box
version execution after successful verification, using the existing
SING_BOX_VERSION and archive values to select the matching trusted artifact.

Comment on lines +86 to +87
- name: Generating SRS files
run: go run ./cmd/csv_to_srs -input_dir ./csv -output_dir ./srs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Fail the job when SRS generation fails.

cmd/csv_to_srs/main.go:20-66 logs filepath.Walk errors without exiting nonzero. Consequently, this step can succeed after a parse/write failure, allowing the commit step to push a new CSV alongside a stale or missing srs/geosite-cn.srs. Make the generator return a nonzero exit status on error before committing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/update_geosite_cn.yml around lines 86 - 87, Update the
csv_to_srs generator entrypoint in cmd/csv_to_srs/main.go so filepath.Walk and
SRS parse/write errors are propagated to main and terminate with a nonzero exit
status. Ensure the “Generating SRS files” workflow step cannot succeed or commit
changes when generation fails.

- name: Generating SRS files
run: go run ./cmd/csv_to_srs -input_dir ./csv -output_dir ./srs

- uses: stefanzweifel/git-auto-commit-action@v7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Workflow snippets:"
if [ -f .github/workflows/update_geosite_cn.yml ]; then
  nl -ba .github/workflows/update_geosite_cn.yml | sed -n '70,105p'
else
  echo ".github/workflows/update_geosite_cn.yml not found"
fi

echo
echo "Occurrences of git-auto-commit-action:"
rg -n "git-auto-commit-action" .github/workflows || true

echo
echo "Other action pins in this workflow:"
rg -n "uses:\s*[^#]+@" .github/workflows/update_geosite_cn.yml || true

Repository: getlantern/rulesets

Length of output: 216


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Workflow snippets:"
if [ -f .github/workflows/update_geosite_cn.yml ]; then
  head -n 110 .github/workflows/update_geosite_cn.yml | awk '{printf "%d\t%s\n", NR, $0}'
else
  echo ".github/workflows/update_geosite_cn.yml not found"
fi

echo
echo "Occurrences of git-auto-commit-action:"
grep -n "git-auto-commit-action" .github/workflows/update_geosite_cn.yml || true

echo
echo "Other action pins in this workflow:"
grep -nE "uses:\s*[^#]+@" .github/workflows/update_geosite_cn.yml || true

echo
echo "Permissions declarations:"
grep -nE "permissions:|contents:|issues:|pull-requests:|checks:" .github/workflows/update_geosite_cn.yml || true

Repository: getlantern/rulesets

Length of output: 4383


Pin the third-party commit action to an immutable SHA.

This workflow grants contents: write, and stefanzweifel/git-auto-commit-action@v7 is a mutable tag. Use the full commit SHA for the selected action ref and update it through a controlled dependency-update process.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/update_geosite_cn.yml at line 89, Update the
stefanzweifel/git-auto-commit-action reference in the workflow to a full
immutable commit SHA instead of the mutable v7 tag, selecting the SHA for the
intended action version and preserving the existing workflow behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant