forked from zizifn/edgetunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (108 loc) · 4.78 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: heroku-deploy-stop-start-destroy
on:
workflow_dispatch:
inputs:
actions:
description: "action: deploy/stop/start/destroy"
default: "deploy"
required: true
heroku-region:
description: "us 或者 eu. 如果你的app已经创建,切换到不同的region,需要先输入 actions 为 destroy 删除app"
default: "us"
required: false
heroku-app-name:
description: "可选,如果输入,则会覆盖 Secrets 里面配置的 APP_NAME。"
default: ""
required: false
env:
description: "environment: Input the name of Environment. If left blank, the main secrets setting will be used by default."
default: ""
required: false
jobs:
jobenv:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.env }}
env: # Or as an environment variable
APP_NAME: ${{ secrets.APP_NAME }}
outputs:
actions: ${{ github.event.inputs.actions || 'deploy'}}
test111: ${{ github.event.inputs.env }} # todo
steps:
- id: isDeployHeroku # TODO check atcion doc for usage
# if: ${{ github.event.inputs.actions == 'start'}}
run: echo "test output"
output-jobenv:
runs-on: ubuntu-latest
needs: jobenv
env:
APP_NAME: ${{ secrets.APP_NAME }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
EMAIL: ${{ secrets.EMAIL }}
HEROKU_V2RAY_UUID: ${{ secrets.HEROKU_V2RAY_UUID }}
HEROKU_TUNNEL_TOKEN: ${{ secrets.HEROKU_TUNNEL_TOKEN }}
steps:
- run: |
echo "actions: ${{ github.event.inputs.actions }}"
echo "heroku-region: ${{ github.event.inputs.heroku-region }}"
echo "heroku-app-name: ${{ github.event.inputs.heroku-app-name }}"
echo "env: ${{ github.event.inputs.env }}"
- id: APP_NAME_is_empty
if: ${{ env.APP_NAME == ''}}
run: echo APP_NAME is empty
- id: HEROKU_API_KEY_is_empty
if: ${{ env.HEROKU_API_KEY == ''}}
run: echo HEROKU_API_KEY is empty
- id: EMAIL_is_empty
if: ${{ env.EMAIL == ''}}
run: echo EMAIL is empty
- id: HEROKU_V2RAY_UUID_is_empty
if: ${{ env.HEROKU_V2RAY_UUID == ''}}
run: echo HEROKU_V2RAY_UUID is empty
- id: HEROKU_TUNNEL_TOKEN_is_empty
if: ${{ env.HEROKU_TUNNEL_TOKEN == ''}}
run: echo HEROKU_TUNNEL_TOKEN is empty
# - run: echo ${{needs.jobenv.outputs.herokuAppName}} | sed 's/./& /g'
heroku-deploy:
needs: jobenv
if: ${{ needs.jobenv.outputs.actions == 'deploy' || needs.jobenv.outputs.actions == ''}}
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.env }}
env: # Or as an environment variable
APP_NAME: ${{ github.event.inputs.heroku-app-name || secrets.APP_NAME }}
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{ env.APP_NAME }} #Must be unique in Heroku
heroku_email: ${{secrets.EMAIL}}
usedocker: true
region: ${{github.event.inputs.heroku-region || 'us'}}
# docker_build_args: |
# HD_UUID
env:
# 这是为了heroku,注意前缀有个HD,这是为了告诉heroku-deploy,这些变量需要传入到 container 中。
HD_UUID: ${{ secrets.HEROKU_V2RAY_UUID }} # UUID for v2ray user, 为了安全,一定要放入 github action token 中
HD_TUNNEL_TOKEN: ${{ secrets.HEROKU_TUNNEL_TOKEN }} # token for cloudflared tunnel
NODE_ENV: production
SECRET_KEY: ${{ secrets.MY_SECRET_KEY }}
stop-start-destroy:
needs: jobenv
if: ${{ needs.jobenv.outputs.actions == 'start' || needs.jobenv.outputs.actions == 'stop' || needs.jobenv.outputs.actions == 'destroy' }}
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.env }}
env: # Or as an environment variable
APP_NAME: ${{ github.event.inputs.heroku-app-name || secrets.APP_NAME }}
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_email: ${{secrets.EMAIL}}
justlogin: true
- run: |
echo action is ${{ needs.jobenv.outputs.actions }}
if [[ ${{ needs.jobenv.outputs.actions }} == 'stop' ]]; then heroku ps:scale web=0 -a ${{env.APP_NAME}} && echo "stop"; fi
if [[ ${{ needs.jobenv.outputs.actions }} == 'start' ]]; then heroku ps:scale web=1 -a ${{env.APP_NAME}} && echo "start"; fi
heroku ps -a ${{env.APP_NAME}}
if [[ ${{ needs.jobenv.outputs.actions }} == 'destroy' ]]; then heroku apps:destroy -a ${{env.APP_NAME}} --confirm ${{env.APP_NAME}} && echo "destroy app"; fi