/
action.yml
145 lines (138 loc) · 5.8 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
name: Clever Cloud Review App on Pull Requests
description: Deploy, sync and delete review apps on Clever Cloud for every pull request targeting the `main` branch
branding:
icon: upload-cloud
colore: red
on:
pull_request_target:
types: [opened, closed, synchronize, reopened]
branches: [ main ]
# Inject these secrets in your GitHub repository.
# List more secrets if needed, for example: HUGO_VERSION: ${{ secrets.HUGO_VERSION }}
jobs:
deploy:
if: github.event.action == 'opened'|| github.event.action == 'reopened'
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: read
environment:
name: PR review apps
steps:
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: install clever-tools
run: npm install -g clever-tools
- name: Create and deploy app
env:
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
# Use "clever create" to deploy your app.
# Replace <type> and <region>
run: |
clever create --type <type> ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }} --alias ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }} --region <region> --org "$ORGA_ID"
# Set environment variable with "clever env set".
# For example: clever env set CC_WEBROOT "/public"
# Inject your secrets as well, for ex:
#clever env set HUGO_VERSION ${{env.HUGO_VERSION}}
clever env set <VARIABLE_NAME> "<variable_value>"
# Set review app domain with "clever domain add".
clever domain add ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io
clever deploy
# Post your domain in PR's discussion
- name: Comment PR
uses: actions/github-script@v5
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
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Deploy review apps on new commits
update:
if: github.event.action == 'synchronize'
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
pull-requests: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: install clever-tools
run: npm install -g clever-tools
- name: Link and update app
env:
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
run: |
clever link -o "$ORGA_ID" ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}
clever deploy
- name: Comment PR
uses: actions/github-script@v5
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `🚀 Your app has been updated and 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
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Delete review app when the PR is closed (merged or not)
delete:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: always() && github.event_name == 'pull_request_target' && github.event.action == 'closed'
steps:
- name: install clever-tools
run: npm install -g clever-tools
- name: Delete app
run: |
clever link -o "$ORGA_ID" ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}
clever delete --alias ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }} --yes
- name: Comment PR
uses: actions/github-script@v5
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `Your review app has been deleted 👋`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}