This GitHub Action does the following
- A PR is opened: it deploys the branch to be reviewed on Clever Cloud and posts a comment with the review app link
- The PR is updated: it deploys last pushed commit and post a comment to confirm the redeployment
- The PR is closed (merged or not): it deletes app and post a comment to confirm the job has been done.
The action will consider both branches on the same repository, and pull requests from forks.
- A Clever Cloud account
- An organisation in Clever Cloud
- Clever Cloud CLI installed in your machine to inject your tokens
Add the following secrets to your repository, in Settings > Secrets and variables:
CLEVER_SECRET
andCLEVER_TOKEN
: find them in yourclever-tools.json
after installing the CLI (example path on Mac:~/.config/clever-cloud/clever-tools.json
)ORGA_ID
: the organisation in which your app is createGITHUB_TOKEN
: implicit, to enable comments on the PR
For better security, we advise generating a specific CLEVER_SECRET
and CLEVER_TOKEN
for GitHub Actions. Follow these steps to do so:
- Create a new user with a new email adress on Clever Cloud
- Create a specific organization for deploying review apps
- From your terminal, run
clever logout
andclever login
right after - Log into the Console with your new user credetials
- Get the generated
CLEVER_SECRET
andCLEVER_TOKEN
and inject it into your repository secrets
Run clever login
again and connect from your main account to set your personal tokens. Your GitHub Acction user's tokens won't be revoked and will be used only from GitHub.
At job level, set the appropriate permissions to enable comments on PRs:
jobs:
deploy:
name: Deploy/redeploy review app
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: read
- In your
.github/workflow/review-app.yml
, define the event trigger for running the action:
on:
pull_request_target:
types: [opened, closed, synchronize, reopened]
branches: [ main ]
- Then, define the mandatory input:
- name: Create review app
uses: CleverCloud/clever-cloud-review-app@latest
env:
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
type: '<type-of-app>'
docker
: for Docker-based applicationselixir
: for Elixir-based applicationsgo
: for Go applicationsgradle
: for applications launched with Gradlehaskell
: for Haskell applicationsjar
: for applications deployed as standalone JAR filesmaven
: for applications launched with Mavenmeteor
: for Meteor applications launched with Node.jsnode
: for Node.js applicationsphp
: for PHP applicationsplay1
: for Play1 applicationsplay2
: for Play2 applicationspython
: for Python applicationsruby
: for Ruby applicationsrust
: for Rust applicationssbt
: for applications launched with SBTstatic-apache
: for static (HTML only) websiteswar
: for applications deployed as WAR files
To inject your app secrets and environment variables on Clever Cloud, add them to your GitHub repository in Settings > Secrets and variables, then add them with an GH_
prefix in your workflow file. Finally, enable the injection with set-env: true
:
name: Create review app
uses: CleverCloud/clever-cloud-review-app@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # To enable comments on the PR
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
GH_CC_RUN_SUCCEEDED_HOOK: ${{ secrets. CC_RUN_SUCCEEDED_HOOK }} # This environment variable will be set on Clever Cloud
with:
type: '<type-of-app>'
set-env: true # Enables the command to set en vars on Clever Cloud
You can override default options by defining region
, domain
, name
, and alias
. Default values are:
region
=par
(Paris)domain
=<repo-name>-PR-#.cleverapps.io
name
=<repo-name>-PR-#>
alias
=<repo-name>-PR-#>
par
(Paris, Clever Cloud)grahds
(Gravelines, HDS servers, OVHcloud)rbx
(Roubaix, OVHcloud)rbxhds
(Roubaix, HDS servers, OVHcloud)scw
(Paris, Scaleway DC5)mtl
(Montreal, OVHcloud)sgp
(Singapore, OVHcloud)syd
(Sydney, OVHcloud)wsw
(Warsaw, OVHcloud)