Generate RULE-SET for Mihomo #14
This file contains 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 Mihomo | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "30 22 * * *" | |
push: | |
branches: | |
- master | |
paths-ignore: | |
- "**/README.md" | |
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 | |
echo "custom_icloud=https://raw.githubusercontent.com/Loyalsoldier/domain-list-custom/release/icloud.txt" >> $GITHUB_ENV | |
echo "custom_tld_not_cn=https://raw.githubusercontent.com/Loyalsoldier/domain-list-custom/release/tld-!cn.txt" >> $GITHUB_ENV | |
echo "custom_private=https://raw.githubusercontent.com/Loyalsoldier/domain-list-custom/release/private.txt" >> $GITHUB_ENV | |
echo "Loyalsoldier_reject=https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/reject-list.txt" >> $GITHUB_ENV | |
echo "Loyalsoldier_proxy=https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt" >> $GITHUB_ENV | |
echo "Loyalsoldier_direct=https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt" >> $GITHUB_ENV | |
echo "Loyalsoldier_gfw=https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt" >> $GITHUB_ENV | |
echo "Loyalsoldier_greatfire=https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/greatfire.txt" >> $GITHUB_ENV | |
echo "felixonmars_apple=https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf" >> $GITHUB_ENV | |
echo "felixonmars_google=https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf" >> $GITHUB_ENV | |
echo "cn_cidr=https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/cn.txt" >> $GITHUB_ENV | |
echo "lan_cidr=https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/private.txt" >> $GITHUB_ENV | |
echo "telegram_cidr=https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/telegram.txt" >> $GITHUB_ENV | |
echo "fakeip_filter=https://raw.githubusercontent.com/juewuy/ShellCrash/dev/public/fake_ip_filter.list" >> $GITHUB_ENV | |
shell: bash | |
- name: Checkout the "hidden" branch | |
uses: actions/checkout@v4 | |
with: | |
repository: Loyalsoldier/clash-rules | |
ref: hidden | |
- name: Download and unzip `mihomo core` | |
run: | | |
mihomo_version=$(curl -sSL https://api.github.com/repos/MetaCubeX/mihomo/releases | grep 'tag_name' | grep -v 'Alpha' | head -n 1 | sed -e 's/.*v/v/' -e 's/".*//') | |
curl -sSL "https://github.com/MetaCubeX/mihomo/releases/download/${mihomo_version}/mihomo-linux-amd64-${mihomo_version}.gz" | gzip -d > ./mihomo | |
chmod +x ./mihomo | |
- name: Generate icloud.txt file | |
run: | | |
echo "payload:" > icloud.yaml | |
curl -sSL ${custom_icloud} | grep -E "^(full|domain):" | awk -F ':' '{printf " - |+.%s|\n", $2}' | sed "s/|/'/g" >> icloud.yaml | |
./mihomo convert-ruleset domain yaml icloud.yaml icloud.mrs | |
./mihomo convert-ruleset domain mrs icloud.mrs icloud.list | |
- name: Generate google.txt file | |
run: | | |
echo "payload:" > google.yaml | |
curl -sSL ${felixonmars_google} | perl -ne '/^server=\/([^\/]+)\// && print " - |+.$1|\n"' | sed "s/|/'/g" >> google.yaml | |
./mihomo convert-ruleset domain yaml google.yaml google.mrs | |
./mihomo convert-ruleset domain mrs google.mrs google.list | |
- name: Generate apple.txt file | |
run: | | |
echo "payload:" > apple.yaml | |
curl -sSL ${felixonmars_apple} | perl -ne '/^server=\/([^\/]+)\// && print " - |+.$1|\n"' | sed "s/|/'/g" >> apple.yaml | |
./mihomo convert-ruleset domain yaml apple.yaml apple.mrs | |
./mihomo convert-ruleset domain mrs apple.mrs apple.list | |
- name: Generate private.txt file | |
run: | | |
echo "payload:" > private.yaml | |
curl -sSL ${custom_private} | awk -F ':' '/^full:/ {printf " - |%s|\n", $2}' | sed "s/|/'/g" >> private.yaml | |
curl -sSL ${custom_private} | awk -F ':' '/^domain:/ {printf " - |+.%s|\n", $2}' | sed "s/|/'/g" >> private.yaml | |
./mihomo convert-ruleset domain yaml private.yaml private.mrs | |
./mihomo convert-ruleset domain mrs private.mrs private.list | |
- name: Generate direct.txt file | |
run: | | |
echo "payload:" > direct.yaml | |
curl -sSL ${Loyalsoldier_direct} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(full:)([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |$2|\n"' | sed "s/|/'/g" >> direct.yaml | |
curl -sSL ${Loyalsoldier_direct} | grep -Ev "^(regexp|keyword|full):" | perl -ne '/^(domain:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$2|\n"' | sed "s/|/'/g" >> direct.yaml | |
./mihomo convert-ruleset domain yaml direct.yaml direct.mrs | |
./mihomo convert-ruleset domain mrs direct.mrs direct.list | |
- name: Generate proxy.txt file | |
run: | | |
echo "payload:" > proxy.yaml | |
curl -sSL ${Loyalsoldier_proxy} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(full:)([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |$2|\n"' | sed "s/|/'/g" >> proxy.yaml | |
curl -sSL ${Loyalsoldier_proxy} | grep -Ev "^(regexp|keyword|full):" | perl -ne '/^(domain:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$2|\n"' | sed "s/|/'/g" >> proxy.yaml | |
./mihomo convert-ruleset domain yaml proxy.yaml proxy.mrs | |
./mihomo convert-ruleset domain mrs proxy.mrs proxy.list | |
- name: Generate reject.txt file | |
run: | | |
echo "payload:" > reject.yaml | |
curl -sSL ${Loyalsoldier_reject} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(domain:|full:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$2|\n"' | sed "s/|/'/g" >> reject.yaml | |
./mihomo convert-ruleset domain yaml reject.yaml reject.mrs | |
./mihomo convert-ruleset domain mrs reject.mrs reject.list | |
- name: Generate gfw.txt file | |
run: | | |
echo "payload:" > gfw.yaml | |
curl -sSL ${Loyalsoldier_gfw} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(domain:|full:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$2|\n"' | sed "s/|/'/g" >> gfw.yaml | |
./mihomo convert-ruleset domain yaml gfw.yaml gfw.mrs | |
./mihomo convert-ruleset domain mrs gfw.mrs gfw.list | |
- name: Generate greatfire.txt file | |
run: | | |
echo "payload:" > greatfire.yaml | |
curl -sSL ${Loyalsoldier_greatfire} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(domain:|full:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$2|\n"' | sed "s/|/'/g" >> greatfire.yaml | |
./mihomo convert-ruleset domain yaml greatfire.yaml greatfire.mrs | |
./mihomo convert-ruleset domain mrs greatfire.mrs greatfire.list | |
- name: Generate tld-not-cn.txt file | |
run: | | |
echo "payload:" > tld-not-cn.yaml | |
curl -sSL "${custom_tld_not_cn}" | perl -ne '/^domain:([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print " - |+.$1|\n"' | sed "s/|/'/g" >> tld-not-cn.yaml | |
./mihomo convert-ruleset domain yaml tld-not-cn.yaml tld-not-cn.mrs | |
./mihomo convert-ruleset domain mrs tld-not-cn.mrs tld-not-cn.list | |
- name: Generate cncidr.txt file | |
run: | | |
echo "payload:" > cncidr.yaml | |
curl -sSL ${cn_cidr} | perl -ne '/(.+\/\d+)/ && print " - |$1|\n"' | sed "s/|/'/g" >> cncidr.yaml | |
./mihomo convert-ruleset ipcidr yaml cncidr.yaml cncidr.mrs | |
./mihomo convert-ruleset ipcidr mrs cncidr.mrs cncidr.list | |
- name: Generate telegramcidr.txt file | |
run: | | |
echo "payload:" > telegramcidr.yaml | |
curl -sSL ${telegram_cidr} | perl -ne '/(.+\/\d+)/ && print " - |$1|\n"' | sed "s/|/'/g" >> telegramcidr.yaml | |
./mihomo convert-ruleset ipcidr yaml telegramcidr.yaml telegramcidr.mrs | |
./mihomo convert-ruleset ipcidr mrs telegramcidr.mrs telegramcidr.list | |
- name: Generate lancidr.txt file | |
run: | | |
echo "payload:" > lancidr.yaml | |
curl -sSL ${lan_cidr} | perl -ne '/(.+\/\d+)/ && print " - |$1|\n"' | sed "s/|/'/g" >> lancidr.yaml | |
./mihomo convert-ruleset ipcidr yaml lancidr.yaml lancidr.mrs | |
./mihomo convert-ruleset ipcidr mrs lancidr.mrs lancidr.list | |
- name: Generate applications.txt file | |
run: | | |
mv applications.txt applications.yaml | |
cat applications.yaml | grep -v 'payload:' | sed -e 's/^[ \t]*- //' >> applications.list | |
- name: Generate fakeip-filter.txt file | |
run: | | |
curl -sSL "${fakeip_filter}" >> fakeip-filter.list | |
./mihomo convert-ruleset domain text fakeip-filter.list fakeip-filter.mrs | |
- name: Move files to publish directory | |
run: | | |
mkdir -p publish | |
cp *.yaml ./publish/ | |
cp *.mrs ./publish/ | |
cp *.list ./publish/ | |
- name: Release and upload assets | |
uses: softprops/action-gh-release@v2 | |
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 |