Generate RULE-SET for Subconverter External Config #1139
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: Generate RULE-SET for Subconverter External Config | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "30 22 * * *" | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - "**/README.md" | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set variables | |
| run: | | |
| echo "RELEASE_NAME=Released on $(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
| echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
| declare -A env_names=( | |
| ["icloud"]="https://raw.githubusercontent.com/Loyalsoldier/domain-list-custom/release/icloud.txt" | |
| ["reject"]="https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/reject-list.txt" | |
| ["proxy"]="https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt" | |
| ["direct"]="https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt" | |
| ["gfw"]="https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt" | |
| ["cn_cidr"]="https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/cn.txt" | |
| ["lan_cidr"]="https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/private.txt" | |
| ["chat"]="https://raw.githubusercontent.com/gitduk/clash-rules/main/custom/chat.txt" | |
| ["openai"]="https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Ruleset/OpenAi.list" | |
| ) | |
| for env_name in "${!env_names[@]}"; do | |
| env_value="${env_names[$env_name]}" | |
| echo "$env_name=$env_value" >> $GITHUB_ENV | |
| done | |
| shell: bash | |
| - name: Checkout the "hidden" branch | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: hidden | |
| - name: Generate txt file | |
| run: | | |
| generate_file () { | |
| if [[ $# -eq 3 ]]; then | |
| echo "# ${1}: ${2}" | |
| eval "curl -sSL ${2} | grep -Ev "^#" | $3" | |
| else | |
| eval "curl -sSL ${1} | grep -Ev "^#" | $2" | |
| fi | |
| } | |
| # icloud | |
| generate_file "iCloud ๅๅๅ่กจ" ${icloud} \ | |
| "grep -E '^full:' | awk -F ':' '{printf \"DOMAIN,%s\\n\", \$2}'" | tee icloud.txt >> direct-uniq.txt | |
| generate_file ${icloud} \ | |
| "grep -E '^domain:' | awk -F ':' '{printf \"DOMAIN-SUFFIX,%s\\n\", \$2}'" |tee -a icloud.txt >> direct-uniq.txt | |
| # reject | |
| generate_file "ๅนฟๅๅๅๅ่กจ" ${reject} \ | |
| "sed 's/^/DOMAIN-SUFFIX,/'" | tee reject.txt >> reject-uniq.txt | |
| # proxy | |
| generate_file "ไปฃ็ๅๅๅ่กจ" ${proxy} \ | |
| "grep -E '^full:' | sed 's/^full:/DOMAIN,/'" | tee proxy.txt >> proxy-uniq.txt | |
| generate_file ${proxy} \ | |
| "grep -Ev '^(full|regexp):' | sed 's/^/DOMAIN-SUFFIX,/'" | tee -a proxy.txt >> proxy-uniq.txt | |
| # direct | |
| generate_file "็ด่ฟๅๅๅ่กจ" ${direct} \ | |
| "grep -E '^full:' | sed 's/^full:/DOMAIN,/'" | tee direct.txt >> direct-uniq.txt | |
| generate_file ${direct} \ | |
| "grep -Ev '^(full|regexp):' | sed 's/^/DOMAIN-SUFFIX,/'" | tee -a direct.txt >> direct-uniq.txt | |
| # gfw | |
| generate_file "gfw ๅๅๅ่กจ" ${gfw} \ | |
| "sed 's/^/DOMAIN-SUFFIX,/'" | tee gfw.txt >> proxy-uniq.txt | |
| # cn_cidr | |
| generate_file "ไธญๅฝๅคง้ IP ๅฐๅๅ่กจ" ${cn_cidr} \ | |
| "sed 's/^/IP-CIDR,/; s/\$/,no-resolve/'" | tee cn_cidr.txt >> direct-uniq.txt | |
| # lan_cidr | |
| generate_file "ๅฑๅ็ฝ IP ๅไฟ็ IP ๅฐๅๅ่กจ" ${lan_cidr} \ | |
| "sed 's/^/IP-CIDR,/; s/\$/,no-resolve/'" | tee lan_cidr.txt >> direct-uniq.txt | |
| # chat | |
| generate_file "็ๆๅผ AI ๅๅๅ่กจ" ${chat} "cat" | tee chat.txt >> proxy-uniq.txt | |
| # openai | |
| generate_file "openai ๅๅๅ่กจ" ${openai} "cat" | tee openai.txt >> proxy-uniq.txt | |
| # sort and uniq | |
| sort -u direct-uniq.txt -o direct-uniq.txt | |
| sort -u reject-uniq.txt -o reject-uniq.txt | |
| sort -u proxy-uniq.txt -o proxy-uniq.txt | |
| - name: Move files to publish directory | |
| run: | | |
| mkdir -p publish | |
| mv *.txt ./publish/ | |
| - name: Release and upload assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: ${{ env.RELEASE_NAME }} | |
| tag_name: ${{ env.TAG_NAME }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| ./publish/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Git push assets to "release" branch | |
| run: | | |
| cd publish || exit 1 | |
| git init | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git checkout -b release | |
| git add . | |
| git commit -m "${{ env.RELEASE_NAME }}" | |
| git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
| git push -f origin release | |
| - name: Purge jsdelivr CDN | |
| run: | | |
| cd publish || exit 1 | |
| for file in $(ls); do | |
| curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}" | |
| done |