.github/workflows/release.yaml #212
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
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '0 1 * * *' | |
workflow_dispatch: | |
inputs: | |
only: | |
description: 'Specific image name to build' | |
type: string | |
required: false | |
default: '' | |
concurrency: release | |
jobs: | |
generate-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.generate-matrix.outputs.matrix }} | |
steps: | |
# On push to main branch, only build images necessary | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} | |
- id: files | |
if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} | |
uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42 # v1 | |
with: | |
format: csv | |
# Checkout public repo to get actions | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
with: | |
repository: chainguard-images/images | |
# For nightly builds, build every image | |
- id: generate-matrix-schedule | |
if: ${{ github.event_name == 'schedule' || ( github.event_name == 'workflow_dispatch' && inputs.only == '' ) }} | |
uses: ./.github/actions/generate-matrix | |
with: | |
repository: chainguard-images/images | |
# On push to main branch, only build images necessary | |
- id: generate-matrix-main | |
if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} | |
uses: ./.github/actions/generate-matrix | |
with: | |
repository: chainguard-images/images | |
modified-files: ${{ steps.files.outputs.all }} | |
# For manual builds, build only the image requested | |
- id: generate-matrix-manual | |
if: ${{ github.event_name == 'workflow_dispatch' && inputs.only != '' }} | |
uses: ./.github/actions/generate-matrix | |
with: | |
repository: chainguard-images/images | |
modified-files: images/${{ inputs.only }}/image.yaml | |
# Generate the final matrix for build based on the above | |
- id: generate-matrix | |
run: | | |
set -x | |
trap "rm -f matrix.json matrix-unique-images.json" EXIT | |
echo '${{ steps.generate-matrix-manual.outputs.matrix }}' > matrix.json | |
[[ "$(cat matrix.json)" != "" ]] || echo '${{ steps.generate-matrix-schedule.outputs.matrix }}' > matrix.json | |
[[ "$(cat matrix.json)" != "" ]] || echo '${{ steps.generate-matrix-main.outputs.matrix }}' > matrix.json | |
echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT | |
echo '${{ steps.generate-matrix-manual.outputs.matrix-unique-images }}' > matrix-unique-images.json | |
[[ "$(cat matrix-unique-images.json)" != "" ]] || echo '${{ steps.generate-matrix-schedule.outputs.matrix-unique-images }}' > matrix-unique-images.json | |
[[ "$(cat matrix-unique-images.json)" != "" ]] || echo '${{ steps.generate-matrix-main.outputs.matrix-unique-images }}' > matrix-unique-images.json | |
echo "matrix-unique-images=$(cat matrix-unique-images.json)" >> $GITHUB_OUTPUT | |
build: | |
runs-on: ubuntu-latest | |
needs: generate-matrix | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | |
permissions: | |
id-token: write | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
with: | |
repository: chainguard-images/images | |
- name: Add additional inputs | |
id: augmented-inputs | |
env: | |
EXTRA_INPUT_APKO_IMAGE: ghcr.io/wolfi-dev/apko:latest@sha256:d0d35729ac785d5bc15d50a1d99ea9a2aef565779fadf37235edfc9b30a10e75 | |
run: | | |
# convert env vars beginning with "EXTRA_INPUT_" | |
# to camelcased input variables passed to next step | |
set -x | |
echo '${{ toJSON(matrix) }}' > inputs.json | |
for kv in `env | grep '^EXTRA_INPUT_' | sed 's/^EXTRA_INPUT_//'`; do | |
k="$(echo "${kv}" | cut -d "=" -f1 | tr '[:upper:]' '[:lower:]' | sed -r 's/(.)_+(.)/\1\U\2/g;s/^[a-z]/\U&/' | sed 's/.*/\l&/')" | |
v="$(echo "${kv}" | cut -d "=" -f2)" | |
cat inputs.json | jq -c '. + {'${k}': "'${v}'"}' > inputs.json.tmp | |
mv inputs.json.tmp inputs.json | |
done | |
echo "augmented-inputs=$(cat inputs.json | tr -d '\n')" >> $GITHUB_OUTPUT | |
- uses: ./.github/actions/release-image | |
with: ${{ fromJSON(steps.augmented-inputs.outputs.augmented-inputs) }} |