GitHub Actions workflow for review apps #4
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: "Review apps: on PR change" | |
on: | |
pull_request: {} | |
jobs: | |
update-review-app: | |
# this references a codebuild project configured in forms-deploy | |
# see: https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html | |
runs-on: codebuild-review-forms-admin-gha-runner-${{github.run_id}}-${{github.run_attempt}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Build and push container | |
id: build-container | |
run: | | |
aws ecr get-login-password --region eu-west-2 \ | |
| docker login --username AWS --password-stdin 842676007477.dkr.ecr.eu-west-2.amazonaws.com | |
IMAGE_TAG="842676007477.dkr.ecr.eu-west-2.amazonaws.com/forms-admin:pr-${{github.event.pull_request.number}}-${{github.event.pull_request.head.ref}}" | |
echo "Building and pushing container image" | |
echo "${IMAGE_TAG}" | |
docker build -t "${IMAGE_TAG}" . | |
docker push "${IMAGE_TAG}" | |
echo "FORMS_ADMIN_IMAGE=${IMAGE_TAG}" >> "$GITHUB_OUTPUT" | |
- name: Determine Terraform version | |
id: terraform-version | |
run: | | |
cat .review_apps/.terraform-version | xargs printf "TF_VERSION=%s" >> "$GITHUB_OUTPUT" | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: ${{steps.terraform-version.outputs.TF_VERSION}} | |
- name: Deploy review app | |
run: | | |
cd .review_apps/ | |
terraform init -backend-config="key=review-apps/forms-admin/pr-${{github.event.pull_request.number}}.tfstate" | |
terraform apply \ | |
-var "pull_request_number=${{github.event.pull_request.number}}" \ | |
-var "forms_admin_container_image=${{steps.build-container.outputs.FORMS_ADMIN_IMAGE}}" \ | |
-no-color \ | |
-auto-approve |