Bump theme #72
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Review app on pull request | |
on: | |
pull_request_target: | |
types: [opened, closed] | |
branches: [ main ] | |
env: | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }} | |
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }} | |
#ORGA_ID: ${{ secrets.ORGA_ID }} | |
HUGO_VERSION: ${{ secrets.HUGO_VERSION }} | |
jobs: | |
deploy: | |
if: github.event.action == 'opened' | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
pull-requests: write | |
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 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
#path: ${{ env.BRANCH_NAME }} | |
- 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 }}." | |
#- run: git fetch --unshallow | |
- name: install clever-tools | |
run: npm install -g clever-tools | |
- name: Create app and configure app | |
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 domain add clever-doc-review-${{ env.BRANCH_NAME }}.cleverapps.io | |
- name: Deploy | |
run: clever deploy | |
- 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)`; | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: message | |
}); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract app_id | |
id: extract_app_id | |
run: | | |
APP_ID=$(jq -r '.apps[0].app_id' .clever.json) | |
echo "::set-output name=app_id::$APP_ID" | |
echo "$APP_ID" > app_id_${{ env.BRANCH_NAME }}.txt | |
- name: Install and configure s3cmd | |
run: | | |
sudo apt-get install s3cmd | |
- name: Upload app_id to S3 | |
run: s3cmd --host ${{ secrets.CELLAR_ADDON_HOST }} --access_key ${{ secrets.CELLAR_ADDON_KEY_ID }} --secret_key ${{ secrets.CELLAR_ADDON_KEY_SECRET }} --host-bucket "%(bucket)s.${{ secrets.CELLAR_ADDON_HOST }}" put app_id_${{ env.BRANCH_NAME }}.txt s3://${{ secrets.CELLAR_BUCKET }}/app_id_${{ env.BRANCH_NAME }}.txt | |
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: Install and configure s3cmd | |
run: | | |
sudo apt-get install s3cmd | |
- name: Download app_id from Cellar | |
run: s3cmd --host ${{ secrets.CELLAR_ADDON_HOST }} --access_key ${{ secrets.CELLAR_ADDON_KEY_ID }} --secret_key ${{ secrets.CELLAR_ADDON_KEY_SECRET }} --host-bucket "%(bucket)s.${{ secrets.CELLAR_ADDON_HOST }}" get s3://${{ secrets.CELLAR_BUCKET }}/app_id_${{ env.BRANCH_NAME }}.txt | |
- name: Get APP_ID | |
id: get_app_id | |
run: | | |
echo "APP_ID=$(<app_id_${{ env.BRANCH_NAME }}.txt)" >> $GITHUB_ENV | |
- name: Delete app | |
run: | | |
clever link $APP_ID | |
clever delete --alias doc-review-${{ env.BRANCH_NAME }} --yes | |
- name: Delete S3 file | |
run: s3cmd --host ${{ secrets.CELLAR_ADDON_HOST }} --access_key ${{ secrets.CELLAR_ADDON_KEY_ID }} --secret_key ${{ secrets.CELLAR_ADDON_KEY_SECRET }} --host-bucket "%(bucket)s.${{ secrets.CELLAR_ADDON_HOST }}" del s3://${{ secrets.CELLAR_BUCKET }}/app_id_${{ env.BRANCH_NAME }}.txt | |
- 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 }} | |