.github/workflows/main.yml #295
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: ZeroTier+V2ray | |
# 注意事项: | |
# 1. 应当指定每个任务的持续时间和开始时间,例如设置 schedule.cron 属性让任务每个小时自动运行一次,每次运行时间 60分钟 (由 "Start V2ray" 中的 timeout-minutes 指定) | |
# 2. 应当确保 IP_ASSIGNMENT | |
on: | |
workflow_dispatch: | |
# 取消注释以启用定时任务(默认每小时),具体生成可参考 https://www.freeformatter.com/cron-expression-generator-quartz.html | |
schedule: | |
- cron: '0 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install ZeroTier | |
run: | | |
curl -s https://install.zerotier.com | sudo bash | |
sudo zerotier-cli info | |
- name: Start ZeroTier | |
env: | |
# 如果修改了 IP_ASSIGNMENT,那么对于 clash 配置的服务器地址也应当同步。 | |
IP_ASSIGNMENT: 10.144.0.10 | |
ZEROTIER_NETWORK_ID: ${{ secrets.ZEROTIER_NETWORK_ID }} | |
ZEROTIER_TOKEN: ${{ secrets.ZEROTIER_TOKEN }} | |
run: | | |
memberId=$(sudo zerotier-cli info | awk -F" " '{print $3}') | |
echo "Member Id is ${memberId}" | |
curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${ZEROTIER_TOKEN}" -d "{\"config\": { \"ipAssignments\": [ \"$IP_ASSIGNMENT\" ] }}" https://api.zerotier.com/api/v1/network/${ZEROTIER_NETWORK_ID}/member/${memberId} | |
sudo zerotier-cli join ${ZEROTIER_NETWORK_ID} | |
- name: Start V2ray | |
timeout-minutes: 60 | |
env: | |
V2RAY_CONFIG_JSON: ${{ secrets.V2RAY_CONFIG_JSON }} | |
run: | | |
echo $V2RAY_CONFIG_JSON > v2ray-runtime-config.json | |
docker run --network=host --name v2ray -v ${{ github.workspace }}/v2ray-runtime-config.json:/etc/v2fly/config.json -p 10086:10086 v2fly/v2fly-core run -c /etc/v2fly/config.json | |
- name: Immediately Cleanup | |
if: always() | |
env: | |
ZEROTIER_NETWORK_ID: ${{ secrets.ZEROTIER_NETWORK_ID }} | |
ZEROTIER_TOKEN: ${{ secrets.ZEROTIER_TOKEN }} | |
# https://docs.zerotier.com/central/v1/#operation/deleteNetworkMember | |
run: | | |
memberId=$(sudo zerotier-cli info | awk -F" " '{print $3}') | |
curl -X DELETE -H "Authorization: token ${ZEROTIER_TOKEN}" https://api.zerotier.com/api/v1/network/${ZEROTIER_NETWORK_ID}/member/${memberId} |