Skip to content

Commit

Permalink
chore: Refactor pull images
Browse files Browse the repository at this point in the history
  • Loading branch information
szinn committed Mar 5, 2025
1 parent 1f8cca3 commit ced5b93
Showing 1 changed file with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Pre-pull Images"
name: Image Pull

on:
pull_request:
branches: ["main"]
paths: ["kubernetes/main/**"]
paths:
- "kubernetes/main/**"
- "kubernetes/repositories/**"

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
pre-job:
name: Pre-pull Images Pre-Job
setup:
name: Image Pull - Setup
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
Expand All @@ -27,18 +29,18 @@ jobs:
with:
files: kubernetes/main/**

extract-images:
name: Extract Images
needs: pre-job
extract:
if: ${{ needs.setup.outputs.any_changed == 'true' }}
name: Image Pull - Extract Images
needs: setup
runs-on: ubuntu-latest
if: ${{ needs.pre-job.outputs.any_changed == 'true' }}
strategy:
matrix:
branches: ["default", "pull"]
fail-fast: false
outputs:
default: ${{ steps.extract-images.outputs.default }}
pull: ${{ steps.extract-images.outputs.pull }}
default: ${{ steps.images.outputs.default }}
pull: ${{ steps.images.outputs.pull }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -58,20 +60,25 @@ jobs:
--output-file images.json
- name: Output Images
id: extract-images
# shellcheck disable=SC2086
run: echo "${{ matrix.branches }}=$(jq --compact-output '.' images.json)" >> $GITHUB_OUTPUT
id: images
run: |

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:6:15: Double quote to prevent globbing and word splitting

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:5:23: Double quote to prevent globbing and word splitting

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:4:19: Double quote to prevent globbing and word splitting

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:3:51: Double quote to prevent globbing and word splitting

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2129:style:3:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

Check failure on line 64 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:1:73: Double quote to prevent globbing and word splitting
echo "${{ matrix.branches }}=$(jq --compact-output '.' images.json)" >> ${GITHUB_OUTPUT}
echo '## Branch ${{ matrix.branches }} images' >> ${GITHUB_STEP_SUMMARY}
echo '```json' >> ${GITHUB_STEP_SUMMARY}
jq '.' images.json >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
compare-images:
name: Compare Images
compare:
if: ${{ needs.setup.outputs.any_changed == 'true' && needs.extract-images.outputs.default != needs.extract-images.outputs.pull }}

Check failure on line 73 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

property "extract-images" is not defined in object type {extract: {outputs: {default: string; pull: string}; result: string}; setup: {outputs: {any_changed: string}; result: string}}

Check failure on line 73 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

property "extract-images" is not defined in object type {extract: {outputs: {default: string; pull: string}; result: string}; setup: {outputs: {any_changed: string}; result: string}}
name: Image Pull - Compare Images
runs-on: ubuntu-latest
needs: ["pre-job", "extract-images"]
needs: ["setup", "extract"]
outputs:
images: ${{ steps.compare-images.outputs.images }}
if: ${{ needs.pre-job.outputs.any_changed == 'true' && needs.extract-images.outputs.default != needs.extract-images.outputs.pull }}
images: ${{ steps.compare.outputs.images }}
steps:
- name: Compare Images
id: compare-images
id: compare
run: |

Check failure on line 82 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:8:33: Double quote to prevent globbing and word splitting

Check failure on line 82 in .github/workflows/image-pull.yaml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2129:style:8:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects
images=$(jq --compact-output --null-input \
--argjson f1 '${{ needs.extract-images.outputs.default }}' \
Expand All @@ -80,28 +87,33 @@ jobs:
)
echo "images=${images}" >> "${GITHUB_OUTPUT}"
pre-pull-images:
name: Pre-pull Images
runs-on: ["k8s-homelab-runner"]
needs: ["pre-job", "compare-images"]
echo '## New images to Pull' >> ${GITHUB_STEP_SUMMARY}
echo '```json' >> ${GITHUB_STEP_SUMMARY}
echo $images | jq >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
pull:
if: ${{ needs.setup.outputs.any_changed == 'true' && needs.compare.outputs.images != '[]' }}
name: Image Pull - Pull Images
runs-on: k8s-homelab-runner
needs: ["setup", "compare"]
strategy:
matrix:
images: ${{ fromJSON(needs.compare-images.outputs.images) }}
images: ${{ fromJSON(needs.compare.outputs.images) }}
max-parallel: 4
fail-fast: false
if: ${{ needs.pre-job.outputs.any_changed == 'true' && needs.compare-images.outputs.images != '[]' }}
steps:
- name: Install talosctl
run: curl -fsSL https://talos.dev/install | sh

- name: Pre-pull Image
- name: Pull Image
run: talosctl -n "${NODE_IP}" image pull ${{ matrix.images }}

pre-pull-images-status:
needs: pre-pull-images
name: Pre-pull Images Success
runs-on: ubuntu-latest
status:
if: ${{ always() }}
name: Image Pull - Success
needs: pull
runs-on: ubuntu-latest
steps:
- name: Any jobs failed?
if: ${{ contains(needs.*.result, 'failure') }}
Expand Down

0 comments on commit ced5b93

Please sign in to comment.