Skip to content

Commit

Permalink
Merge pull request #3234 from twz123/reusable-workflows
Browse files Browse the repository at this point in the history
Refactor GitHub workflows for reusability
  • Loading branch information
twz123 authored Jun 23, 2023
2 parents e9b1174 + 61abe46 commit c777ddc
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 179 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build-airgap-image-bundle.yml
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"
92 changes: 92 additions & 0 deletions .github/workflows/build-k0s.yml
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
Loading

0 comments on commit c777ddc

Please sign in to comment.