Merge pull request #2696 from twz123/update-gh-actions-pt2 #807
Workflow file for this run
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: Go build | |
on: | |
push: | |
branches: | |
- main | |
- release-* | |
paths-ignore: | |
- 'docs/**' | |
- 'examples/**' | |
- '**.md' | |
- LICENSE | |
- '**.svg' | |
- '.github/workflows/docs.yml' | |
- '.github/workflows/mkdocs-set-default-version.yml' | |
- 'mkdocs.yml' | |
pull_request: | |
branches: | |
- main | |
- release-* | |
paths-ignore: | |
- 'docs/**' | |
- 'examples/**' | |
- '**.md' | |
- LICENSE | |
- '**.svg' | |
- '.github/workflows/docs.yml' | |
- '.github/workflows/mkdocs-set-default-version.yml' | |
- 'mkdocs.yml' | |
env: | |
GO_VERSION: 1.18.7 | |
GO_VERSION_WIN: 1.18.7 | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
outputs: | |
airgap-image-bundle-hash-linux: ${{ steps.create-airgap-image-list.outputs.linux-hash }} | |
steps: | |
- name: Get PR Reference and Set Cache Name | |
run: | | |
PR_NUMBER=$(echo ${GITHUB_REF} | cut -d / -f 3 ) | |
echo "cachePrefix=k0s-${PR_NUMBER}-${{ github.sha }}" >> $GITHUB_ENV | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # for `git describe` | |
persist-credentials: false | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
id: go | |
- uses: actions/cache@v3 | |
name: Go modules cache | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Bindata cache | |
uses: actions/cache@v3 | |
id: generated-bindata | |
with: | |
path: | | |
.bins.linux.stamp | |
embedded-bins/staging/linux/bin/ | |
bindata_linux | |
pkg/assets/zz_generated_offsets_linux.go | |
embedded-bins/Makefile.variables | |
key: ${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }} | |
restore-keys: | | |
${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }} | |
- name: Build | |
run: make build | |
- name: Run unit tests | |
run: make check-unit | |
- name: Validate OCI images manifests | |
run: go run hack/validate-images/main.go -architectures amd64,arm64,arm | |
- name: Cache compiled binary for further testing | |
uses: actions/cache@v3 | |
id: cache-compiled-binary | |
with: | |
path: | | |
k0s | |
key: build-${{env.cachePrefix}} | |
- name: Create airgap image list | |
id: create-airgap-image-list | |
# Capture the calculated image bundle hash in a build output, so it can | |
# be shared between the cache actions in this job and in the integration | |
# test matrix. A cleaner solution would have been to use the cache here, | |
# and then upload the cached image bundle, to be downloaded later on in | |
# the integration tests. That's the way it's done for the k0s binary. | |
# Unfortunately, the upload action is significantly slower than the | |
# cache action, for unclear reasons, so stick with this solution for | |
# faster builds. See: | |
# * https://github.com/actions/upload-artifact/issues/199#issuecomment-1190171851 | |
run: | | |
make airgap-images.txt | |
echo 'linux-hash=${{ hashFiles('Makefile', 'airgap-images.txt', 'hack/image-bundler/*') }}' >> $GITHUB_OUTPUT | |
- name: Cache airgap image bundle | |
id: cache-airgap-image-bundle | |
uses: actions/cache@v3 | |
# Technically, there's no need to restore the cache here, since this | |
# is more like a create-if-not-exists logic. Currently, there's no way | |
# to achieve this directly via actions/cache. See: | |
# * https://github.com/actions/cache/issues/321 | |
# * https://github.com/actions/cache/pull/420 | |
with: | |
key: airgap-image-bundle-linux-amd64.tar-${{ steps.create-airgap-image-list.outputs.linux-hash }} | |
path: airgap-image-bundle-linux-amd64.tar | |
- name: Create airgap image bundle if not cached | |
if: steps.cache-airgap-image-bundle.outputs.cache-hit != 'true' | |
run: make airgap-image-bundle-linux-amd64.tar | |
build_windows: | |
name: Build windows | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR Reference and Set Cache Name | |
run: | | |
PR_NUMBER=$(echo ${GITHUB_REF} | cut -d / -f 3 ) | |
echo "cachePrefix=k0s-win-${PR_NUMBER}-${{ github.sha }}" >> $GITHUB_ENV | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION_WIN }} | |
id: go | |
- uses: actions/cache@v3 | |
name: Go modules cache | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go-win- | |
- name: Bindata cache | |
uses: actions/cache@v3 | |
id: generated-bindata | |
with: | |
path: | | |
.bins.windows.stamp | |
embedded-bins/staging/windows/bin/ | |
bindata_windows | |
pkg/assets/zz_generated_offsets_windows.go | |
embedded-bins/Makefile.variables | |
key: ${{ runner.os }}-embedded-bins-win-${{ hashFiles('**/embedded-bins/**/*') }} | |
restore-keys: | | |
${{ runner.os }}-embedded-bins-win-${{ hashFiles('**/embedded-bins/**/*') }} | |
- name: Build | |
run: make k0s.exe | |
smoketest: | |
name: Smoke test | |
needs: build | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
smoke-suite: | |
- check-basic | |
- check-addons | |
- check-byocri | |
- check-calico | |
- check-cnichange | |
- check-ctr | |
- check-customports | |
- check-dualstack | |
- check-externaletcd | |
- check-hacontrolplane | |
- check-kine | |
- check-metrics | |
- check-multicontroller | |
- check-noderole | |
- check-singlenode | |
- check-backup | |
- check-k0scloudprovider | |
- check-cli | |
- check-disabledcomponents | |
- check-extraargs | |
- check-configchange | |
- check-upgrade | |
- check-psp | |
- check-statussocket | |
- check-tunneledkas | |
- check-workerrestart | |
- check-kubectl | |
- check-k0sctl | |
- check-capitalhostnames | |
steps: | |
- name: Get PR Reference and Set Cache Name | |
run: | | |
PR_NUMBER=$(echo ${GITHUB_REF} | cut -d / -f 3 ) | |
echo "cachePrefix=k0s-${PR_NUMBER}-${{ github.sha }}" >> $GITHUB_ENV | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
id: go | |
- name: Cache compiled binary for smoke testing | |
uses: actions/cache@v3 | |
id: restore-compiled-binary | |
with: | |
path: | | |
k0s | |
key: build-${{env.cachePrefix}} | |
- name: Run test . | |
run: make -C inttest ${{ matrix.smoke-suite }} | |
- name: Collect test logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.cachePrefix }}-logs-${{ matrix.smoke-suite }}-${{ github.run_number }} | |
path: | | |
/tmp/*.log | |
smoketest-airgap: | |
name: Smoke test for airgap install | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR Reference and Set Cache Name | |
run: | | |
PR_NUMBER=$(echo ${GITHUB_REF} | cut -d / -f 3 ) | |
echo "cachePrefix=k0s-${PR_NUMBER}-${{ github.sha }}" >> $GITHUB_ENV | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
id: go | |
- name: Cache compiled binary for smoke testing | |
uses: actions/cache@v3 | |
id: restore-compiled-binary | |
with: | |
path: | | |
k0s | |
key: build-${{env.cachePrefix}} | |
# We need the bindata cache too so the makefile targets and deps work properly | |
- name: Bindata cache | |
uses: actions/cache@v3 | |
id: generated-bindata | |
with: | |
path: | | |
.bins.linux.stamp | |
embedded-bins/staging/linux/bin/ | |
bindata_linux | |
pkg/assets/zz_generated_offsets_linux.go | |
embedded-bins/Makefile.variables | |
key: ${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }} | |
restore-keys: | | |
${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }} | |
- name: Cache airgap image bundle | |
id: cache-airgap-image-bundle | |
uses: actions/cache@v3 | |
with: | |
key: airgap-image-bundle-linux-amd64.tar-${{ needs.build.outputs.airgap-image-bundle-hash-linux }} | |
path: airgap-image-bundle-linux-amd64.tar | |
- name: Run test | |
run: | | |
[ -f airgap-image-bundle-linux-amd64.tar ] || { | |
echo Airgap image bundle file missing! | |
exit 1 | |
} | |
make -C inttest check-airgap | |
- name: Cache images bundle | |
uses: actions/cache@v3 | |
id: save-bundle | |
with: | |
path: | | |
image-bundle/bundle.tar | |
key: build-image-bundle-${{env.cachePrefix}} | |
- name: Collect test logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.cachePrefix }}-logs-check-airgap-${{ github.run_number }} | |
path: | | |
/tmp/*.log | |
smoketest-arm: | |
name: Smoke test on arm64 | |
runs-on: [self-hosted,linux,arm64] | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # for `git describe` | |
persist-credentials: false | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
id: go | |
- uses: actions/cache@v3 | |
name: Go modules cache | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Bindata cache | |
uses: actions/cache@v3 | |
id: generated-bindata | |
with: | |
path: | | |
.bins.linux.stamp | |
embedded-bins/staging/linux/bin/ | |
bindata_linux | |
pkg/assets/zz_generated_offsets_linux.go | |
embedded-bins/Makefile.variables | |
key: ${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }}-arm64 | |
restore-keys: | | |
${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }}-arm64 | |
- name: Build | |
run: make build | |
- name: Run test . | |
run: make check-basic | |
- name: Create airgap image list | |
run: make airgap-images.txt | |
- name: Cache airgap image bundle | |
id: cache-airgap-image-bundle | |
uses: actions/cache@v3 | |
with: | |
key: airgap-image-bundle-linux-arm64-${{ hashFiles('Makefile', 'airgap-images.txt', 'hack/image-bundler/*') }} | |
path: | | |
airgap-images.txt | |
airgap-image-bundle-linux-arm64.tar | |
- name: Create airgap image bundle if not cached | |
if: steps.cache-airgap-image-bundle.outputs.cache-hit != 'true' | |
run: make airgap-image-bundle-linux-arm64.tar | |
- name: Run airgap test | |
run: | | |
make --touch airgap-image-bundle-linux-arm64.tar | |
make check-airgap | |
- name: Collect test logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.cachePrefix }}-logs-check-basic-arm64-${{ github.run_number }} | |
path: | | |
/tmp/*.log | |
smoketest-armv7: | |
name: Smoke test on armv7 | |
runs-on: [self-hosted,linux,arm] | |
steps: | |
# We cannot rely on this as it's not working on arm, see https://github.com/actions/setup-go/issues/106 | |
# Instead we must have proper golang version setup at system level. | |
# - name: Set up Go 1.x | |
# uses: actions/setup-go@v3 | |
# with: | |
# go-version: ${{ env.GO_VERSION }} | |
# id: go | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Install GoLang for ARMHF | |
run: "echo $HOME/.local/go/bin >> $GITHUB_PATH; rm -rf $HOME/.local/go && mkdir -p $HOME/.local/go && curl --silent -L https://golang.org/dl/go$(make -s -f go_version.mk).linux-armv6l.tar.gz | tar -C $HOME/.local -xz" | |
- name: Go Version | |
run: go version | |
- name: Bindata cache | |
uses: actions/cache@v3 | |
id: generated-bindata | |
with: | |
path: | | |
.bins.linux.stamp | |
embedded-bins/staging/linux/bin/ | |
bindata_linux | |
pkg/assets/zz_generated_offsets_linux.go | |
embedded-bins/Makefile.variables | |
key: ${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }}-armv7 | |
restore-keys: | | |
${{ runner.os }}-embedded-bins-${{ hashFiles('**/embedded-bins/**/*') }}-armv7 | |
- name: Build | |
run: make build | |
- name: Run test . | |
run: TIMEOUT=15m make check-basic | |
- name: Create airgap image list | |
run: make airgap-images.txt | |
- name: Cache airgap image bundle | |
id: cache-airgap-image-bundle | |
uses: actions/cache@v3 | |
with: | |
key: airgap-image-bundle-linux-arm-${{ hashFiles('Makefile', 'airgap-images.txt', 'hack/image-bundler/*') }} | |
path: | | |
airgap-images.txt | |
airgap-image-bundle-linux-arm.tar | |
- name: Create airgap image bundle if not cached | |
if: steps.cache-airgap-image-bundle.outputs.cache-hit != 'true' | |
run: make airgap-image-bundle-linux-arm.tar | |
- name: Run airgap test | |
run: | | |
make --touch airgap-image-bundle-linux-arm.tar | |
make check-airgap | |
- name: Collect test logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.cachePrefix }}-logs-check-basic-armv7-${{ github.run_number }} | |
path: | | |
/tmp/*.log |