Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(operator): adds reusable workflow for opening PRs to hub repos #12149

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/operator-publish-operator-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Publish release on operator hub"
on:
release:
types: [published]

jobs:
operator-hub-prod-release:
if: startsWith(github.event.release.tag_name, 'operator/')
uses: ./.github/workflows/operator-reusable-hub-release.yaml
with:
org: redhat-openshift-ecosystem
repo: community-operators-prod
secrets:
GRAFANABOT_GITHUB_TOKEN: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}
JoaoBraveCoding marked this conversation as resolved.
Show resolved Hide resolved

operator-hub-community-release:
if: startsWith(github.event.release.tag_name, 'operator/')
uses: ./.github/workflows/operator-reusable-hub-release.yaml
with:
org: k8s-operatorhub
repo: community-operators
secrets:
GRAFANABOT_GITHUB_TOKEN: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}
110 changes: 110 additions & 0 deletions .github/workflows/operator-reusable-hub-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Reusable - Create operator hub pull request

on:
workflow_call:
inputs:
org:
type: string
required: true
repo:
type: string
required: true
secrets:
GRAFANABOT_GITHUB_TOKEN:
required: true

jobs:
create-operator-pull-request:
runs-on: ubuntu-latest
steps:
- name: Set redhat-openshift-ecosystem specific variables
if: ${{ inputs.org == 'redhat-openshift-ecosystem' }}
env:
ocpDir: '/path/to/openshift/directory'
ocpSupportedVersions: 'v4.12'
run: |
echo "ocpDir=${ocpDir}" >> $GITHUB_ENV
echo "ocpSupportedVersions=${ocpSupportedVersions}" >> $GITHUB_ENV

- name: Set version as env variable
env:
TAG: ${{ github.ref_name }}
run: |
echo $TAG
TAG=${TAG:10} # remove "operator/v" (prefix)
echo version=${TAG} >> $GITHUB_ENV # update GitHub ENV vars

- name: Sync fork
env:
GH_TOKEN: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}
run: |
# synchronizing the fork is fast, and avoids the need to fetch the full upstream repo
# (fetching the upstream repo with "--depth 1" would lead to "shallow update not allowed"
# error when pushing back to the origin repo)
gh repo sync grafanabot/${{ inputs.repo }} \
--source ${{ inputs.org }}/${{ inputs.repo }} \
--force

- name: Checkout operatorhub repo
uses: actions/checkout@v4
with:
repository: grafanabot/${{ inputs.repo }}
token: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}

- name: Checkout loki to tmp/ directory
uses: actions/checkout@v4
with:
repository: grafana/loki
token: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}
path: tmp/

- name: Update version
env:
VERSION: ${{ env.version }}
OCP_DIR: ${{ env.ocpDir || ''}}
run: |
mkdir operators/loki-operator/${VERSION}
cp -R ./tmp/operator/bundle/community${OCP_DIR}/* oOCP_DIR}/* opperators/loki-operator/${VERSION}
rm -f "operators/loki-operator/${VERSION}/bundle.Dockerfile"
rm -rf ./tmp

- name: Add OpenShift Supported versions to redhat catalog
if: ${{ inputs.org == 'redhat-openshift-ecosystem' }}
env:
VERSION: ${{ env.version }}
OCP_SUPPORTED_VERSIONS: ${{ env.ocpSupportedVersions || ''}}
uses: fjogeleit/yaml-update-action@main
with:
valueFile: "./operators/loki-operator/${VERSION}/metadata/annotations.yaml"
propertyPath: "annotations['com.redhat.openshift.versions']"
value: ${OCP_SUPPORTED_VERSIONS}

- name: Use CLA approved github bot
run: |
git config user.name grafanabot
git config user.email [email protected]

- name: Create pull request against ${{ inputs.org }}/${{ inputs.repo }}
env:
VERSION: ${{ env.version }}
GH_TOKEN: ${{ secrets.GRAFANABOT_GITHUB_TOKEN }}
run: |
message="Update the loki-operator to $VERSION"
body="Release loki-operator \`$VERSION\`.

cc @periklis @xperimental @JoaoBraveCoding @btaani @shwetaap
"
branch="update-loki-operator-to-${VERSION}"

# gh pr create doesn't have a way to explicitly specify different head and base
# repositories currently, but it will implicitly pick up the head from a different
# repository if you set up a tracking branch

git checkout -b $branch
git add -A
git commit -s -m "$message"
git push -f --set-upstream origin $branch
gh pr create --title "$message" \
--body "$body" \
--repo ${{ inputs.org }}/${{ inputs.repo }} \
--base main
10 changes: 0 additions & 10 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ LOKI_OPERATOR_NS ?= kubernetes-operators
VERSION ?= 0.5.0
CHANNELS ?= "alpha"
DEFAULT_CHANNEL ?= "alpha"
SUPPORTED_OCP_VERSIONS="v4.12"

# REGISTRY_BASE
# defines the container registry and organization for the bundle and operator container images.
Expand Down Expand Up @@ -344,15 +343,6 @@ web: $(HUGO) | web-pre ## Run production build of the loki-operator.dev website
web-serve: $(HUGO) | web-pre ## Run local preview version of the loki-operator.dev website
@cd $(WEBSITE_DIR) && $(HUGO) serve

.PHONY: operatorhub
operatorhub: check-operatorhub-pr-template
SUPPORTED_OCP_VERSIONS="$(SUPPORTED_OCP_VERSIONS)" ./hack/operatorhub.sh

.PHONY: check-operatorhub-pr-template
check-operatorhub-pr-template:
curl https://raw.githubusercontent.com/operator-framework/community-operators/master/docs/pull_request_template.md -o hack/.operatorhub-pr-template.md -s > /dev/null 2>&1
git diff -s --exit-code hack/.operatorhub-pr-template.md || (echo "Build failed: the PR template for OperatorHub has changed. Sync it and try again." && exit 1)

JSONNET_SRC = $(shell find . -type f -not -path './jsonnet/vendor/*' \( -name '*.libsonnet' -o -name '*.jsonnet' \))
JSONNET_VENDOR_DIR = jsonnet/vendor

Expand Down
75 changes: 0 additions & 75 deletions operator/hack/operatorhub.sh

This file was deleted.

Loading