Convert shellcheck image to use a bake file #381
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: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
inputs: | |
build_context: | |
description: 'Build directory' | |
required: true | |
jobs: | |
# Job to run change detection | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
# Expose matched filters as job 'images' output variable | |
images: ${{ steps.filter.outputs.changes }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set context from workflow_dispatch | |
if: github.event_name != 'workflow_dispatch' | |
id: manual_filter | |
run: | | |
echo "changes={ ${{ inputs.build_context}}: '${{ inputs.build_context}}/**' }" | |
- uses: dorny/paths-filter@v2 | |
if: github.event_name != 'workflow_dispatch' | |
id: filter | |
with: | |
# Use context to get the branch where commits were pushed. | |
# If there is only one long-lived branch (e.g. master), | |
# you can specify it directly. | |
# If it's not configured, the repository default branch is used. | |
base: ${{ github.ref }} | |
filters: | | |
aws-cli: 'aws-cli/**' | |
buildpack-deps/ubuntu/jammy: 'buildpack-deps/ubuntu/jammy/**' | |
fpm: 'fpm/**' | |
meshcmd: 'meshcmd/**' | |
python/3.8/jammy: 'python/3.8/jammy/**' | |
python/3.8/slim-jammy: 'python/3.8/slim-jammy/**' | |
python/3.9/jammy: 'python/3.9/jammy/**' | |
python/3.9/slim-jammy: 'python/3.9/slim-jammy/**' | |
python/3.10/jammy: 'python/3.10/jammy/**' | |
python/3.10/slim-jammy: 'python/3.10/slim-jammy/**' | |
python/3.11/jammy: 'python/3.11/jammy/**' | |
python/3.11/slim-jammy: 'python/3.11/slim-jammy/**' | |
python/3.12/jammy: 'python/3.12/jammy/**' | |
python/3.12/slim-jammy: 'python/3.12/slim-jammy/**' | |
# Job to build and test each of the modified images | |
build: | |
needs: changes | |
strategy: | |
matrix: | |
# Parse JSON array containing names of all filters matching any of changed files | |
# e.g. ['image1', 'image2'] if both image folders contains changes | |
image: ${{ fromJSON(needs.changes.outputs.images) }} | |
if: ${{ needs.changes.outputs.images != '[]' && needs.changes.outputs.images != '' }} | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ matrix.image }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check the Containerfile with hadolint | |
run: | | |
$(git rev-parse --show-toplevel)/bin/lint.sh | |
- name: Install QEMU static binaries | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build locally for testing | |
uses: docker/bake-action@v4 | |
with: | |
workdir: ${{ matrix.image }} | |
targets: local | |
load: true | |
- name: Run tests on the image with cinc-auditor | |
run: | | |
$(git rev-parse --show-toplevel)/bin/test.sh | |
- name: Login to DockerHub | |
if: github.event_name == 'push' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} | |
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} | |
- name: Build and push | |
uses: docker/bake-action@v4 | |
with: | |
workdir: ${{ matrix.image }} | |
push: ${{ github.event_name != 'pull_request' }} | |
- name: Get the image name | |
if: github.event_name != 'pull_request' | |
id: image_name | |
run: | | |
json_data="$(docker buildx bake local --print 2>/dev/null)" | |
if echo "$json_data" | jq -e '.target.default.labels["dev.polymathrobotics.image.readme-filepath"]' > /dev/null; then | |
image_name=$(echo $json_data | jq -r '.target."release-default".["dev.polymathrobotics.image.title"]') | |
echo "image_name=$image_name" >> $GITHUB_ENV | |
else | |
echo "image_name=$(docker buildx bake --print 2>/dev/null | jq -r '.target.default.labels."org.opencontainers.image.title"')" >> $GITHUB_ENV | |
fi | |
- name: Get the image description | |
if: github.event_name != 'pull_request' | |
id: image_description | |
run: | | |
json_data="$(docker buildx bake local --print 2>/dev/null)" | |
if echo "$json_data" | jq -e '.target.default.labels["dev.polymathrobotics.image.readme-filepath"]' > /dev/null; then | |
image_description=$(echo $json_data | jq -r '.target."release-default".labels["dev.polymathrobotics.image.description"]') | |
echo "image_description=$image_name" >> $GITHUB_ENV | |
else | |
echo "image_description=$(docker buildx bake --print 2>/dev/null | jq -r '.target.default.labels."org.opencontainers.image.description"')" >> $GITHUB_ENV | |
fi | |
- name: Get the image readme filepath | |
if: github.event_name != 'pull_request' | |
id: image_readme_filepath | |
run: | | |
# Check if .group.local.targets.default exists, and if it does, extract its value | |
json_data="$(docker buildx bake local --print 2>/dev/null)" | |
if echo "$json_data" | jq -e '.target.default.labels["dev.polymathrobotics.image.readme-filepath"]' > /dev/null; then | |
readme_filepath=$(echo $json_data | jq -r '.target.default.labels["dev.polymathrobotics.image.readme-filepath"]') | |
echo "image_readme_filepath=$readme_filepath" >> $GITHUB_ENV | |
else | |
echo "image_readme_filepath=${{ matrix.image }}/README.md" >> $GITHUB_ENV | |
fi | |
- name: Update Docker Hub Description | |
if: github.event_name != 'pull_request' | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} | |
password: ${{ secrets.CONTAINER_DESCRIPTION_PASSWORD }} | |
repository: boxcutter/${{ env.image_name }} | |
short-description: ${{ env.image_description }} | |
readme-filepath: ${{ env.image_readme_filepath }} | |