Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions .github/workflows/docker-publish.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
126 changes: 126 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Release Action

on:
release:
types:
- published

concurrency:
group: '${{ github.workflow }}'
cancel-in-progress: true

jobs:
deploy_container:
name: Deploy Container
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3

- name: Get version number
id: version
env:
REF: ${{ github.ref }}
run: |
version="${REF##*/}"
if ! echo "$version" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Release tag '$version' is not a valid semver tag (vX.Y.Z)" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Populate version.json
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
hash=$(git rev-parse HEAD)
echo "{\"version\": {\"hash\": \"$hash\", \"version\": \"$VERSION\"}}" > ./version.json

- name: Login to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
push: true
tags: "ghcr.io/${{ github.repository_owner }}/web-api:${{ steps.version.outputs.version }}"

- name: Update Terraform variable set
env:
TF_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}
VARSET_ID: ${{ secrets.TERRAFORM_CLOUD_VARSET_ID }}
VAR_KEY: web_api_image_tag
VERSION: ${{ steps.version.outputs.version }}
run: |
variable_id=$(curl -sSL \
--header "Authorization: Bearer $TF_TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request GET \
"https://app.terraform.io/api/v2/varsets/$VARSET_ID/relationships/vars" \
| jq -r --arg k "$VAR_KEY" '.data[] | select(.attributes.key == $k) | .id')

if [ -z "$variable_id" ] || [ "$variable_id" = "null" ]; then
echo "::error::Variable '$VAR_KEY' not found in the configured variable set" >&2
exit 1
fi

curl -sSL \
--header "Authorization: Bearer $TF_TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request PATCH \
--data "$(jq -n --arg v "$VERSION" '{data: {type: "vars", attributes: {value: $v}}}')" \
"https://app.terraform.io/api/v2/varsets/$VARSET_ID/relationships/vars/$variable_id"

- name: Trigger Terraform apply
env:
TF_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}
TF_ORG: ohf
TF_WORKSPACE: web-api
VERSION: ${{ steps.version.outputs.version }}
run: |
# The variable set update above does not queue a run on its own, so we
# create one explicitly and let Terraform Cloud apply it without manual
# confirmation. web-api is its own workspace/state, so this only
# deploys web-api — shared infrastructure is untouched.
workspace_id=$(curl -sSL \
--header "Authorization: Bearer $TF_TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request GET \
"https://app.terraform.io/api/v2/organizations/$TF_ORG/workspaces/$TF_WORKSPACE" \
| jq -r '.data.id')

if [ -z "$workspace_id" ] || [ "$workspace_id" = "null" ]; then
echo "::error::Could not resolve Terraform Cloud workspace '$TF_WORKSPACE'" >&2
exit 1
fi

run_id=$(curl -sSL \
--header "Authorization: Bearer $TF_TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data "$(jq -n --arg ws "$workspace_id" --arg v "$VERSION" '{
data: {
type: "runs",
attributes: {
message: "Deploy web-api \($v) (release action)",
"auto-apply": true
},
relationships: {
workspace: { data: { type: "workspaces", id: $ws } }
}
}
}')" \
"https://app.terraform.io/api/v2/runs" \
| jq -r '.data.id')

if [ -z "$run_id" ] || [ "$run_id" = "null" ]; then
echo "::error::Failed to create Terraform Cloud run" >&2
exit 1
fi

echo "Triggered Terraform Cloud run $run_id (auto-apply) for $TF_WORKSPACE"