Skip to content

chore: change workflow to trigger changed-files #4

chore: change workflow to trigger changed-files

chore: change workflow to trigger changed-files #4

Workflow file for this run

name: Build container image
on:
push:
branches: ["main"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
FLUX_VERSION: "v2.4.0"
KUSTOMIZE_VERSION: "v5.4.3"
KUBECONFORM_VERSION: "v0.6.7"
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: |
Dockerfile
.github/workflows/**/*
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to the Container registry
if: steps.changed-files.outputs.any_changed == 'true'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
if: steps.changed-files.outputs.any_changed == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
labels: |
org.opencontainers.image.description=Alpine image with flux-cli (${{ env.FLUX_VERSION }}), kustomize (${{ env.KUSTOMIZE_VERSION }}), and kubeconform (${{ env.KUBECONFORM_VERSION }})
annotations: |
org.opencontainers.image.description=Alpine image with flux-cli (${{ env.FLUX_VERSION }}), kustomize (${{ env.KUSTOMIZE_VERSION }}), and kubeconform (${{ env.KUBECONFORM_VERSION }})
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
- name: Build and push Docker image
if: steps.changed-files.outputs.any_changed == 'true'
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
FLUX_VERSION=${{ env.FLUX_VERSION }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
- name: Generate artifact attestation
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true