diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml deleted file mode 100644 index 555bb5b8..00000000 --- a/.github/workflows/build-dev.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: build-dev -on: - workflow_dispatch: - push: - branches: - - dev -env: - platform: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -defaults: - run: - shell: bash - working-directory: ./ -jobs: - cook: - uses: ./.github/workflows/cook.yml - docker: - needs: cook - runs-on: ubuntu-latest - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_TOKEN }} - - uses: actions/checkout@v4 - with: - ref: dev - - name: Build Docker - run: | - docker buildx build --push --platform "${{ env.platform }}" -t ${{ secrets.DOCKER_USER }}/genpac:dev . diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..a45e9abb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: build +on: + workflow_dispatch: + inputs: + branch: + type: choice + options: + - dev + - master + default: "dev" + required: true +env: + platform: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 +defaults: + run: + shell: bash + working-directory: ./ +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_TOKEN }} + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + - uses: mikefarah/yq@master + id: get_version + with: + cmd: "yq -p toml -oy '.project.version' pyproject.toml" + - if: ${{ inputs.branch == 'master' }} + name: Build Docker From master + run: | + docker buildx build --push --platform "${{ env.platform }}" \ + -t ${{ secrets.DOCKER_USER }}/genpac \ + -t ${{ secrets.DOCKER_USER }}/genpac:${{steps.get_version.outputs.result}} \ + . + - if: ${{ inputs.branch == 'dev' }} + name: Build Docker From dev + run: | + docker buildx build --push --platform "${{ env.platform }}" \ + -t ${{ secrets.DOCKER_USER }}/genpac:dev . diff --git a/.github/workflows/cook-branch.yml b/.github/workflows/cook-branch.yml new file mode 100644 index 00000000..e62c35d6 --- /dev/null +++ b/.github/workflows/cook-branch.yml @@ -0,0 +1,42 @@ +name: cook-branch +on: + workflow_call: + inputs: + branch: + type: string + default: master + required: true +jobs: + cooking: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout Branch + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + path: work + - name: Checkout Branch cooked + uses: actions/checkout@v4 + with: + ref: cooked + path: cooked + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: fire + run: | + pip install ./work/ && \ + mkdir -p ./cooked/${{ inputs.branch }} && \ + cd ./cooked/${{ inputs.branch }} && \ + rm -rf * && \ + genpac --config=../../work/example/config.ini && \ + ls -alhR ./ + - name: commit + uses: stefanzweifel/git-auto-commit-action@v5 + with: + repository: ./cooked + commit_message: update + add_options: '-A' + push_options: '--force' diff --git a/.github/workflows/cook.yml b/.github/workflows/cook.yml index 1da4229f..08be6002 100644 --- a/.github/workflows/cook.yml +++ b/.github/workflows/cook.yml @@ -1,41 +1,16 @@ name: cook on: workflow_dispatch: - workflow_call: schedule: - cron: "0 */12 * * *" + push: jobs: - cooking: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout Branch dev - uses: actions/checkout@v4 - with: - ref: dev - path: dev - - name: Checkout Branch cooked - uses: actions/checkout@v4 - with: - ref: cooked - path: cooked - - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: fire - run: | - pip install ./dev/ && \ - mkdir ./temp && \ - DEST=./temp genpac --config=./dev/example/config.ini - - name: clean and copy - run: | - find ./cooked -maxdepth 1 -type f -name "*.*" ! -name "README.md" ! -name ".gitignore" -delete && \ - cp ./temp/* ./cooked/ - - name: commit - uses: stefanzweifel/git-auto-commit-action@v5 - with: - repository: ./cooked - commit_message: update - push_options: '--force' + master: + uses: ./.github/workflows/cook-branch.yml + with: + branch: master + dev: + uses: ./.github/workflows/cook-branch.yml + with: + branch: dev diff --git a/example/config.ini b/example/config.ini index 290f1b21..3460b1b3 100644 --- a/example/config.ini +++ b/example/config.ini @@ -1,7 +1,11 @@ ; 配置示例 ; 注: 命令中直接输入的选项优先级高于配置文件 ; 布尔型的设置仅当为true时才为真 -; 支持环境变量 如下面配置中的 DEST +; 支持环境变量(全局可用) 及 家目录 ~ (仅能在路径类配置) 如: +; pac-proxy = "SOCKS5 ${PROXY_HOST}:${PROXY_PORT}" +; output = ${HOME}/pac.js +; outtut = ~/pac.js + ; 通用配置节点 ; [job]节点使用其值作为默认值 @@ -20,7 +24,7 @@ gfwlist-url = https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.t ; gfwlist本地文件,在线地址获取失败时读取本地 ; 默认: - -gfwlist-local = ${DEST}/gfwlist-local.txt +gfwlist-local = ./gfwlist-local.txt ; 更新本地gfwlist文件 ; 当成功获取在线的gfwlist文件并且gfwlist-local存在,是否更新gfwlist-local @@ -29,7 +33,7 @@ gfwlist-update-local = true ; 保存解码后的gfwlist文件 用于开发测试 ; 默认: 空 -gfwlist-decoded-save = ${DEST}/gfwlist-decoded.txt +gfwlist-decoded-save = ./gfwlist-decoded.txt ; etag缓存加速 默认: false etag-cache = true @@ -78,27 +82,27 @@ pac-proxy = "SOCKS5 127.0.0.1:1080; DIRECT" ; pac-compress = false ; 精确匹配 默认 false ; pac-precise = false -output = ${DEST}/pac.js +output = ./pac.js ; 相同的格式可重复出现 [job:pac] ; 配置可重复出现,优先级高于[config]节点下的值 gfwlist-url = https://raw.githubusercontent.com/gfwlist/tinylist/master/tinylist.txt -gfwlist-local = ${DEST}/tinylist-local.txt +gfwlist-local = ./tinylist-local.txt gfwlist-update-local = true -gfwlist-decoded-save = ${DEST}/tinylist-decoded.txt +gfwlist-decoded-save = ./tinylist-decoded.txt pac-proxy = "SOCKS5 127.0.0.1:1080; DIRECT" -output = ${DEST}/pac-tiny.conf +output = ./pac-tiny.conf ; list: 规则列表 ; 与GFWLIST相似的base64编码 [job:list] -output = ${DEST}/list.txt +output = ./list.txt ; 明文,不进行base64编码 [job:list] list-raw = true -output = ${DEST}/list-raw.txt +output = ./list-raw.txt ; dnsmasq: DNSmasq的DNS服务器、ipset、nftset [job:dnsmasq] @@ -111,7 +115,7 @@ dnsmasq-nftset = "4#inet#GFW#GFWLIST,6#inet#GFW#GFWLIST6" ; ipset ; 详见dnsmasq手册的`--ipset`参数的说明 dnsmasq-ipset = "GFWLIST,GFWLIST6" -output = ${DEST}/dnsmasq.conf +output = ./dnsmasq.conf ; v2ray: v2ray的规则配置文件 [job:v2ray] @@ -121,72 +125,72 @@ v2ray-proxy-tag = proxy v2ray-direct-tag = direct ; 输出格式 默认: json ; v2ray-format = json -output = ${DEST}/v2ray.json +output = ./v2ray.json ; v2ray 输出yaml [job:v2ray] v2ray-proxy-tag = gfw v2ray-direct-tag = direct v2ray-format = yaml -output = ${DEST}/v2ray.yaml +output = ./v2ray.yaml ; ssacl: shadowsocks的访问控制列表 [job:ssacl] -output = ${DEST}/ss.acl +output = ./ss.acl [job:ssacl] ssacl-geocn = true -output = ${DEST}/ss-gencn.acl +output = ./ss-gencn.acl ; ip输出 [job:ip] -output = ${DEST}/ip-cn.txt +output = ./ip-cn.txt ip-cc = cn ip-family = all _order = 100 [job:ip] -output = ${DEST}/ipv4-cn.txt +output = ./ipv4-cn.txt ip-cc = cn ip-family = 4 _order = 100 [job:ip] -output = ${DEST}/ipv6-cn.txt +output = ./ipv6-cn.txt ip-cc = cn ip-family = 6 _order = 100 [job:ip] -output = ${DEST}/ipv6-us.txt +output = ./ipv6-us.txt ip-cc = us ip-family = 6 _order = 100 [job:copy] copy-from = https://github.com/gaoyifan/china-operator-ip/raw/ip-lists/china6.txt -output = ${DEST}/asn-china-ipv6.txt +output = ./asn-china-ipv6.txt [job:copy] copy-from = https://github.com/gaoyifan/china-operator-ip/raw/ip-lists/china.txt -output = ${DEST}/asn-china-ipv4.txt +output = ./asn-china-ipv4.txt [job:copy] copy-from = https://github.com/sapics/ip-location-db/raw/main/geolite2-country/geolite2-country-ipv6.csv -output = ${DEST}/geolite2-country-ipv6.csv +output = ./geolite2-country-ipv6.csv [job:copy] copy-from = https://github.com/sapics/ip-location-db/raw/main/geolite2-country/geolite2-country-ipv4.csv -output = ${DEST}/geolite2-country-ipv4.csv +output = ./geolite2-country-ipv4.csv [job:qtx] -output = ${DEST}/quantumultx.conf +output = ./quantumultx.conf [job:surge] -output = ${DEST}/surge.conf +output = ./surge.conf [job:wingy] -output = ${DEST}/wingy.yaml +output = ./wingy.yaml ; adapter选项 ; wingy-adapter-opts = ; 匹配规则使用的adapter ID