Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarbian-sap committed Jul 14, 2023
1 parent de73c36 commit bed193c
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 143 deletions.
172 changes: 172 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
name: Build artifacts

on:
push:
branches:
- main

pull_request:
branches:
- main

concurrency: build-${{ github.ref }}

env:
REGISTRY: ghcr.io

defaults:
run:
shell: bash

jobs:
test:
name: Run tests
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Check that license header boilerplate is correct
run: |
this_year=$(date +%Y)
last_year=$((this_year-1))
repository=$(echo ${{ github.repository }} | cut -d/ -f2)
boilerplate=hack/boilerplate.go.txt
tempdir=$(mktemp -d)
trap 'rm -rf $tempdir' EXIT
cat > $tempdir/boilerplate-this-year <<END
/*
SPDX-FileCopyrightText: $this_year SAP SE or an SAP affiliate company and $repository contributors
SPDX-License-Identifier: Apache-2.0
*/
END
cat > $tempdir/boilerplate-last-year <<END
/*
SPDX-FileCopyrightText: $last_year SAP SE or an SAP affiliate company and $repository contributors
SPDX-License-Identifier: Apache-2.0
*/
END
if diff -q $boilerplate $tempdir/boilerplate-this-year >/dev/null; then
exit 0
fi
if diff -q $boilerplate $tempdir/boilerplate-last-year >/dev/null; then
>&1 echo "Warning: license boilerplate outdated ($last_year); next year, this will result in an error."
exit 0
fi
>&1 echo "Error: incorrect license boilerplate."
exit 1
END
- name: Check that license headers are correct
run: |
boilerplate=hack/boilerplate.go.txt
tempdir=$(mktemp -d)
trap 'rm -rf $tempdir' EXIT
boilerplate_linecount=$(wc -l $boilerplate | awk '{print $1}')
errors=0
for f in $(find . -name "*.go"); do
if head -n 1 $f | grep -q "!ignore_autogenerated"; then
continue
fi
head -n $boilerplate_linecount $f > $tempdir/out
if ! diff -q $tempdir/out $boilerplate >/dev/null; then
>&1 echo "Error: incorrect license header found in $f."
errors=$((errors+1))
fi
rm -f $tempdir/out
done
if [ $errors -gt 0 ]; then
exit 1
fi
- name: Check that generated artifacts are up-to-date
run: |
make generate
echo "Running 'git status' ..."
git status --porcelain | tee status.out
if [[ -s status.out ]]; then
>&1 echo "Generated artifacts are not up-to-date; probably 'make generate' was not run before committing."
exit 1
else
echo "Generated artifacts are up-to-date."
fi
- name: Check that manifests are up-to-date
run: |
make manifests
echo "Running 'git status' ..."
git status --porcelain | tee status.out
if [[ -s status.out ]]; then
>&1 echo "Manifests are not up-to-date; probably 'make manifests' was not run before committing."
exit 1
else
echo "Manifests are up-to-date."
fi
- name: Run tests
run: |
make envtest
KUBEBUILDER_ASSETS=$(pwd)/bin/k8s/current E2E_ENABLED=${{ github.event_name == 'push' }} go test -count 1 ./...
build-docker:
name: Build Docker image
runs-on: ubuntu-22.04
needs: test
permissions:
contents: read
env:
IMAGE_NAME: ${{ github.repository }}
outputs:
image-archive: image.tar
image-repository: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
image-tag: ${{ steps.extract-metadata.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Extract metadata (tags, labels) for Docker
id: extract-metadata
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build Docker image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
context: .
cache-from: |
type=gha,scope=sha-${{ github.sha }}
type=gha,scope=${{ github.ref_name }}
type=gha,scope=${{ github.base_ref || 'main' }}
type=gha,scope=main
cache-to: |
type=gha,scope=sha-${{ github.sha }},mode=max
type=gha,scope=${{ github.ref_name }},mode=max
outputs: |
type=oci,dest=${{ runner.temp }}/image.tar
tags: ${{ steps.extract-metadata.outputs.tags }}
labels: ${{ steps.extract-metadata.outputs.labels }}

- name: Upload Docker image archive
uses: actions/upload-artifact@v3
with:
name: image.tar
path: ${{ runner.temp }}/image.tar
141 changes: 13 additions & 128 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ on:
release:
types: [published]

push:
branches:
- main

pull_request:
branches:
- main

# note: we do not use any concurrency here, in order to avoid queued release workflows being cancelled by
# higher priority push/pull_request workflows
concurrency: release-${{ github.event.release.tag_name }}

env:
REGCTL_VERSION: v0.4.8
Expand All @@ -27,112 +18,9 @@ defaults:
shell: bash

jobs:
test:
name: Run tests
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Check that license header boilerplate is correct
run: |
this_year=$(date +%Y)
last_year=$((this_year-1))
repository=$(echo ${{ github.repository }} | cut -d/ -f2)
boilerplate=hack/boilerplate.go.txt
tempdir=$(mktemp -d)
trap 'rm -rf $tempdir' EXIT
cat > $tempdir/boilerplate-this-year <<END
/*
SPDX-FileCopyrightText: $this_year SAP SE or an SAP affiliate company and $repository contributors
SPDX-License-Identifier: Apache-2.0
*/
END
cat > $tempdir/boilerplate-last-year <<END
/*
SPDX-FileCopyrightText: $last_year SAP SE or an SAP affiliate company and $repository contributors
SPDX-License-Identifier: Apache-2.0
*/
END
if diff -q $boilerplate $tempdir/boilerplate-this-year >/dev/null; then
exit 0
fi
if diff -q $boilerplate $tempdir/boilerplate-last-year >/dev/null; then
>&1 echo "Warning: license boilerplate outdated ($last_year); next year, this will result in an error."
exit 0
fi
>&1 echo "Error: incorrect license boilerplate."
exit 1
END
- name: Check that license headers are correct
run: |
boilerplate=hack/boilerplate.go.txt
tempdir=$(mktemp -d)
trap 'rm -rf $tempdir' EXIT
boilerplate_linecount=$(wc -l $boilerplate | awk '{print $1}')
errors=0
for f in $(find . -name "*.go"); do
if head -n 1 $f | grep -q "!ignore_autogenerated"; then
continue
fi
head -n $boilerplate_linecount $f > $tempdir/out
if ! diff -q $tempdir/out $boilerplate >/dev/null; then
>&1 echo "Error: incorrect license header found in $f."
errors=$((errors+1))
fi
rm -f $tempdir/out
done
if [ $errors -gt 0 ]; then
exit 1
fi
- name: Check that generated artifacts are up-to-date
run: |
make generate
echo "Running 'git status' ..."
git status --porcelain | tee status.out
if [[ -s status.out ]]; then
>&1 echo "Generated artifacts are not up-to-date; probably 'make generate' was not run before committing."
exit 1
else
echo "Generated artifacts are up-to-date."
fi
- name: Check that manifests are up-to-date
run: |
make manifests
echo "Running 'git status' ..."
git status --porcelain | tee status.out
if [[ -s status.out ]]; then
>&1 echo "Manifests are not up-to-date; probably 'make manifests' was not run before committing."
exit 1
else
echo "Manifests are up-to-date."
fi
- name: Run tests
run: |
make envtest
KUBEBUILDER_ASSETS=$(pwd)/bin/k8s/current E2E_ENABLED=${{ github.event_name == 'release' }} go test -count 1 ./...
build-docker:
name: Build Docker image
publish-docker:
name: Publish Docker image
runs-on: ubuntu-22.04
needs: test
permissions:
contents: read
packages: write
Expand All @@ -143,7 +31,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
Expand All @@ -154,12 +42,12 @@ jobs:
password: ${{ github.token }}

- name: Extract metadata (tags, labels) for Docker
id: meta
id: extract-metadata
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
Expand All @@ -172,15 +60,13 @@ jobs:
cache-to: |
type=gha,scope=sha-${{ github.sha }},mode=max
type=gha,scope=${{ github.ref_name }},mode=max
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.extract-metadata.outputs.tags }}
labels: ${{ steps.extract-metadata.outputs.labels }}

build-crds:
name: Build CRD image
publish-crds:
name: Publish CRD image
runs-on: ubuntu-22.04
needs: test
if: github.event_name == 'release'
permissions:
contents: read
packages: write
Expand All @@ -205,7 +91,7 @@ jobs:
run: |
regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }}
- name: Build artifact
- name: Build and push artifact
run: |
cd crds
repository=${{ github.repository }}/crds
Expand All @@ -214,8 +100,7 @@ jobs:
update-chart:
name: Update Helm chart
runs-on: ubuntu-22.04
needs: [build-docker,build-crds]
if: github.event_name == 'release'
needs: [publish-docker,publish-crds]

steps:
- name: Prepare
Expand Down
Loading

0 comments on commit bed193c

Please sign in to comment.