DAT-16244: changes as per spacelift migration #53
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
# Terraform Action to lint and apply updated redirects | |
name: Publish Redirects to Staging for Docs | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'scripts/redirect_creation/**' | |
pull_request: | |
branches: | |
- master | |
paths: | |
- 'scripts/redirect_creation/**' | |
jobs: | |
publish-docs-staging-redirects: | |
runs-on: ubuntu-20.04 | |
env: | |
TF_VAR_env: "staging" | |
defaults: | |
run: | |
working-directory: scripts/redirect_creation | |
steps: | |
- name: Checkout branch with draft redirects | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.branch }} | |
- name: Install spacectl | |
uses: spacelift-io/setup-spacectl@main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Preview liquibase-docs-stagging Stack run | |
env: | |
SPACELIFT_API_KEY_ENDPOINT: https://liquibase.app.spacelift.io | |
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }} | |
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }} | |
run: | |
spacectl stack local-preview --id liquibase-docs-staging | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.DOCS_AWS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DOCS_AWS_KEY }} | |
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 -backend-config=$TF_VAR_env.remote.tfbackend | |
- name: Terraform Validate | |
if: ${{ github.event_name == 'pull_request' }} | |
id: validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
if: ${{ github.event_name == 'pull_request' }} | |
id: plan | |
run: | | |
terraform plan -out=plan.tmp | |
terraform show -no-color plan.tmp >${GITHUB_WORKSPACE}/plan.out | |
continue-on-error: false | |
- name: Terraform Show Plan in PR | |
uses: actions/github-script@v6 | |
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: Terraform Apply | |
if: ${{ github.event_name == 'push' }} | |
run: terraform apply -auto-approve |