Skip to content

Publish Redirects to Staging for EnterpriseDocs #264

Publish Redirects to Staging for EnterpriseDocs

Publish Redirects to Staging for EnterpriseDocs #264

# Terraform Action to lint and apply updated redirects
name: Publish Redirects to Staging for EnterpriseDocs
on:
workflow_run:
workflows:
- "Publish Redirects to Staging for Docs"
types:
- completed
paths:
- 'scripts/redirect_creation/**'
jobs:
publish-enterprise-staging-redirects:
runs-on: ubuntu-20.04
permissions: write-all
env:
TF_VAR_env: "staging"
SPACELIFT_API_KEY_ENDPOINT: ${{ secrets.SPACELIFT_API_KEY_ENDPOINT }}
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
defaults:
run:
working-directory: scripts/redirect_creation
steps:
- name: Checkout branch with draft redirects
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Install spacectl
uses: spacelift-io/setup-spacectl@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ADMIN_GITHUB_OIDC_ROLE_ARN_DOCS }}
aws-region: us-east-1
- name: Terraform Format
if: ${{ github.event_name == 'pull_request' }}
id: fmt
run: terraform fmt
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Validate
if: ${{ github.event_name == 'pull_request' }}
id: validate
run: terraform validate -no-color
- name: Preview infrastructure
run: |
spacectl stack local-preview --id liquibase-docs-staging > ${GITHUB_WORKSPACE}/plan.out
cat ${GITHUB_WORKSPACE}/plan.out
- name: Terraform Show Plan in PR
uses: actions/github-script@v7
continue-on-error: true
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
const run_link = '<a href="' + run_url + '">Actions</a>.'
const fs = require('fs')
const plan_file = fs.readFileSync('plan.out', 'utf8')
const plan = plan_file.length > 65000 ? plan_file.toString().substring(0, 65000) + " ..." : plan_file
const truncated_message = plan_file.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${plan}
\`\`\`
</details>
${truncated_message}
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ github.workspace }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Deploy infrastructure
if: ${{ github.event_name == 'push' }}
run: |
spacectl stack set-current-commit --id liquibase-docs-staging --sha ${{ github.sha }}
spacectl stack deploy --id liquibase-docs-staging --auto-confirm