-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
124 lines (115 loc) · 4.15 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
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'
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: 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 }}
- 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}"
done
- name: Deploy app
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
shell: bash
id: deploy
run: clever deploy
- name: Update app
if: ${{ github.event.action == 'synchronize' }}
shell: bash
id: update
run: |
clever link -o "$ORGA_ID" ${{ inputs.name }}
clever deploy --force
- name: Update app
if: ${{ github.event.action == 'closed' }}
shell: bash
id: delete
run: |
clever link -o "$ORGA_ID" ${{ inputs.name }}
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://${{ inputs.domain }})`;
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://${{ inputs.domain }})`;
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
});