Skip to content

Commit

Permalink
Divide steps and set conditional comments (#7)
Browse files Browse the repository at this point in the history
- refactor to divide the scripts in several steps
- use the steps context to post comments on the PR
  • Loading branch information
juliamrch authored Jul 29, 2024
1 parent e936040 commit f576571
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 42 deletions.
17 changes: 2 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Create review app
uses: CleverCloud/clever-cloud-review-app@divide-steps
uses: CleverCloud/clever-cloud-review-app@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
ORGA_ID: ${{ secrets.ORGA_ID }}
Expand All @@ -29,17 +30,3 @@ jobs:
type: 'static-apache'
set-env: true
environment: 'review'
- 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://${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
109 changes: 82 additions & 27 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ inputs:
default: ${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io
set-env:
description: 'Set environment variables'
type: boolean
required: false
default: false
default: 'false'
environment:
description: 'Environment to run tests against'
type: environment
required: true
default: ''
runs:
Expand All @@ -41,29 +39,86 @@ runs:
- name: Install clever-tools
shell: bash
run: npm install -g clever-tools
- name: Execute commands based on action

- name: Create app
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
shell: bash
run: |
clever create --type ${{ inputs.type }} ${{ inputs.name }} --alias ${{ inputs.alias }} --region ${{ inputs.region }} --org ${{ inputs.organization }}
clever domain add ${{ inputs.domain }}
- name: Set environment variables
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' && inputs.set-env }}
shell: bash
run: |
# Remove prefix from print
for var in $(env | awk -F= '/^GH_/ { print $1 }')
do
real_var=${var#GH_}
# Inject variable in the app on Clever Cloud
clever env set $real_var "${!var}"
done
- name: Deploy app
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
shell: bash
id: deploy
run: clever deploy

- name: Update app
if: ${{ github.event.action == 'synchronize' }}
shell: bash
id: update
run: |
clever link -o "$ORGA_ID" ${{ inputs.name }}
clever deploy --force
- name: Update app
if: ${{ github.event.action == 'closed' }}
shell: bash
id: delete
run: |
if [ "${{ github.event.action }}" = 'opened' ] || [ "${{ github.event.action }}" = 'reopened' ]; then
clever create --type ${{ inputs.type }} ${{ inputs.name }} --alias ${{ inputs.alias }} --region ${{ inputs.region }} --org ${{ inputs.organization }}
clever domain add ${{ inputs.domain }}
# Only select environment variables with GH_ prefix
# to exclude GitHub runner variables
if ${{ inputs.set-env }}; then
# Remove prefix from print
for var in $(env | awk -F= '/^GH_/ { print $1 }')
do
real_var=${var#GH_}
# Inject variable in the app on Clever Cloud
clever env set $real_var "${!var}"
done
clever link -o "$ORGA_ID" ${{ inputs.name }}
clever delete --alias ${{ inputs.alias }} --yes
- name: Comment PR on app creation
if: ${{ steps.deploy.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `Deployment has finished 👁️👄👁️ Your app is available [here](https://${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
clever deploy
fi
elif [ "${{ github.event.action }}" = 'synchronize' ]; then
clever link -o "$ORGA_ID" ${{ inputs.name }}
clever deploy --force
elif [ "${{ github.event.action }}" = 'closed' ]; then
clever link -o "$ORGA_ID" ${{ inputs.name }}
clever delete --alias ${{ inputs.alias }} --yes
fi
shell: bash
- name: Comment PR on app update
if: ${{ steps.update.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `🚀 You updated your review app. Check it [here](https://${{ github.event.pull_request.base.repo.name }}-PR-${{ github.event.number }}.cleverapps.io)`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
- name: Comment PR on deletion
if: ${{ steps.delete.outcome == 'success' }}
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const message = `You closed this PR and deleted the review app 👋`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});

0 comments on commit f576571

Please sign in to comment.