generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f47bff
commit ef3dbc8
Showing
25 changed files
with
1,986 additions
and
54 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,4 @@ | ||
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
# Ignore build and test binaries. | ||
bin/ | ||
testbin/ |
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,103 @@ | ||
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@v4 | ||
|
||
- name: Setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Check that license header boilerplate is correct | ||
uses: sap/cs-actions/check-go-license-boilerplate@main | ||
with: | ||
boilerplate-path: hack/boilerplate.go.txt | ||
|
||
- name: Check that license headers are correct | ||
uses: sap/cs-actions/check-go-license-headers@main | ||
with: | ||
boilerplate-path: hack/boilerplate.go.txt | ||
|
||
- 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 | ||
outputs: | ||
image-archive: image.tar | ||
image-repository: ${{ steps.prepare-repository-name.outputs.repository }} | ||
image-tag: ${{ steps.extract-metadata.outputs.version }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Prepare repository name | ||
id: prepare-repository-name | ||
run: | | ||
repository=$REGISTRY/${{ github.repository }} | ||
echo "repository=${repository,,}" >> $GITHUB_OUTPUT | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: extract-metadata | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ steps.prepare-repository-name.outputs.repository }} | ||
|
||
- 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 | ||
|
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,170 @@ | ||
name: Publish artifacts | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
concurrency: release-${{ github.event.release.tag_name }} | ||
|
||
env: | ||
SEMVER_VERSION: 3.4.0 | ||
REGISTRY: ghcr.io | ||
# CHART_REPOSITORY: | ||
# CHART_DIRECTORY: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
publish-docker: | ||
name: Publish Docker image | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
|
||
- name: Prepare repository name | ||
id: prepare-repository-name | ||
run: | | ||
repository=$REGISTRY/${{ github.repository }} | ||
echo "repository=${repository,,}" >> $GITHUB_OUTPUT | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: extract-metadata | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ steps.prepare-repository-name.outputs.repository }} | ||
|
||
- name: Build and push 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 | ||
push: true | ||
tags: ${{ steps.extract-metadata.outputs.tags }} | ||
labels: ${{ steps.extract-metadata.outputs.labels }} | ||
|
||
update-chart: | ||
name: Update Helm chart | ||
runs-on: ubuntu-22.04 | ||
needs: [publish-docker] | ||
|
||
steps: | ||
- name: Prepare | ||
id: prepare | ||
run: | | ||
chart_repository=$CHART_REPOSITORY | ||
if [ -z "$chart_repository" ]; then | ||
chart_repository=${{ github.repository }}-helm | ||
fi | ||
echo "chart_repository=$chart_repository" >> $GITHUB_OUTPUT | ||
chart_directory=$CHART_DIRECTORY | ||
if [ -z "$chart_directory" ]; then | ||
chart_directory=chart | ||
fi | ||
echo "chart_directory=$chart_directory" >> $GITHUB_OUTPUT | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Checkout chart repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ steps.prepare.outputs.chart_repository }} | ||
path: chart-repository | ||
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }} | ||
|
||
- name: Setup semver | ||
uses: sap/cs-actions/setup-semver@main | ||
with: | ||
version: ${{ env.SEMVER_VERSION }} | ||
install-directory: ${{ runner.temp }}/bin | ||
|
||
- name: Update chart repository | ||
id: update | ||
run: | | ||
cd chart-repository | ||
chart_directory=${{ steps.prepare.outputs.chart_directory }} | ||
old_version=$(yq .appVersion $chart_directory/Chart.yaml) | ||
if [ "${old_version:0:1}" != v ] || [ "$(semver validate $old_version)" != valid ]; then | ||
>&2 echo "Found invalid current appVersion ($old_version) in $chart_directory/Chart.yaml)." | ||
exit 1 | ||
fi | ||
new_version=${{ github.event.release.tag_name }} | ||
if [ "${new_version:0:1}" != v ] || [ "$(semver validate $new_version)" != valid ]; then | ||
>&2 echo "Invalid target appVersion ($new_version)." | ||
exit 1 | ||
fi | ||
if [ $(semver compare $new_version $old_version) -lt 0 ]; then | ||
echo "Target appVersion ($new_version) is lower than current appVersion ($old_version); skipping update ..." | ||
exit 0 | ||
fi | ||
version_bump=$(semver diff $new_version $old_version) | ||
echo "Found appVersion bump: $version_bump." | ||
if [ "$version_bump" != major ] && [ "$version_bump" != minor ]; then | ||
version_bump=patch | ||
fi | ||
echo "Performing chart version bump: $version_bump ..." | ||
echo "Updating appVersion in $chart_directory/Chart.yaml (current: $old_version; target: $new_version) ..." | ||
perl -pi -e "s#^appVersion:.*#appVersion: $new_version#g" $chart_directory/Chart.yaml | ||
if [ -z "$(git status --porcelain)" ]; then | ||
echo "Nothing has changed; skipping commit/push ..." | ||
exit 0 | ||
fi | ||
git config user.name "${{ vars.WORKFLOW_USER_NAME }}" | ||
git config user.email "${{ vars.WORKFLOW_USER_EMAIL }}" | ||
git add -A | ||
git commit -F- <<END | ||
Update chart (triggered by operator release $new_version) | ||
Repository: ${{ github.repository }} | ||
Release: ${{ github.event.release.tag_name }} | ||
Commit: ${{ github.sha }} | ||
END | ||
git push | ||
echo "version_bump=$version_bump" >> $GITHUB_OUTPUT | ||
# add some safety sleep to overcome github race conditions | ||
sleep 10s | ||
- name: Release chart repository | ||
if: steps.update.outputs.version_bump != '' | ||
uses: benc-uk/workflow-dispatch@v1 | ||
with: | ||
repo: ${{ steps.prepare.outputs.chart_repository }} | ||
workflow: release.yaml | ||
ref: main | ||
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }} | ||
inputs: '{ "version-bump": "${{ steps.update.outputs.version_bump }}" }' | ||
|
Oops, something went wrong.