Files
firezone/.github/workflows/cd.yml
Jamil b782436f98 Fix Rust/Swift caching and parallelize swift build (#1793)
- Renames remnants of `cloud` ref to `main`
- Uses matrix for macOS, iphoneos builds
2023-07-14 23:09:15 -07:00

102 lines
3.9 KiB
YAML

name: Continuous Delivery
on:
push:
branches:
- main
# Cancel old workflow runs if new code is pushed
concurrency:
group: "cd-${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: false
jobs:
elixir:
uses: ./.github/workflows/elixir.yml
rust:
uses: ./.github/workflows/rust.yml
terraform:
uses: ./.github/workflows/terraform.yml
secrets: inherit
deploy:
runs-on: ubuntu-latest
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: write
needs:
- elixir
- rust
- terraform
env:
TF_CLOUD_ORGANIZATION: "firezone"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "staging"
steps:
- name: Get Terraform Version
run: |
TERRAFORM_VERSION=$(cat .tool-versions | grep terraform | awk '{ print $NF; }')
echo "TERRAFORM_VERSION=${TERRAFORM_VERSION}" >> $GITHUB_ENV
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
# - name: "Push Changed Application Tags"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# FILE_TO_COMMIT: terraform/environments/staging/versions.auto.tfvars
# DESTINATION_BRANCH: ${{ github.ref_name }}
# run: |
# sed -ri 's/^(\s*)(api_image_tag\s*=\s*"[^"]*"\s*$)/api_image_tag = "${{ github.sha }}"/' ./terraform/environments/staging/versions.auto.tfvars
# sed -ri 's/^(\s*)(web_image_tag\s*=\s*"[^"]*"\s*$)/web_image_tag = "${{ github.sha }}"/' ./terraform/environments/staging/versions.auto.tfvars
# cat ./terraform/environments/staging/versions.auto.tfvars
# export TODAY=$( date -u '+%Y-%m-%d' )
# export SHA=$( git rev-parse $DESTINATION_BRANCH:$FILE_TO_COMMIT )
# export CONTENT=$( base64 -i $FILE_TO_COMMIT )
# gh api \
# --method PUT /repos/${{ github.repository }}/contents/$FILE_TO_COMMIT \
# --field message="Push updated container versions [skip actions]" \
# --field content="$CONTENT" \
# --field encoding="base64" \
# --field branch="$DESTINATION_BRANCH" \
# --field sha="$SHA"
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.0.0
id: apply-upload
with:
workspace: ${{ env.TF_WORKSPACE }}
# Subdirectory is set in the project settings:
# https://app.terraform.io/app/firezone/workspaces/staging/settings/general
directory: "./"
- name: Create Plan Run
uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0
id: apply-run
env:
TF_VAR_api_image_tag: '"${{ github.sha }}"'
TF_VAR_web_image_tag: '"${{ github.sha }}"'
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }}
- name: Apply
uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.0.0
if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable
id: apply
with:
run: ${{ steps.apply-run.outputs.run_id }}
comment: "Apply Run from GitHub Actions CI ${{ github.sha }}"
- name: Report Status
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_USERNAME: "GitHub Actions"
SLACK_COLOR: "#ff0000"
MSG_MINIMAL: "ref,actions url"
SLACK_TITLE: "Deployment Failed"
SLACK_MESSAGE: "Automatic deployment to ${{ env.TF_WORKSPACE }} failed"
with:
status: ${{ job.status }}
notify_when: "failure"