mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
135 lines
4.5 KiB
YAML
135 lines
4.5 KiB
YAML
name: Cloudflare Infra
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'infra/web/**'
|
|
- '.github/workflows/cloudflare-web-deploy.yml'
|
|
- '.github/actions/prepare-tofu/**'
|
|
- '.github/actions/setup/**'
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
git_tag:
|
|
description: 'Git tag to deploy (e.g. v1.2.3). Leave empty to deploy current HEAD.'
|
|
required: false
|
|
type: string
|
|
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.TF_CLOUDFLARE_API_TOKEN }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
TF_VAR_workers_message: ${{ github.event_name == 'pull_request' && github.event.pull_request.title || github.ref_name }}
|
|
TF_VAR_account_id: ${{ secrets.TF_VAR_ACCOUNT_ID }}
|
|
TF_VAR_zone_id: ${{ secrets.TF_VAR_ZONE_ID }}
|
|
TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }}
|
|
TF_HTTP_LOCK_ADDRESS: ${{ secrets.TF_HTTP_LOCK_ADDRESS }}
|
|
TF_HTTP_UNLOCK_ADDRESS: ${{ secrets.TF_HTTP_UNLOCK_ADDRESS }}
|
|
TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }}
|
|
TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }}
|
|
TF_HTTP_LOCK_METHOD: 'POST'
|
|
TF_HTTP_UNLOCK_METHOD: 'DELETE'
|
|
TF_HTTP_RETRY_WAIT_MIN: '5'
|
|
|
|
concurrency:
|
|
group: cloudflare-infra
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
plan:
|
|
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
defaults:
|
|
run:
|
|
working-directory: infra/web
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Resolve release version
|
|
id: version
|
|
shell: bash
|
|
env:
|
|
GIT_TAG: ${{ inputs.git_tag }}
|
|
REF_NAME: ${{ github.ref_name }}
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
run: |
|
|
if [[ "$EVENT_NAME" == "workflow_dispatch" && -n "$GIT_TAG" ]]; then
|
|
TAG="$GIT_TAG"
|
|
else
|
|
TAG="$REF_NAME"
|
|
fi
|
|
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Prepare OpenTofu deployment
|
|
uses: ./.github/actions/prepare-tofu
|
|
with:
|
|
is_release_tag: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.git_tag != '') }}
|
|
env:
|
|
VITE_SENTRY_DSN: ${{ secrets.VITE_SENTRY_DSN }}
|
|
VITE_SENTRY_ENVIRONMENT: production
|
|
VITE_APP_VERSION: ${{ steps.version.outputs.version }}
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
|
|
|
- name: Comment PR plan
|
|
uses: dflook/tofu-plan@cdb4f4d604c9fa695e457744dd1f802853397ce7 # v3.0.0
|
|
with:
|
|
path: infra/web
|
|
label: production
|
|
|
|
apply:
|
|
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
defaults:
|
|
run:
|
|
working-directory: infra/web
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.git_tag || '' }}
|
|
|
|
- name: Resolve release version
|
|
id: version
|
|
shell: bash
|
|
env:
|
|
GIT_TAG: ${{ inputs.git_tag }}
|
|
REF_NAME: ${{ github.ref_name }}
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
run: |
|
|
if [[ "$EVENT_NAME" == "workflow_dispatch" && -n "$GIT_TAG" ]]; then
|
|
TAG="$GIT_TAG"
|
|
else
|
|
TAG="$REF_NAME"
|
|
fi
|
|
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Prepare OpenTofu deployment
|
|
uses: ./.github/actions/prepare-tofu
|
|
with:
|
|
is_release_tag: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.git_tag != '') }}
|
|
env:
|
|
VITE_SENTRY_DSN: ${{ secrets.VITE_SENTRY_DSN }}
|
|
VITE_SENTRY_ENVIRONMENT: production
|
|
VITE_APP_VERSION: ${{ steps.version.outputs.version }}
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
|
|
|
- name: Plan infrastructure
|
|
run: mise run opentofu -- plan -input=false -no-color
|
|
|
|
- name: Apply infrastructure
|
|
run: mise run opentofu -- apply -input=false -auto-approve
|