-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (80 loc) · 2.71 KB
/
build-terraform-oci.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Terraform: Build OCI artifacts"
on:
workflow_dispatch:
push:
branches:
- main
paths:
- .github/workflows/build-terraform-oci.yaml
- infrastructure/terraform/**
jobs:
changed-files:
name: Generate matrix for building images
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
dir_names: true
dir_names_max_depth: 3
json: true
files: |
infrastructure/terraform/**
- name: List all changed files
run: |
echo '${{ steps.changed-files.outputs.all_changed_files }}'
- name: Install jo
uses: awalsh128/[email protected]
with:
packages: jo
- name: Store changed projects
id: set-matrix
run: |
if [[ "${{ steps.changed-files.outputs.all_changed_files }}" == "[]" ]]; then
echo "matrix={\"project\":$(find infrastructure/terraform -type d -mindepth 1 -maxdepth 1 | jo -a)}" >> "${GITHUB_OUTPUT}"
else
echo "matrix={\"project\":${{ steps.changed-files.outputs.all_changed_files }}}" >> "${GITHUB_OUTPUT}"
fi
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs:
- changed-files
if: ${{ needs.changed-files.outputs.matrix != '[]' }}
strategy:
matrix: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Flux
uses: fluxcd/flux2/action@main
with:
version: "latest"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tag
id: generate-tag
shell: bash
run: echo "tag=ghcr.io/${{ github.repository_owner }}/terraform/$(basename ${{ matrix.project }}):$(git rev-parse --short HEAD)" >> "${GITHUB_OUTPUT}"
- name: Publish OCI
run: |
flux push artifact "oci://${{ steps.generate-tag.outputs.tag }}" \
--path="./${{ matrix.project }}" \
--source="$(git config --get remote.origin.url)" \
--revision="$(git branch --show-current)/$(git rev-parse HEAD)"
- name: Tag OCI
run: |
flux tag artifact "oci://${{ steps.generate-tag.outputs.tag }}" --tag main