Generate clash rules files #418
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 clash rules files | |
on: | |
workflow_dispatch: | |
inputs: | |
PRE_RELEASE: | |
description: "Set as pre-release" | |
required: false | |
type: boolean | |
default: false | |
schedule: | |
- cron: "50 5 * * *" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Iran-clash-rules repository | |
uses: actions/checkout@v4 | |
- name: Checkout release branch from Iran-v2ray-rules repository | |
uses: actions/checkout@v4 | |
with: | |
repository: Chocolate4U/Iran-v2ray-rules | |
ref: release | |
path: source | |
- name: Set ENV variables | |
run: | | |
echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
echo "RELEASE_DATE=$(date +'%A %F %T %Z')" >> $GITHUB_ENV | |
- name: Fetch Android Packages lists | |
run: | | |
curl -sSL https://raw.githubusercontent.com/Chocolate4U/Iran-Android-Packages/main/packages.md | sed -e 's/\*\*Package name\:\*\*//g' -e '/#/d' -e '/^\s*$/d' | awk '{$1=$1};1' | sort -u > apps.txt | |
- name: Create release directory | |
run: mkdir release | |
- name: Generate Meta-geoip | |
run: | | |
gh release download -p "geo-linux-amd64" --repo metacubex/geo --output geo | |
chmod +x ./geo | |
./geo convert ip -i v2ray -o meta -f geoip.metadb ./source/geoip.dat | |
./geo convert ip -i v2ray -o meta -f geoip-lite.metadb ./source/geoip-lite.dat | |
./geo convert ip -i v2ray -o meta -f security-ip.metadb ./source/security-ip.dat | |
mv geoip.metadb geoip-lite.metadb security-ip.metadb release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get IR ASN numbers from RIPE | |
run: | | |
curl -sSLO ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-latest | |
awk -F\| '{if ($2 == "IR" && $3 == "asn" ) print $4}' < delegated-ripencc-latest > irasn.txt | |
- name: Generate clash text rules | |
run: | | |
chmod +x ./scripts/generate-clash-text-rules.sh | |
./scripts/generate-clash-text-rules.sh | |
- name: Generate clash yaml rules | |
run: | | |
chmod +x ./scripts/generate-clash-yaml-rules.sh | |
./scripts/generate-clash-yaml-rules.sh | |
- name: Generate Release Notes | |
run: | | |
echo "* Updated on ${{ env.RELEASE_DATE }}" > RELEASE_NOTES | |
- name: Push assets to release branch | |
if: ${{ !inputs.PRE_RELEASE }} | |
run: | | |
cd release || 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 | |
if: ${{ !inputs.PRE_RELEASE }} | |
run: | | |
cd release || exit 1 | |
for file in $(ls); do | |
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}" | |
done | |
- name: Release and upload assets | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: ${{ env.RELEASE_NAME }} | |
tag_name: ${{ env.TAG_NAME }} | |
body_path: RELEASE_NOTES | |
draft: false | |
prerelease: ${{ inputs.PRE_RELEASE }} | |
files: ./release/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Clean older releases | |
if: ${{ !inputs.PRE_RELEASE }} | |
uses: dev-drprasad/delete-older-releases@v0.3.3 | |
with: | |
keep_latest: 7 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |