ci #549
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
pull_request: | |
branches: [ main ] | |
push: | |
branches: [ main ] | |
schedule: | |
- cron: '0 0 * * *' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
list-apko-images: | |
runs-on: ubuntu-latest | |
outputs: | |
images: ${{ steps.output-images.outputs.images }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: list images | |
id: output-images | |
run: | | |
cd images/apko | |
echo "images=$(ls *.yaml | sed -e 's/\.yaml$//' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
build-apko-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: list-apko-images | |
strategy: | |
matrix: | |
image: ${{fromJSON(needs.list-apko-images.outputs.images)}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Log in to the Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build apko image ${{ matrix.image }} | |
if: github.event_name == 'pull_request' | |
uses: distroless/actions/apko-build@main | |
with: | |
config: images/apko/${{ matrix.image }}.yaml | |
tag: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest | |
- name: Build and publish apko image ${{ matrix.image }} | |
if: github.event_name != 'pull_request' | |
uses: distroless/actions/apko-publish@main | |
with: | |
config: images/apko/${{ matrix.image }}.yaml | |
tag: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest | |
list-images: | |
runs-on: ubuntu-latest | |
outputs: | |
images: ${{ steps.output-images.outputs.images }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: list images | |
id: output-images | |
run: | | |
echo "images=$(ls images | grep -v apko | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
build-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: list-images | |
strategy: | |
matrix: | |
image: ${{fromJSON(needs.list-images.outputs.images)}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v44 | |
with: | |
files: | | |
images/${{ matrix.image }}/** | |
- name: changed files | |
if: steps.changed-files.outputs.any_changed == 'true' | |
run: | | |
echo ${{ steps.changed-files.outputs.any_changed }} | |
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}" | |
- name: Log in to the Container registry | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
id: meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 | |
with: | |
images: ghcr.io/${{ github.repository }}/${{ matrix.image }} | |
- name: Build and push Docker image | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
uses: docker//build-push-action@v5 | |
with: | |
context: images/${{ matrix.image }} | |
platforms: linux/amd64,linux/s390x,linux/ppc64le | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
test: | |
strategy: | |
fail-fast: false # Keep running if one leg fails. | |
matrix: | |
pipeline-version: | |
- v0.50.5 | |
- v0.53.3 | |
- latest | |
runs-on: ubuntu-latest | |
needs: | |
- build-images | |
- build-apko-images | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
# instantiate a KinD (Kubernetes in Docker) cluster, installs `kubectl` and configures the | |
# `kubeconfig` to reach the local cluster | |
- uses: helm/[email protected] | |
with: | |
cluster_name: kind | |
wait: 120s | |
# installs Tekton Pipelines and `tkn` command line, including a local Container-Registry with | |
# settings to reach it during testing | |
- uses: openshift-pipelines/setup-tektoncd@v1 | |
with: | |
pipeline_version: ${{ matrix.pipeline-version }} | |
- name: run-tests | |
run: | | |
set -Eeuo pipefail | |
exitCode=0 | |
# go-crane-image | |
kubectl create -f ./go-crane-image/go-crane-image.yaml | |
kubectl create -f ./go-crane-image/tests/run.yaml | |
tkn pipelinerun logs -f go-crane-image-test-run | |
tkn pipelinerun describe go-crane-image-test-run | |
kubectl get pipelinerun go-crane-image-test-run | |
status=$(kubectl get pipelinerun go-crane-image-test-run -o json | jq -r '.status.conditions[] | select(.type == "Succeeded") | .status') | |
if [[ "${status}" != "True" ]]; then | |
echo "go-crane-image test failed" | |
kubectl get pipelinerun/go-crane-image-test-run -o yaml | |
exitCode=1 | |
fi | |
# go-ko-image | |
kubectl create -f ./go-ko-image/go-ko-image.yaml | |
kubectl create -f ./go-ko-image/tests/run.yaml | |
tkn pipelinerun logs -f go-ko-image-test-run | |
tkn pipelinerun describe go-ko-image-test-run | |
kubectl get pipelinerun go-ko-image-test-run | |
status=$(kubectl get pipelinerun go-ko-image-test-run -o json | jq -r '.status.conditions[] | select(.type == "Succeeded") | .status') | |
if [[ "${status}" != "True" ]]; then | |
echo "go-ko-image test failed" | |
kubectl get pipelinerun/go-ko-image-test-run -o yaml | |
exitCode=1 | |
fi | |
exit $exitCode |