Generate sing-box routing rules #504
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 sing-box routing rules | |
on: | |
workflow_dispatch: | |
inputs: | |
PRE_RELEASE: | |
description: "Set as pre-release" | |
required: false | |
type: boolean | |
default: false | |
schedule: | |
- cron: "50 4 * * *" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Iran-sing-box-rules repository | |
uses: actions/checkout@v4 | |
- name: Checkout sing-geoip repository | |
uses: actions/checkout@v4 | |
with: | |
repository: Chocolate4U/sing-geoip | |
path: sing-geoip | |
- name: Checkout sing-geosite repository | |
uses: actions/checkout@v4 | |
with: | |
repository: Chocolate4U/sing-geosite | |
path: sing-geosite | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.21" | |
cache-dependency-path: sing-geoip/go.sum | |
- 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: Create release and rule-set directories | |
run: mkdir release rule-set | |
- name: Generate geoip.db file | |
run: | | |
cd sing-geoip | |
mkdir rule-set | |
go run -v . | |
mv *.db ../release | |
cp -a rule-set/. ../rule-set | |
- name: Generate geosite.db file | |
run: | | |
cd sing-geosite | |
mkdir rule-set | |
go run -v . | |
mv *.db ../release | |
cp -a rule-set/. ../rule-set | |
- name: Generate sha256sum | |
run: | | |
sha256sum release/geoip.db > release/geoip.db.sha256sum | |
sha256sum release/geoip-lite.db > release/geoip-lite.db.sha256sum | |
sha256sum release/geosite.db > release/geosite.db.sha256sum | |
sha256sum release/geosite-lite.db > release/geosite-lite.db.sha256sum | |
sha256sum release/security-ip.db > release/security-ip.db.sha256sum | |
sha256sum release/security.db > release/security.db.sha256sum | |
sha256sum release/geoip-services.db > release/geoip-services.db.sha256sum | |
- 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: Push rule sets to rule-set branch | |
if: ${{ !inputs.PRE_RELEASE }} | |
run: | | |
cd rule-set || 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 rule-set | |
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 rule-set | |
- name: Purge jsDelivr CDN cache - release | |
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: Purge jsDelivr CDN cache - rule-set | |
if: ${{ !inputs.PRE_RELEASE }} | |
run: | | |
cd rule-set || exit 1 | |
for file in $(ls); do | |
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@rule-set/${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/[email protected] | |
with: | |
keep_latest: 7 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |