Skip to content

Commit

Permalink
gh-action for olm bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <[email protected]>
  • Loading branch information
jkremser committed Oct 21, 2021
1 parent d060c56 commit fb4dddb
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/olm_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: OLM bundle and PR

on:
workflow_dispatch:
inputs:
bundleVersion:
description: Version of the bundle that should be generated. If not provided, the latest release tag is taken
required: false
default: ""
upstreamRepo:
description: "The pull request will be opened against this repository"
required: true
# default: "k8s-operatorhub/community-operators"
default: "jkremser/community-operators"
olmBundleToolVersion:
description: "Version of the olm-bundle tool that generate CSV file from Chart.yaml and yamls on FS"
required: false
default: "0.5.3"

jobs:
olm-bundle-pr:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get version
id: get_version
run: |
if [ "${{ github.event.inputs.bundleVersion }}x" == "x" ]; then
version=$(git describe --abbrev=0 --tags)
else
version=${{ github.event.inputs.bundleVersion }}
fi
echo "::set-output name=version::${version#v}"
- name: Generate OLM bundle
env:
TOOL_VERSION: ${{ github.event.inputs.olmBundleToolVersion }}
run: |
./olm/generate.sh ${{ steps.get_version.outputs.version }}
cp -r ./olm/bundle/ $GITHUB_WORKSPACE/
- uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.upstreamRepo }}
path: sandbox
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0

- name: Copy the generated manifests
run: |
mkdir -p $GITHUB_WORKSPACE/sandbox/community-operators/operators/k8gb/
cp -r $GITHUB_WORKSPACE/bundle $GITHUB_WORKSPACE/sandbox/community-operators/operators/k8gb/${{ github.event.inputs.bundleVersion }}
- name: Open Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GH_TOKEN }}
path: sandbox
commit-message: OLM bundle for k8gb@${{ github.event.inputs.bundleVersion }}
title: OLM bundle for k8gb@${{ github.event.inputs.bundleVersion }}
body: ':package:'
branch: k8gb-${{ github.event.inputs.bundleVersion }}
delete-branch: true
signoff: true

- name: Check PR
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ _site

# OLM
/olm/bundle
/olm/olm-bundle
64 changes: 58 additions & 6 deletions olm/generate.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
#!/bin/bash
[ "${DEBUG}" == 1 ] && set -x

DIR="${DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )}"
TOOL_VERSION=${TOOL_VERSION:-"0.5.3"}

helm -n placeholder template ${DIR}/../chart/k8gb \
--name-template=k8gb \
--set k8gb.securityContext.runAsUser=null \
--set k8gb.log.format=simple \
--set k8gb.log.level=info | olm-bundle --chart-file-path=${DIR}/../chart/k8gb/Chart.yaml --output-dir ${DIR}
main() {
# checks
[[ $# != 1 ]] && echo "Usage: $0 <version> # provide version in x.y.z format" && exit 1
_VERSION=$1
_VERSION=${_VERSION#"v"}

git checkout v${_VERSION}

_OS=${OS:-`uname | tr '[:upper:]' '[:lower:]'`}
_ARCH=""
case $(uname -m) in
x86_64) _ARCH="amd64" ;;
i386 | i686) _ARCH="386" ;;
arm) dpkg --print-architecture | grep -q "arm64" && _ARCH="arm64" || _ARCH="arm" ;;
*) echo "Unknown architecture: $(uname -m)" ; exit 1 ;;
esac

DIR="${DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )}"

if ! which olm-bundle > /dev/null; then
[ -f ${DIR}/olm-bundle ] || dlForked
OLM_BINARY="${DIR}/olm-bundle"
else
OLM_BINARY="olm-bundle"
# OLM_BINARY="/Users/ab017z6/workspace/olm-bundle/_output/bin/darwin_amd64/olm-bundle"
fi

generate
}

generate() {
cd ${DIR}/../chart/k8gb && helm dependency update && cd -
helm -n placeholder template ${DIR}/../chart/k8gb \
--name-template=k8gb \
--set k8gb.securityContext.runAsUser=null \
--set k8gb.log.format=simple \
--set k8gb.log.level=info | ${OLM_BINARY} \
--chart-file-path=${DIR}/../chart/k8gb/Chart.yaml \
--version=${_VERSION} \
--output-dir ${DIR}
}

dlUpstream() {
# upstream
_VERSION="0.5.2"
curl -Lo ${DIR}/olm-bundle https://github.com/upbound/olm-bundle/releases/download/v${_VERSION}/olm-bundle_${_OS}-${_ARCH}
chmod +x ${DIR}/olm-bundle
}

dlForked() {
# our fork
curl -Ls https://github.com/AbsaOSS/olm-bundle/releases/download/v${_VERSION}/olm-bundle_${_VERSION}_${_OS}_${_ARCH}.tar.gz | tar -xz
mv ${DIR}/bin/olm-bundle ${DIR}/olm-bundle
}

main $@

0 comments on commit fb4dddb

Please sign in to comment.