-
Notifications
You must be signed in to change notification settings - Fork 24
141 lines (118 loc) · 5.3 KB
/
review-app-creation.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
# See https://developer.github.com/v3/
# and https://help.github.com/en/actions
name: 🕵 Review app
# Run this pipeline when a label is added and when a push is made on this PR.
# `types: [ synchronize ]` targets a push event made on a PR.
on:
pull_request:
types: [ labeled, synchronize ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
env:
CLEVER_TOOLS_DOWNLOAD_URL: https://clever-tools.clever-cloud.com/releases/latest/clever-tools-latest_linux.tar.gz
CLEVER_TAR_FILE: clever-tools-latest_linux.tar.gz
CLEVER_CLI: clever-tools-latest_linux/clever
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
BRANCH: ${{ github.head_ref }}
jobs:
create:
runs-on: ubuntu-latest
if: github.event.action == 'labeled' && github.event.label.name == '1-recette-jetable'
steps:
- name: 📥 Checkout to the PR branch
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.head_ref }}
- name: 📥 Fetch git branches
run: git fetch --prune --unshallow
# Environment variables
- name: 🏷 Set review app name
run:
echo "REVIEW_APP_NAME=`echo \"c1-review-$BRANCH\" | sed -r 's/[-;\\/._]+/-/g'`" >> $GITHUB_ENV
- name: 🏷 Set database addon name
run:
echo "REVIEW_APP_DB_NAME=`echo $REVIEW_APP_NAME | sed -r 's/-/_/g'`" >> $GITHUB_ENV
- name: 🏷 Set deploy url
run:
# The maximum length of a domain label (part of domain name separated
# by dot) is 63 characters.
# https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.4
echo "DEPLOY_URL=`echo \"${REVIEW_APP_NAME::63}.cleverapps.io\"`" >> $GITHUB_ENV
# End of environment variables
- name: 🧫 Create a review app on Clever Cloud
run: |
curl $CLEVER_TOOLS_DOWNLOAD_URL > $CLEVER_TAR_FILE
tar -xvf $CLEVER_TAR_FILE
echo "Clever CLI version: $($CLEVER_CLI version)"
$CLEVER_CLI login --token $CLEVER_TOKEN --secret $CLEVER_SECRET
$CLEVER_CLI create $REVIEW_APP_NAME -t python --org itou_review_apps --region par --alias $REVIEW_APP_NAME
$CLEVER_CLI link $REVIEW_APP_NAME --org itou_review_apps
$CLEVER_CLI domain add $DEPLOY_URL --alias $REVIEW_APP_NAME
- name: 🗃 Create database addon
run: |
$CLEVER_CLI addon create postgresql-addon $REVIEW_APP_DB_NAME --org itou_review_apps --plan xxs_sml --yes --addon-version 15 --option direct-host-only=true
$CLEVER_CLI service link-addon $REVIEW_APP_DB_NAME
- name: 🤝 Link addons & add environment variables
run: |
$CLEVER_CLI link $REVIEW_APP_NAME --org itou_review_apps
$CLEVER_CLI env set ITOU_ENVIRONMENT "REVIEW-APP"
$CLEVER_CLI env set S3_STORAGE_BUCKET_NAME $REVIEW_APP_NAME
$CLEVER_CLI env set ITOU_FQDN $DEPLOY_URL
$CLEVER_CLI service link-addon c1-s3
$CLEVER_CLI service link-addon c1-deployment-config
$CLEVER_CLI service link-addon c1-redis
# CC_PYTHON_VERSION=3 is set by default when creating the app
# but we want to use the one from c1-deployment-config
$CLEVER_CLI env rm CC_PYTHON_VERSION
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: 🚀 Deploy to Clever Cloud
timeout-minutes: 15
run: |
$CLEVER_CLI link $REVIEW_APP_NAME --org itou_review_apps
until $CLEVER_CLI env | grep --quiet POSTGRESQL_ADDON_DIRECT_PORT
do
echo "Waiting for POSTGRESQL_ADDON_DIRECT_HOST/PORT env variables to be available"
sleep 1
done
scripts/clever-deploy --clever-cli "$CLEVER_CLI" --branch "$BRANCH" --app-alias "$REVIEW_APP_NAME"
- name: 🍻 Add link to pull request
uses: thollander/actions-comment-pull-request@v3.0.1
with:
message: |-
🥁 La recette jetable est prête ! [👉 Je veux tester cette PR !](https://${{ env.DEPLOY_URL }})
github-token: ${{ secrets.GITHUB_TOKEN }}
redeploy:
runs-on: ubuntu-latest
# A push event targets a new deployment.
if: github.event.action == 'synchronize' && contains( github.event.pull_request.labels.*.name, '1-recette-jetable')
steps:
- name: 📥 Checkout to the PR branch
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.head_ref }}
- name: 📥 Fetch git branches
run: git fetch --prune --unshallow
- name: 🏷 Set review app name
run:
echo "REVIEW_APP_NAME=`echo \"c1-review-$BRANCH\" | sed -r 's/[-;\\/._]+/-/g'`" >> $GITHUB_ENV
- name: 🤝 Find the application on Clever Cloud
run: |
curl $CLEVER_TOOLS_DOWNLOAD_URL > $CLEVER_TAR_FILE
tar -xvf $CLEVER_TAR_FILE
echo "Clever CLI version: $($CLEVER_CLI version)"
$CLEVER_CLI login --token $CLEVER_TOKEN --secret $CLEVER_SECRET
$CLEVER_CLI link $REVIEW_APP_NAME --org itou_review_apps
- name: ⏭ Skip fixtures
run:
$CLEVER_CLI env set SKIP_FIXTURES true
- name: 💂 Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: 🚀 Deploy to Clever Cloud
timeout-minutes: 15
run: scripts/clever-deploy --clever-cli "$CLEVER_CLI" --branch "$BRANCH" --app-alias "$REVIEW_APP_NAME"