Skip to content

Commit

Permalink
Merge pull request #125 from stakater/operator-PR
Browse files Browse the repository at this point in the history
Generic Operator Pull Request workflow
  • Loading branch information
rasheedamir authored Oct 4, 2024
2 parents 9438796 + 8b80c75 commit b62486c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 16 deletions.
67 changes: 60 additions & 7 deletions .github/workflows/operator_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,42 @@ on:
required: false
type: string

Run_GOLANG_CI_LINT:
description: Run golangci-lint
default: true
required: false
type: boolean

GOLANG_CI_LINT_VERSION:
description: golang-ci-lint version to use
default: "v1.50.1"
default: "v1.53.3"
required: false
type: string


RUN_GOLANG_TESTS:
description: Run golang tests
default: true
required: false
type: boolean

DOCKERFILE_PATH:
description: Dockerfile path
required: true
type: string

HELM_CHARTS_PATH:
description: Helm charts path
required: true
required: false
type: string

HELM_CHART_TEMPLATE_NAME:
description: Helm template chart name
required: true
required: false
type: string

HELM_CHART_NAMESPACE_NAME:
description: Helm chart namespace name for templates
required: true
required: false
type: string

HELM_VERSION:
Expand All @@ -41,6 +53,18 @@ on:
required: false
type: string

BUILD_CUSTOM_CATALOG:
description: Build custom catalog
default: false
required: false
type: boolean

OPERATOR_SDK_VERSION:
description: Operator SDK version to use
default: "v1.32.0"
required: false
type: string

secrets:
SLACK_WEBHOOK_URL:
description: "Secret to send success/failure message to slack"
Expand Down Expand Up @@ -90,24 +114,29 @@ jobs:
go-version: ${{ inputs.GOLANG_VERSION }}

- name: Lint
uses: golangci/golangci-lint-action@v6
if: ${{ inputs.Run_GOLANG_CI_LINT }}
uses: golangci/golangci-lint-action@v3
with:
version: ${{ inputs.GOLANG_CI_LINT_VERSION }}
only-new-issues: false
args: --timeout 10m
skip-pkg-cache: true

# Run Tests
- name: Test
if: ${{ inputs.RUN_GOLANG_TESTS }}
run: make test

# Set up helm binary
- name: Set up Helm
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
uses: azure/setup-helm@v4
with:
version: ${{ inputs.HELM_VERSION }}

# Test Helm Templating
- name: Test Helm Template
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
run: |
helm dependency build ${{ inputs.HELM_CHARTS_PATH }}
helm template ${{ inputs.HELM_CHART_TEMPLATE_NAME }} ${{ inputs.HELM_CHARTS_PATH }} -n ${{ inputs.HELM_CHART_NAMESPACE_NAME }}
Expand All @@ -128,7 +157,7 @@ jobs:
driver-opts: |
image=moby/buildkit:v0.9.3
buildkitd-flags: --debug

- name: Login to Registry
uses: docker/login-action@v3
with:
Expand All @@ -142,6 +171,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v6
id: build_and_push
with:
context: .
file: ${{ inputs.DOCKERFILE_PATH }}
Expand All @@ -154,6 +184,29 @@ jobs:
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.revision=${{ github.sha }}
# Build custom catalog
- name: Generate Tag
if: ${{ inputs.BUILD_CUSTOM_CATALOG }}
id: generate_tag_for_catalog
run: |
sha=${{ github.event.pull_request.head.sha }}
tag="${sha:0:8}"
echo "GIT_TAG=$(echo ${tag})" >> $GITHUB_OUTPUT
- name: Install CLI tools from OpenShift Mirror
if: ${{ inputs.BUILD_CUSTOM_CATALOG }}
uses: redhat-actions/openshift-tools-installer@v1
with:
source: "github"
operator-sdk: ${{ inputs.OPERATOR_SDK_VERSION }}

- name: Build and Push Bundle and Catalog
if: ${{ inputs.BUILD_CUSTOM_CATALOG }}
run: make custom-bundle bundle-build bundle-push catalog-build catalog-push
env:
IMAGE_DIGEST: ${{ steps.build_and_push.outputs.digest }}
PR_TAG: -${{ steps.generate_tag_for_catalog.outputs.GIT_TAG }}

- name: Comment on PR
uses: mshick/add-pr-comment@v2
if: always()
Expand Down
69 changes: 60 additions & 9 deletions .github/workflows/operator_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ on:
required: false
type: string

RUN_GOLANG_CI_LINT:
description: Run golangci-lint
default: true
required: false
type: boolean

GOLANG_CI_LINT_VERSION:
description: golang-ci-lint version to use
default: "v1.50.1"
default: "v1.53.3"
required: false
type: string

RUN_GOLANG_TESTS:
description: Run golang tests
default: true
required: false
type: boolean

