Skip to content

Merge pull request #7 from tbobm/docs/document-generation-script #13

Merge pull request #7 from tbobm/docs/document-generation-script

Merge pull request #7 from tbobm/docs/document-generation-script #13

Workflow file for this run

---
name: "Build Containers"
'on':
workflow_dispatch:
push:
branches: ["main"]
tags: ["*"]
jobs:
release:
name: 'Create a release'
runs-on: ubuntu-20.04
outputs:
release_version: steps.semantic-release.outputs.new_release_version
new_release: steps.semantic-release.outputs.new_release_published
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Semantic Release
id: semantic-release
uses: cycjimmy/semantic-release-action@v2
with:
branches: |
[
'main'
]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
matrix:
runs-on: "ubuntu-latest"
name: "Generate the matrix"
outputs:
matrix: ${{ steps.create-matrix.outputs.matrix }}
steps:
- name: "Checkout the code"
uses: "actions/checkout@v3"
- name: "Run generate_matrix.sh"
id: create-matrix
run: |
yq --version
matrix=$(./generate_matrix.sh | yq -I=0 -o=json)
echo matrix="$matrix"
echo "::set-output name=matrix::$(./generate_matrix.sh | yq -I=0 -o=json)"
- name: "Display matrix"
run: echo '${{ steps.create-matrix.outputs.matrix }}'
check-matrix:
runs-on: ubuntu-latest
name: "Validate and display matrix"
needs: matrix
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml
- name: Check matrix definition
run: |
matrix='${{ needs.matrix.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml
build-containers:
runs-on: "ubuntu-latest"
name: "Build and push OCIs"
needs:
- matrix
- release
strategy:
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- name: "Checkout the code"
uses: "actions/checkout@v3"
- name: "GitHub Slug Action"
uses: rlespinasse/github-slug-action@4.2.3
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1
- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Slugify path to create container tag"
id: slugify-src
env:
TARGET_SRC: ${{ matrix.target.src }}
run: |
echo "::set-output name=target-slug::$(echo $TARGET_SRC | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)"
- name: "Build container ${{ matrix.target.name }}"
uses: docker/build-push-action@v2
with:
context: "${{ matrix.target.src }}"
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
"ghcr.io/${{ env.GITHUB_REPOSITORY }}:${{ steps.slugify-src.outputs.target-slug }}-latest"
"ghcr.io/${{ env.GITHUB_REPOSITORY }}:${{ steps.slugify-src.outputs.target-slug }}-${{ needs.release.outputs.new_release == 'true' && needs.release.outputs.release_version || env.GITHUB_REF_SLUG }}"