-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (53 loc) · 1.89 KB
/
deploy-coder-templates.yaml
File metadata and controls
60 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Deploy Coder Templates
on:
push:
branches: [ main ]
paths: [ 'templates/**' ] # Only run if the files int eh templates folder change
workflow_dispatch:
jobs:
# Detect which templates actually changed
detect-changes:
runs-on: coder-runner-set
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed template directories
id: set-matrix
run: |
# Finds all unique directories under /templates that had changes
# Formats them into a JSON array: ["project1", "project2"]
DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | \
grep '^templates/' | cut -d/ -f2 | sort -u | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=$DIRS" >> $GITHUB_OUTPUT
# Push only the changed templates
deploy:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.matrix != '[]' }} # Skips if no templates changed
runs-on: coder-runner-set
strategy:
matrix:
template: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.0"
- name: Install Coder CLI
run: curl -L https://coder.com/install.sh | sh
- name: Push Template to Coder
env:
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
CODER_URL: ${{ vars.CODER_URL }}
run: |
# Authenticate with token
coder login $CODER_URL --token $CODER_SESSION_TOKEN
coder templates push ${{ matrix.template }} \
--directory ./templates/${{ matrix.template }} \
--yes \
--activate \
--ignore-lockfile