forked from plotly/de-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
172 lines (166 loc) · 6.57 KB
/
action.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Dash Enterprise Deploy
description: Dash Enterprise Deploy
inputs:
DE_PASSWORD:
description: Dash Enterprise password
required: true
type: string
DE_HOST:
description: Dash Enterprise host
required: true
type: string
DE_USERNAME:
description: Dash Enterprise username
required: true
type: string
GH_ACCESS_TOKEN:
description: Github Personal Access token with permissions set to "repo".
required: true
type: string
app_name:
description: Name of the app to deploy. If not provided, the repository name will be used.
required: false
type: string
app_directory:
description: Directory of the app to deploy. If not provided, the root directory will be used.
required: false
default: ${{ github.workspace }}
group_viewers:
description: User groups to add as viewers to the app. If not provided, no groups will be added.
required: false
type: strong
group_co_owners:
description: User groups to add as co-owners to the app. If not provided, no groups will be added.
type: boolean
required: false
create_redis:
description: True to create a Redis instance for the app.
type: boolean
required: false
create_postgres:
description: True to create a Postgres instance for the app.
type: boolean
required: false
create_persistent_filesystem:
description: True to create a persistent filesystem for the app.
type: boolean
required: false
de_client_version:
description: Version of the Dash Enterprise client to install. If not provided, the latest version will be installed.
required: false
default: ''
type: string
runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install de-client
shell: bash
run: |
python -m pip install --upgrade pip
if [ -z "${{ inputs.de_client_version }}" ]; then
# If no version is specified, install the latest version
pip install de-client --extra-index-url=https://${{ inputs.DE_HOST }}/packages
else
# Install the specified version
pip install de-client==${{ inputs.de_client_version }} --extra-index-url=https://${{ inputs.DE_HOST }}/packages
fi
- name: Generate app name
id: app_name
shell: bash
run: |
# If an app name is not provided, use the repository name as the app name
if [ -z "$APP_NAME" ]; then
repository="$GITHUB_REPOSITORY"
APP_NAME=${repository#*/}
fi
# Add the PR number as a suffix for deploy previews
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
APP_NAME=$APP_NAME-$EVENT_NUMBER
fi
echo "::set-output name=app_name::$APP_NAME"
env:
APP_NAME: ${{ inputs.app_name }}
EVENT_NUMBER: ${{github.event.number}}
- name: Create app if it does not exist
shell: bash
run: |
# Create the app if it does not already exist
exists=$(de --no-keyfile apps exists -n $APP_NAME)
if [[ $exists == *"App [$APP_NAME] does not exist on [$DASH_ENTERPRISE_HOST]."* ]]; then
de --no-keyfile apps create -n $APP_NAME
fi
env:
DASH_ENTERPRISE_HOST: ${{ inputs.DE_HOST }}
DASH_ENTERPRISE_USERNAME: ${{ inputs.DE_USERNAME }}
DASH_ENTERPRISE_PASSWORD: ${{ inputs.DE_PASSWORD }}
APP_NAME: ${{ steps.app_name.outputs.app_name }}
- name: Generate details link as commit status
shell: bash
if: github.event.action != 'closed'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json"\
-H "Authorization: Bearer ${{inputs.GH_ACCESS_TOKEN}}"\
-H "X-GitHub-Api-Version: 2022-11-28"\
https://api.github.com/repos/${{ github.repository }}/statuses/${{github.event.pull_request.head.sha || github.sha}}\
-d '{"state":"success","target_url":"https://${{ inputs.DE_HOST }}/apps/${{ steps.app_name.outputs.app_name }}","description":"App manager ready!","context":"deploy/${{ steps.app_name.outputs.app_name }}"}'
- name: Create Redis
shell: bash
if: ${{ inputs.create_redis }}
run: |
exists=$(de --no-keyfile services exists -n ${{ steps.app_name.outputs.app_name }} -t redis)
if [[ $exists == "False" ]]; then
de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type redis
fi
env:
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}
- name: Create Postgres
shell: bash
if: ${{ inputs.create_postgres }}
run: |
exists=$(de --no-keyfile services exists -n ${{ steps.app_name.outputs.app_name }} -t postgres)
if [[ $exists == "False" ]]; then
de --no-keyfile services create --app-name ${{ steps.app_name.outputs.app_name }} --type postgres
fi
env:
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}
- name: Create presistent filesystem
shell: bash
if: ${{ inputs.create_persistent_filesystem }}
run: |
de --no-keyfile apps update -n ${{ steps.app_name.outputs.app_name }} --persistent-filesystem
env:
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}
- name: Inject code and deploy
shell: bash
if: github.event.action != 'closed'
run: |
de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y
de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-group-co-owner "${{ inputs.group_co_owners }}" --add-group-viewer "${{ inputs.group_viewers }}"
env:
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}
- name: Remove staging application
shell: bash
if: github.event.action == 'closed'
run: |
de --no-keyfile apps delete --name ${{ steps.app_name.outputs.app_name }}
env:
DASH_ENTERPRISE_PASSWORD: ${{inputs.DE_PASSWORD}}
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}
branding:
icon: activity
color: purple