Skip to content

Commit

Permalink
feat: lint build-ci-docker-images.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmaestro committed Nov 14, 2024
1 parent 0846aca commit 800cac6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/build-ci-docker-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ on:
# NOTE: keep in-sync with env.TEST_IMAGE
default: testimage
PLATFORMS:
description: |-
Select platforms to build
default: linux/amd64
TAG_DATE:
description: Tag image date in ISO format (YYYYMMDD)
Expand Down Expand Up @@ -147,11 +149,11 @@ jobs:
# NOTE:
# GH_SHA_BEFORE is empty on pushing the first commit of a new branch
# or when running manually via workflow_dispatch
if [[ -z $GH_SHA_BEFORE ]]; then
DOCKERFILES="$(ls $SPARSE_PATH/*/Dockerfile)"
if [[ -z "$GH_SHA_BEFORE" ]]; then
DOCKERFILES="$(ls "$SPARSE_PATH"/*/Dockerfile)"
else
DOCKERFILES="$(
git diff --name-only $GH_SHA_BEFORE $GH_SHA |
git diff --name-only "$GH_SHA_BEFORE" "$GH_SHA" |
grep Dockerfile || {
# NOTE:
# this grep could fail if e.g. we are force-pushing a stack
Expand All @@ -167,22 +169,26 @@ jobs:
DOCKERFILES_JSON="$(echo -n "$DOCKERFILES" | jq -R '.' | jq -sc '.' )"
echo "DOCKERFILES_JSON=$DOCKERFILES_JSON"
echo "DOCKERFILES_JSON=$DOCKERFILES_JSON" >> $GITHUB_ENV
echo "DOCKERFILES_JSON=$DOCKERFILES_JSON" >> "$GITHUB_ENV"
- name: Define targets
id: define_targets
env:
RE_TARGET_INCLUDE: .
run: |-
if [[ "$GH_EVENT_NAME" == "push" ]]; then
RE_TARGET_EXCLUDE="$RE_TARGET_EXCLUDE|$TEST_IMAGE"
fi
DOCKERFILES=($(echo "$DOCKERFILES_JSON" | jq -r 'join(" ")'))
read -ra DOCKERFILES <<< "$(
echo "$DOCKERFILES_JSON" | jq -r 'join(" ")'
)"
if [[ ${#DOCKERFILES[@]} -gt 0 ]]; then
if [[ "${#DOCKERFILES[@]}" -gt 0 ]]; then
TARGETS_LS="$(
grep -i '^FROM .* AS ' ${DOCKERFILES[@]} |
grep -i '^FROM .* AS ' "${DOCKERFILES[@]}" |
awk '{print $NF}' |
{ grep -E "$RE_TARGET_INCLUDE" || true; } |
{ grep -E "${RE_TARGET_INCLUDE:-}" || true; } |
{ grep -vE "$RE_TARGET_EXCLUDE" || true; } |
jq -R '.'
)"
Expand Down Expand Up @@ -259,12 +265,12 @@ jobs:
CONTEXT="$SPARSE_PATH/$DISTRO"
{
for tag in ${!TAGS[@]}; do
for tag in "${!TAGS[@]}"; do
echo "IMAGE_TAG_${tag^^}=$IMAGE_NAME:${TAGS[$tag]}"
done
echo "CONTEXT=$CONTEXT"
} >> $GITHUB_ENV
} >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
files: >-
(?x)^(
.github/workflows/build-ci-docker-images.yaml
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: mixed-line-ending
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/mpalmer/action-validator
rev: v0.6.0
hooks:
- id: action-validator

- repo: https://github.com/rhysd/actionlint
rev: v1.7.4
hooks:
- id: actionlint

0 comments on commit 800cac6

Please sign in to comment.