-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GitHub workflows for reusability
Separate the k0s and airgap image bundle builds into their own reusable workflows, enhancing composability and enabling reuse in higher-level workflows. The new reusable workflows are parameterized over os and arch. Hopefully they can be reused by the ARM builds at some point as well. To increase the reusability and generalization of the k0s build workflow, extract the airgap image bundle build into a separate reusable workflow. Additionally, eliminate the special case for the smoke test matrix generation. Instead, introduce a dedicated "Prepare" workflow that generates the matrix for the regular and Autopilot smoke tests. Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
- Loading branch information
Showing
3 changed files
with
245 additions
and
174 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: "Build :: Airgap image bundle" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target-os: | ||
type: string | ||
description: The OS to build the airgap image bundle for. | ||
target-arch: | ||
type: string | ||
required: true | ||
description: The architecture to build the airgap image bundle for. | ||
outputs: | ||
cache-key: | ||
description: The airgap image bundle's cache key. | ||
value: ${{ jobs.build.outputs.cache-key }} | ||
|
||
jobs: | ||
build: | ||
name: "${{ inputs.target-os }}-${{ inputs.target-arch }}" | ||
runs-on: ubuntu-22.04 | ||
|
||
outputs: | ||
cache-key: ${{ steps.cache-airgap-image-bundle-calc-key.outputs.cache-key }} | ||
|
||
env: | ||
TARGET_OS: ${{ inputs.target-os }} | ||
TARGET_ARCH: ${{ inputs.target-arch }} | ||
|
||
steps: | ||
- name: "Build :: Checkout" | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: "Download :: Airgap image list" | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: airgap-image-list-${{ inputs.target-os }}-${{ inputs.target-arch }} | ||
|
||
# Capture the calculated image bundle source hash in a build output, so | ||
# it can be shared between the cache actions in this job and in the | ||
# smoketests. Do this in a separate step, as the hashFiles function is | ||
# evaluated before the step execution. So all the required files need to | ||
# exist before that. | ||
- name: "Cache :: Airgap image bundle :: Calculate cache key" | ||
id: cache-airgap-image-bundle-calc-key | ||
env: | ||
HASH_VALUE: ${{ hashFiles('Makefile', 'airgap-images.txt', 'hack/image-bundler/*') }} | ||
run: | | ||
printf 'cache-key=build-airgap-image-bundle-%s-%s-%s\n' "$TARGET_OS" "$TARGET_ARCH" "$HASH_VALUE" >> "$GITHUB_OUTPUT" | ||
- name: "Cache :: Airgap image bundle" | ||
id: cache-airgap-image-bundle | ||
uses: actions/cache@v3 | ||
with: | ||
key: ${{ steps.cache-airgap-image-bundle-calc-key.outputs.cache-key }} | ||
path: airgap-image-bundle-${{ inputs.target-os }}-${{ inputs.target-arch }}.tar | ||
lookup-only: true | ||
|
||
- name: "Build :: Airgap image bundle" | ||
if: steps.cache-airgap-image-bundle.outputs.cache-hit != 'true' | ||
run: | | ||
mkdir -p "embedded-bins/staging/$TARGET_OS/bin" | ||
make --touch airgap-images.txt | ||
make "airgap-image-bundle-$TARGET_OS-$TARGET_ARCH.tar" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: "Build :: k0s" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target-os: | ||
type: string | ||
required: true | ||
description: The OS to build k0s for (linux or windows). | ||
target-arch: | ||
type: string | ||
required: true | ||
description: The architecture to build k0s for. | ||
|
||
jobs: | ||
build: | ||
name: ${{ inputs.target-os }}-${{ inputs.target-arch }} | ||
runs-on: ubuntu-22.04 | ||
|
||
env: | ||
TARGET_OS: ${{ inputs.target-os }} | ||
TARGET_ARCH: ${{ inputs.target-arch }} | ||
|
||
steps: | ||
- name: "Build :: Checkout" | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # for `git describe` | ||
persist-credentials: false | ||
|
||
- name: "Build :: Prepare" | ||
id: build-prepare | ||
run: | | ||
.github/workflows/prepare-build-env.sh | ||
executableSuffix='' | ||
if [ "TARGET_OS" = windows ]; then | ||
executableSuffix=.exe | ||
fi | ||
echo executable-suffix="$executableSuffix" >>"$GITHUB_OUTPUT" | ||
- name: "Cache :: embedded binaries" | ||
uses: actions/cache@v3 | ||
with: | ||
key: build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-embedded-bins-${{ hashFiles('embedded-bins/**/*') }} | ||
path: | | ||
.bins.${{ inputs.target-os }}.stamp | ||
bindata_${{ inputs.target-os }} | ||
embedded-bins/staging/${{ inputs.target-os }}/bin/ | ||
embedded-bins/Makefile.variables | ||
pkg/assets/zz_generated_offsets_${{ inputs.target-os }}.go | ||
- name: "Cache :: GOCACHE" | ||
uses: actions/cache@v3 | ||
with: | ||
key: build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-gocache-${{ github.ref_name }}-${{ github.sha }} | ||
restore-keys: | | ||
build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-gocache-${{ github.ref_name }}- | ||
path: | | ||
build/cache/go/build | ||
- name: "Cache :: GOMODCACHE" | ||
uses: actions/cache@v3 | ||
with: | ||
key: build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-gomodcache-${{ hashFiles('go.sum') }} | ||
path: | | ||
build/cache/go/mod | ||
- name: "Build :: k0s" | ||
run: | | ||
make bindata | ||
make --touch codegen | ||
make build | ||
- name: "Upload :: k0s" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: k0s-${{ inputs.target-os }}-${{ inputs.target-arch }} | ||
path: | | ||
k0s${{ steps.build-prepare.outputs.executable-suffix }} | ||
k0s${{ steps.build-prepare.outputs.executable-suffix }}[.]exe | ||
- name: "Build :: Airgap image list" | ||
if: inputs.target-os != 'windows' | ||
run: make airgap-images.txt && cat airgap-images.txt | ||
|
||
- name: "Upload :: Airgap image list" | ||
if: inputs.target-os != 'windows' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: airgap-image-list-${{ inputs.target-os }}-${{ inputs.target-arch }} | ||
path: airgap-images.txt |
Oops, something went wrong.