HELM_VERSION:
description: Helm version to use
default: "v3.8.2"
Expand All @@ -28,24 +40,38 @@ on:

HELM_CHARTS_PATH:
description: Helm charts path
required: true
required: false
type: string

BOT_USERNAME:
description: Bot username to create release
required: true
default: "stakater-github-root"
required: false
type: string

BOT_EMAIL:
description: Bot email to create release
required: true
default: "[email protected]"
required: false
type: string

RELEASE_BRANCH:
description: Release branch to push changes
required: true
type: string

BUILD_CUSTOM_CATALOG:
description: Build custom catalog
default: false
required: false
type: boolean

OPERATOR_SDK_VERSION:
description: Operator SDK version to use
default: "v1.32.0"
required: false
type: string

secrets:
ADMIN_TOKEN:
description: "Secret to pull latest tag"
Expand All @@ -69,15 +95,15 @@ on:

HELM_REGISTRY_URL:
description: "Helm registry to publish helm chart"
required: true
required: false

HELM_REGISTRY_USERNAME:
description: "Username to login to helm registry"
required: true
required: false

HELM_REGISTRY_PASSWORD:
description: "Password to login to helm registry"
required: true
required: false

jobs:
push-operator-setup:
Expand All @@ -98,6 +124,7 @@ jobs:
fi
- name: Check if helm registry secrets are set
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
run: |
if [ "${{ secrets.HELM_REGISTRY_URL }}" == "" ] || [ "${{ secrets.HELM_REGISTRY_USERNAME }}" == "" ] || [ "${{ secrets.HELM_REGISTRY_PASSWORD }}" == "" ]; then
echo "Required secrets 'HELM_REGISTRY_URL' or 'HELM_REGISTRY_USERNAME' or 'HELM_REGISTRY_PASSWORD' are not set!"
Expand All @@ -118,6 +145,7 @@ jobs:
go-version: ${{ inputs.GOLANG_VERSION }}

- name: Lint
if: ${{ inputs.RUN_GOLANG_CI_LINT }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ inputs.GOLANG_CI_LINT_VERSION }}
Expand All @@ -126,6 +154,7 @@ jobs:

# Run Tests
- name: Test
if: ${{ inputs.RUN_GOLANG_TESTS }}
run: make test

- name: Generate Tag
Expand Down Expand Up @@ -167,6 +196,7 @@ jobs:

# Set up helm binary
- name: Set up Helm
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
uses: azure/setup-helm@v4
with:
version: ${{ inputs.HELM_VERSION }}
Expand All @@ -184,7 +214,7 @@ jobs:
driver-opts: |
image=moby/buildkit:v0.9.3
buildkitd-flags: --debug

- name: Login to Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -194,6 +224,7 @@ jobs:

- name: Build and push
uses: docker/build-push-action@v6
id: build_and_push
with:
context: .
file: ${{ inputs.DOCKERFILE_PATH }}
Expand All @@ -206,17 +237,35 @@ jobs:
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.revision=${{ github.sha }}
# Build custom catalog
- name: Install CLI tools from OpenShift Mirror
if: ${{ inputs.BUILD_CUSTOM_CATALOG }}
uses: redhat-actions/openshift-tools-installer@v1
with:
source: "github"
operator-sdk: ${{ inputs.OPERATOR_SDK_VERSION }}

- name: Build and Push Bundle and Catalog
if: ${{ inputs.BUILD_CUSTOM_CATALOG }}
run: make custom-bundle bundle-build bundle-push catalog-build catalog-push
env:
IMAGE_DIGEST: ${{ steps.build_and_push.outputs.digest }}
VERSION: ${{ needs.push-operator-setup.outputs.new_tag_without_v }}

# Update chart tag to the latest semver tag
- name: Update Chart Version
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
env:
VERSION: ${{ needs.push-operator-setup.outputs.new_tag_without_v }}
run: make bump-chart

- name: Update Chart CRDs
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
run: make generate-crds

# Publish helm chart
- name: Publish Helm chart
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
run: |
helm dependency build ${{ inputs.HELM_CHARTS_PATH }}
helm package ${{ inputs.HELM_CHARTS_PATH }} --destination ./packaged-chart
Expand All @@ -225,6 +274,7 @@ jobs:
# Commit back changes
- name: Commit files
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
run: |
git config --local user.email "${{ inputs.BOT_EMAIL }}"
git config --local user.name "${{ inputs.BOT_USERNAME }}"
Expand All @@ -233,6 +283,7 @@ jobs:
git commit -m "[skip-ci] Update artifacts" -a
- name: Push changes
if: ${{ inputs.HELM_CHARTS_PATH != '' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.ADMIN_TOKEN }}
Expand Down Expand Up @@ -263,4 +314,4 @@ jobs:
status: ${{ job.status }}
fields: repo,author,action,eventName,ref,workflow
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

0 comments on commit b62486c

Please sign in to comment.