forked from CleverCloud/clever-cloud-review-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
149 lines (137 loc) · 5.31 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
name: 'Clever Cloud review app on PRs'
description: 'Deploy a review app on Clever Cloud when a PR is opened'
inputs:
type:
description: 'Which type of app to create'
required: true
name:
description: 'The name of your app'
required: true
default: ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}
alias:
description: 'The alias of your app'
required: true
default: ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}
region:
description: 'The region to deploy on'
required: true
default: 'par'
organization:
description: 'The organization to deploy on'
required: true
default: $ORGA_ID
domain:
description: 'The domain to use for the app'
required: false
default: ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io
set-env:
description: 'Set environment variables'
required: false
default: 'false'
services:
description: "add-ons to link"
required: false
default: ''
min-flavor:
description: "min flavor for the application"
required: false
default: 'nano'
environment:
description: 'Environment to run tests against'
required: true
default: ''
runs:
using: "composite"
steps:
- name: Install clever-tools
shell: bash
run: npm install -g clever-tools
- name: Install clever-tools
shell: bash
run: pip3 install --user invoke
- name: Create app
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
shell: bash
run: |
clever create --type ${{ inputs.type }} ${{ inputs.name }} --alias ${{ inputs.alias }} --region ${{ inputs.region }} --org ${{ inputs.organization }}
clever domain add ${{ inputs.domain }} --alias ${{ inputs.alias }}
clever scale --min-flavor ${{ inputs.min-flavor }} --alias ${{ inputs.alias }}
- name: Set environment variables
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' && inputs.set-env }}
shell: bash
run: |
# Remove prefix from print
for var in $(env | awk -F= '/^GH_/ { print $1 }')
do
real_var=${var#GH_}
# Inject variable in the app on Clever Cloud
clever env set $real_var "${!var}" --alias ${{ inputs.alias }}
done
- name: Link service
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' && inputs.services != '' }}
shell: bash
run: |
# loop services
for service in $(echo "${{inputs.services }}" ) ; do
clever service link-addon ${service} --alias ${{ inputs.alias }}
done
- name: Deploy app
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
shell: bash
id: deploy
run: python ${{ github.action_path }}/dist/clever-deploy.py --branch "$BRANCH" --app-alias ${{ inputs.alias }}
- name: Update app
if: ${{ github.event.action == 'synchronize' }}
shell: bash
id: update
run: |
clever link -o "$ORGA_ID" ${{ inputs.name }}
# clever deploy --force --alias ${{ inputs.alias }}
git config http.postBuffer 524288000
python ${{ github.action_path }}dist/clever-deploy.py --branch "$BRANCH" --app-alias ${{ inputs.alias }}
- name: Update app
if: ${{ github.event.action == 'closed' }}
shell: bash
id: delete
run: |
clever link -o "$ORGA_ID" ${{ inputs.name }} --alias ${{ inputs.alias }}
clever delete --alias ${{ inputs.alias }} --yes
- name: Comment PR on app creation
if: ${{ steps.deploy.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `Deployment has finished 👁️👄👁️ Your app is available [here](https://${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
- name: Comment PR on app update
if: ${{ steps.update.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `🚀 You updated your review app. Check it [here](https://${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
- name: Comment PR on deletion
if: ${{ steps.delete.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `You closed this PR and deleted the review app 👋`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});