Skip to content

switched some talks #454

switched some talks

switched some talks #454

Workflow file for this run

name: Clever Cloud Review App on Pull Requests
# description: Deploy, sync and delete review apps on Clever Cloud for every pull request
on:
workflow_run:
workflows: ["Build"]
types:
- completed
pull_request_target:
types: [opened, closed, synchronize, reopened]
branches: [main]
concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
APP_NAME: "scalaio-preview"
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_NB: ${{ github.event.pull_request.number }}
BRANCH_NAME_RAW: ${{ github.head_ref || github.ref_name }}
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
jobs:
slugify:
runs-on: ubuntu-latest
outputs:
branch_slug: ${{ steps.slugify.outputs.slug }}
steps:
- id: slugify
run: echo "slug=$(echo ${{ env.PR_NB }}-${{ env.BRANCH_NAME_RAW }} | sed 's/[^a-zA-Z0-9\-]/-/g')" >> "$GITHUB_OUTPUT"
deploy:
if: github.event.action == 'opened'|| github.event.action == 'reopened'
runs-on: ubuntu-latest
needs: slugify
permissions:
issues: write
pull-requests: write
contents: read
env:
BRANCH_NAME: ${{ needs.slugify.outputs.branch_slug }}
steps:
- uses: actions/checkout@v4
with:
repository: ${{ env.PR_REPO }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: coursier/setup-action@v1.3.4
with:
jvm: adoptium:1.17.0.7
apps: sbt
- name: Install clever-tools
run: |
npm install -g clever-tools
clever login --token ${{ secrets.CLEVER_TOKEN }} --secret ${{ secrets.CLEVER_SECRET }}
- name: Create app and add domain
run: |
clever create --type node ${{ env.APP_NAME }}-${BRANCH_NAME} --alias ${{ env.APP_NAME }}-${BRANCH_NAME} --region par --org ${{secrets.ORGA_ID}}
clever scale --flavor pico
clever domain add ${{ env.APP_NAME }}-${BRANCH_NAME}.cleverapps.io
- name: Compile
run: |
sbt "compile; fullLinkJS"
npm install
npx sass src/main/resources/css/main.scss src/main/resources/css/output.css
- name: Build website
run: |
npm run build
mv dist dist-prod
cp robots.txt dist-prod/robots.txt
- name: Commit changes
run: |
git config --global user.email ${{ secrets.GIT_EMAIL }}
git config --global user.name ${{ secrets.GIT_NAME }}
git add .
git commit -m "chore: forward changed to preprod"
- name: Deploy
run: clever deploy
# Post your domain in PR's discussion
- name: Comment PR
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `Deployment has finished πŸ‘οΈπŸ‘„πŸ‘οΈ Your app is available [here](https://${{ env.APP_NAME }}-${process.env.BRANCH_NAME}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
# Deploy review apps on new commits
update:
if: github.event.action == 'synchronize'
runs-on: ubuntu-latest
needs: slugify
permissions:
issues: write
contents: read
pull-requests: write
env:
BRANCH_NAME: ${{ needs.slugify.outputs.branch_slug }}
steps:
- uses: actions/checkout@v4
with:
repository: ${{ env.PR_REPO }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: coursier/setup-action@v1.3.4
with:
jvm: adoptium:1.17.0.7
apps: sbt
- name: Compile
run: |
sbt "compile; fullLinkJS"
npm install
npx sass src/main/resources/css/main.scss src/main/resources/css/output.css
- name: Build website
run: |
npm run build
mv dist dist-prod
cp robots.txt dist-prod/robots.txt
- name: Commit changes
run: |
git config --global user.email ${{ secrets.GIT_EMAIL }}
git config --global user.name ${{ secrets.GIT_NAME }}
git add .
git commit -m "chore: forward changed to preprod"
- name: Deploy to Clever Cloud
run: |
npm install -g clever-tools
clever login --token ${{ secrets.CLEVER_TOKEN }} --secret ${{ secrets.CLEVER_SECRET }}
clever link -o ${{ env.ORGA_ID }} ${{ env.APP_NAME }}-${BRANCH_NAME}
clever deploy --force
- name: Comment PR
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `πŸš€ Your app has been updated and is available [here](https://${{ env.APP_NAME }}-${process.env.BRANCH_NAME}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
# Delete review app when the PR is closed (merged or not)
delete:
runs-on: ubuntu-latest
needs: slugify
permissions:
issues: write
pull-requests: write
if: always() && github.event_name == 'pull_request_target' && github.event.action == 'closed'
env:
BRANCH_NAME: ${{ needs.slugify.outputs.branch_slug }}
steps:
- name: Delete app
run: |
npm install -g clever-tools
clever login --token ${{ secrets.CLEVER_TOKEN }} --secret ${{ secrets.CLEVER_SECRET }}
clever link -o ${{ env.ORGA_ID }} ${{ env.APP_NAME }}-${BRANCH_NAME}
clever delete --alias ${{ env.APP_NAME }}-${BRANCH_NAME} --yes
- name: Comment PR
uses: actions/github-script@v7
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 }}