Skip to content

Merge pull request #7438 from h3mmy/renovate/oci-6.x #327

Merge pull request #7438 from h3mmy/renovate/oci-6.x

Merge pull request #7438 from h3mmy/renovate/oci-6.x #327

---
name: "Terraform: Build OCI artifacts"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches:
- main
paths:
- "infrastructure/terraform/**"
env:
IMAGE_REGISTRY: ghcr.io
jobs:
changed-files:
name: Generate Build Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Generate Token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
id: generate-token
with:
app_id: "${{ secrets.APP_ID }}"
private_key: "${{ secrets.APP_PRIVATE_KEY }}"
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
token: "${{ steps.generate-token.outputs.token }}"
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@48d8f15b2aaa3d255ca5af3eba4870f807ce6b3c # v45.0.2
with:
dir_names: true
dir_names_max_depth: 3
json: true
files: |
infrastructure/terraform/**
- name: List all changed files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo $ALL_CHANGED_FILES
- name: Install jo
uses: awalsh128/cache-apt-pkgs-action@v1.4.2
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:
name: Publish OCI
runs-on: ubuntu-latest
permissions:
actions: read
packages: write
id-token: write
needs: [changed-files]
if: ${{ needs.changed-files.outputs.matrix != '[]' }}
strategy:
matrix: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
steps:
- name: Generate Token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
id: generate-token
with:
app_id: "${{ secrets.APP_ID }}"
private_key: "${{ secrets.APP_PRIVATE_KEY }}"
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
token: "${{ steps.generate-token.outputs.token }}"
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Setup Tools
run: |
brew install cosign fluxcd/tap/flux
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate OCI tag
id: generate-tag
run: echo "tag=${{ env.IMAGE_REGISTRY }}/${{ 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