Some checks are pending
CI / tongo-core (push) Waiting to run
CI / web-terminal (push) Waiting to run
Deploy / build-and-push (push) Waiting to run
Deploy / deploy (push) Blocked by required conditions
Infrastructure / plan (push) Waiting to run
Infrastructure / apply (push) Blocked by required conditions
73 lines
1.9 KiB
YAML
73 lines
1.9 KiB
YAML
name: Infrastructure
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths: ['infra/**']
|
|
pull_request:
|
|
branches: [main]
|
|
paths: ['infra/**']
|
|
|
|
jobs:
|
|
plan:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup OpenTofu
|
|
uses: opentofu/setup-opentofu@v1
|
|
|
|
- name: Set environment target
|
|
id: target
|
|
run: |
|
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
echo "env_name=production" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "env_name=staging" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Init and Plan
|
|
working-directory: infra
|
|
env:
|
|
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
|
|
ENV_NAME: ${{ steps.target.outputs.env_name }}
|
|
run: |
|
|
tofu init
|
|
tofu workspace select $ENV_NAME || tofu workspace new $ENV_NAME
|
|
tofu plan -out=tfplan
|
|
|
|
- name: Upload plan artifact
|
|
if: github.event_name == 'pull_request'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: tfplan
|
|
path: infra/tfplan
|
|
|
|
apply:
|
|
runs-on: self-hosted
|
|
needs: plan
|
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup OpenTofu
|
|
uses: opentofu/setup-opentofu@v1
|
|
|
|
- name: Set environment target
|
|
id: target
|
|
run: |
|
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
echo "env_name=production" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "env_name=staging" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Init and Apply
|
|
working-directory: infra
|
|
env:
|
|
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
|
|
ENV_NAME: ${{ steps.target.outputs.env_name }}
|
|
run: |
|
|
tofu init
|
|
tofu workspace select $ENV_NAME || tofu workspace new $ENV_NAME
|
|
tofu apply -auto-approve
|