Build and Push #2
Workflow file for this run
This file contains hidden or 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: "Build and Push" | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- closed | |
# push: | |
# branches: | |
# - main | |
jobs: | |
post-build-option-instructions: | |
name: "Build Option Instructions" | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'pull_request'}} | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Post Instructions | |
id: post-build-options | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const output = ` | |
### To Build & Push Docker Containers: Set Build Group Label | |
Please set one of the following labels on this PR to define the Docker build group: | |
- **Docker-all**: Build all Docker images | |
- **Docker-lambda**: Build only Lambda-related Docker images | |
- **Docker-ECS**: Build only the ECS-related Docker images | |
By default no docker containers will be built if none of these labels are attached. | |
### To set pdal_runner Repo branch: Set PDAL Repo branch Label | |
Please set one of the following labels on this PR to define the Docker build group: | |
- **PDAL-dev**: Build with PDAL from branch dev | |
- **PDAL-[branch-name]**: Build with PDAL from branch [branch-name] | |
By default the PDAL branch used is 'main' | |
### To Apply Terraform: Set Terraform Apply Label | |
Please set one of the following labels on this PR to define the Docker build group: | |
- **Terraform-apply**: Build all Docker images | |
By default no terraform apply action will be taken if this label is not attached. | |
You can apply the label in the right-hand sidebar of this PR. | |
`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output, | |
}); | |
terraform: | |
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} | |
name: "Terraform" | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }} | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
run: terraform init | |
- name: Terraform Validate | |
id: validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
id: plan | |
if: github.event_name == 'pull_request' | |
run: | | |
echo "Selected Build Option: ${{ needs.fetch-build-option.outputs.build_option }}" | |
terraform plan -no-color -input=false > plan_output.txt | |
continue-on-error: true | |
- name: Update Pull Request | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const planOutput = require('fs').readFileSync('plan_output.txt', 'utf8'); | |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` | |
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` | |
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` | |
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`terraform | |
${planOutput} | |
\`\`\` | |
</details> | |
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output, | |
}); | |
- name: Terraform Plan Status | |
if: steps.plan.outcome == 'failure' | |
run: exit 1 | |
- name: Get Build Type | |
if: github.event.pull_request.merged == true | |
run: | | |
echo "This step runs only when a pull request is closed." | |
- name: Print PR Labels | |
env: | |
LABELS: ${{ toJson(github.event.pull_request.labels) }} | |
run: | | |
echo "Labels on this PR:" | |
echo "$LABELS" | jq -r '.[] | "- \(.name)"' | |
- name: Print GitHub Event Context | |
env: | |
GITHUB_EVENT: ${{ toJSON(github.event) }} | |
run: | | |
echo "$GITHUB_EVENT" | |
- name: Terraform Apply | |
if: github.event.pull_request.merged == true | |
run: terraform apply -auto-approve -input=false |