chore(preview-envs): Add preview env workflows to camunda docs repo #120
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: preview-env-deploy | |
on: | |
pull_request: | |
types: [labeled, synchronize] | |
concurrency: | |
cancel-in-progress: true | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
jobs: | |
deploy-preview: | |
if: github.event.pull_request.state != 'closed' && (contains( github.event.label.name, 'deploy') || contains( github.event.pull_request.labels.*.name, 'deploy')) | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 30 | |
name: deploy-preview-env | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Import secrets from Vault | |
id: secrets | |
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c | |
with: | |
url: ${{ secrets.VAULT_ADDR }} | |
method: approle | |
roleId: ${{ secrets.VAULT_ROLE_ID }} | |
secretId: ${{ secrets.VAULT_SECRET_ID }} | |
secrets: | | |
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_BUCKET_NAME; | |
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_GCLOUD_SA_KEY; | |
- name: Install Dependencies | |
run: npm ci | |
- name: Build Docs | |
env: | |
NODE_OPTIONS: --max_old_space_size=8192 | |
DOCS_SITE_URL: https://${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }} | |
DOCS_SITE_BASE_URL: /pr-${{ github.event.number }}/ | |
run: npm run build | |
- name: Start Deployment | |
uses: bobheadxi/deployments@v1 | |
id: deployment | |
with: | |
step: start | |
token: "${{ github.token }}" | |
env: ${{ github.event.repository.name }} | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Authenticate with Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ steps.secrets.outputs.PREVIEW_ENV_GCLOUD_SA_KEY }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Upload files to Google bucket | |
env: | |
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }} | |
run: | | |
gcloud config set pass_credentials_to_gsutil true | |
gsutil -m rsync -d -r build gs://$BUCKET_NAME/pr-${{ github.event.number }} | |
- uses: bobheadxi/deployments@v1 | |
with: | |
step: finish | |
token: "${{ github.token }}" | |
status: ${{ job.status }} | |
env: ${{ steps.deployment.outputs.env }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env_url: https://${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}/pr-${{ github.event.number }}/index.html | |
- name: Shorten commit SHA | |
run: echo "short_sha=$(echo ${{ github.sha }} | cut -c1-10)" >> $GITHUB_ENV | |
- name: Find tear-down comment | |
uses: peter-evans/find-comment@v3 | |
id: find-teardown-comment | |
with: | |
issue-number: ${{ github.event.number }} | |
body-includes: Your preview env has been torn down. | |
- name: Update tear-down comment | |
if: steps.find-teardown-comment.outputs.comment-id != '' | |
uses: peter-evans/create-or-update-comment@v4 | |
env: | |
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }} | |
with: | |
comment-id: ${{ steps.find-teardown-comment.outputs.comment-id }} | |
body: | | |
The preview environment relating to the commit ${{ env.short_sha }} has successfully been deployed. You can access it on https://${{ env.BUCKET_NAME }}/pr-${{ github.event.number }}/index.html. | |
edit-mode: replace | |
- name: Find deployment comment | |
uses: peter-evans/find-comment@v3 | |
id: find-deployment-comment | |
with: | |
issue-number: ${{ github.event.number }} | |
body-includes: The preview environment relating to the commit | |
- name: Add deployment comment | |
if: steps.find-deployment-comment.outputs.comment-id == '' && steps.find-teardown-comment.outputs.comment-id == '' | |
uses: peter-evans/create-or-update-comment@v4 | |
env: | |
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }} | |
with: | |
issue-number: ${{ github.event.number }} | |
body: | | |
The preview environment relating to the commit ${{ env.short_sha }} has successfully been deployed. You can access it on https://${{ env.BUCKET_NAME }}/pr-${{ github.event.number }}/index.html. | |
edit-mode: replace |