Skip to content

Commit

Permalink
write readme with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
juliamrch committed Dec 19, 2023
1 parent 7ac4b9e commit e81afcb
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 21 deletions.
75 changes: 72 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,79 @@

# Review apps on Clever Cloud

This script does the following
This GitHub Action does the following

1. **A PR is opened:** it deploys the branch to be reviewed on Clever Cloud and posts a comment with the link
1. **A PR is opened:** it deploys the branch to be reviewed on Clever Cloud and posts a comment with the review app link
2. **The PR is updated:** it deploys last pushed commit and post a comment to confirm the redeployment
3. **The PR is closed (merged or not):** it deletes app and post a comment to confirm the job has been done.

Currently [WIP](https://docs.github.com/en/actions/creating-actions/publishing-actions-in-github-marketplace?learn=create_actions&learnProduct=actions) (but usable).
## Requirements for this Action

- A [Clever Cloud](https://www.clever-cloud.com) account
- An [organisation](https://developers.clever-cloud.com/doc/account/administrate-organization/) in Clever Cloud
- [Clever Cloud CLI](https://developers.clever-cloud.com/doc/cli/getting_started/) installed in your machine to inject your tokens

## How to use this Action

Place this script in your repository in `.github/workflows/` and modify the following values:

- `<type>` for the type of app
- `<app-name>` for the name of your app
- `region` for where you want the app to be deployed
- `<VARIABLE_NAME>` and `variable_value` for your environment variables

### Values for `--type`

- `docker`: for Docker-based applications
- `go`: for Go applications
- `gradle`: for applications launched with gradle
- `haskell`: for haskell applications
- `jar`: for applications deployed as standalone jar files
- `maven`: for applications launched with maven
- `meteor`: for Meteor applications launched with Node.js
- `node`: for Node.js applications
- `php`: for PHP applications
- `play1`: for Play1 applications
- `play2`: for Play2 applications
- `python`: for python27 and python3 applications
- `ruby`: for ruby applications
- `rust`: for rust applications
- `sbt`: for applications launched with SBT
- `static-apache`: for static (HTML only) websites
- `war`: for applications deployed as war files

### Values for `--region`

- `par` (Paris, [Clever Cloud](https://www.clever-cloud.com/infrastructure/))
- `rbx` (Roubaix, OVHcloud)
- `rbxhds` (Roubaix, HDS servers, OVHcloud)
- `scw` (Paris, [Scaleway DC5](https://www.clever-cloud.com/blog/press/2023/01/17/clever-cloud-and-scaleway-join-forces-to-unveil-a-sovereign-european-paas-offering/))
- `jed` (Jeddah, Oracle Cloud)
- `mtl` (Montreal, OVHcloud)
- `sgp` (Singapore, OVHcloud)
- `syd` (Sydney, OVHcloud)
- `wsw` (Warsaw, OVHcloud)

## Secrets you'll need

- `CLEVER_SECRET` and `CLEVER_TOKEN`: find them in your `clever-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 created

## Inject App Secrets

You can pass more secrets in your app by setting them in your GitHub repository and listing them in `env` and adding them like this : `<A_SECRET>: ${{ secrets.<A_SECRET> }}`.

Then when injecting environment variables in `Set evironment variables` step, add `clever env set <A_SECRET> ${{env.<A_SECRET>}}`.

### Example Script

```yaml
env:
...
HUGO_VERSION: ${{ secrets.HUGO_VERSION }}

...
- name: Set evironment variables
run: |
clever env set HUGO_VERSION ${{env.HUGO_VERSION}}
```
48 changes: 30 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ on:
types: [opened, closed, synchronize]
branches: [ main ]


# Inject these secrets in your GitHub repository.
# List more secrets if needed, for example: HUGO_VERSION: ${{ secrets.HUGO_VERSION }}
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
Expand All @@ -28,7 +29,6 @@ jobs:
contents: read
environment:
name: PR review apps
url: clever-doc-preprod-${{ env.BRANCH_NAME }}.cleverapps.io
steps:
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
Expand All @@ -44,26 +44,34 @@ jobs:
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: install clever-tools
run: npm install -g clever-tools
- name: Create app and configure app
- name: Create app
# Use "clever create" to deploy your app.
# Replace <type>, <app-name> and <region>
run: |
clever login --token ${{ env.CLEVER_TOKEN }} --secret ${{ env.CLEVER_SECRET }}
clever create --type static-apache doc-review-${{ env.BRANCH_NAME }} --alias doc-review-${{ env.BRANCH_NAME }} --region par --org ${{secrets.ORGA_ID}}
clever env set CC_PRE_BUILD_HOOK "./clevercloud-deploy-script.sh"
clever env set CC_WEBROOT "/public"
clever env set HUGO_ENV "production"
clever env set HUGO_VERSION ${{env.HUGO_VERSION}}
clever env set CC_PHP_VERSION "7"
clever env set CC_CGI_IMPLEMENTATION "proxy_fcgi"
clever env set CC_COMPOSER_VERSION "2"
clever create --type <type> <app-name>-${{ env.BRANCH_NAME }} --alias <app-name>-${{ env.BRANCH_NAME }} --region <region> --org ${{secrets.ORGA_ID}}
- name: Set evironment variables
# Set environment variable with "clever env set".
# For example: clever env set CC_WEBROOT "/public"
run: |
clever env set <VARIABLE_NAME> "<variable_value>"
clever domain add clever-doc-review-${{ env.BRANCH_NAME }}.cleverapps.io
- name: Set domain
# Set review app domain with "clever domain add".
# Replace <app-name>
# Inject your secrets as well, for ex:
#clever env set HUGO_VERSION ${{env.HUGO_VERSION}}
run: |
clever domain add <app-name>-${{ env.BRANCH_NAME }}.cleverapps.io
- name: Deploy
run: clever deploy
# Post your domain in PR's discussion
# Replace <app-name>
- 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://clever-doc-review-${process.env.BRANCH_NAME}.cleverapps.io)`;
const message = `Deployment has finished 👁️👄👁️ Your app is available [here](https://<app-name>-${process.env.BRANCH_NAME}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -73,6 +81,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Deploy review apps on new commits
update:
if: github.event.action == 'synchronize'
runs-on: ubuntu-latest
Expand All @@ -89,15 +98,17 @@ jobs:
- name: install clever-tools
run: npm install -g clever-tools
- name: Link and update app
# Replace <app-name>
run: |
clever link -o ${{ env.ORGA_ID }} doc-review-${{ env.BRANCH_NAME }}
clever link -o ${{ env.ORGA_ID }} <app-name>-${{ env.BRANCH_NAME }}
clever deploy
- name: Comment PR
uses: actions/github-script@v5
with:
# Replace <app-name>
script: |
const issue_number = context.payload.pull_request.number;
const message = `🚀 Your app has been updated and is available [here](https://clever-doc-review-${process.env.BRANCH_NAME}.cleverapps.io)`;
const message = `🚀 Your app has been updated and is available [here](https://<app-name>-${process.env.BRANCH_NAME}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -107,6 +118,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Delete review app when the PR is closed (merged or not)
delete:
runs-on: ubuntu-latest
permissions:
Expand All @@ -117,10 +129,10 @@ jobs:
- name: install clever-tools
run: npm install -g clever-tools
- name: Delete app
# Replace <app-name>
run: |
clever login --token ${{ env.CLEVER_TOKEN }} --secret ${{ env.CLEVER_SECRET }}
clever link -o ${{ env.ORGA_ID }} doc-review-${{ env.BRANCH_NAME }}
clever delete --alias doc-review-${{ env.BRANCH_NAME }} --yes
clever link -o ${{ env.ORGA_ID }} <app-name>-${{ env.BRANCH_NAME }}
clever delete --alias <app-name>-${{ env.BRANCH_NAME }} --yes
- name: Comment PR
uses: actions/github-script@v5
with:
Expand Down

0 comments on commit e81afcb

Please sign in to comment.