Skip to content

Commit 52c8425

Browse files
committed
Initial commit
1 parent 8c04918 commit 52c8425

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
11
# openshift-operator-pr
2-
GitHub action to submit PRs to OpenShift operator repositories
2+
3+
GitHub action to submit PRs to OpenShift operator repositories.
4+
5+
### Operator repositories
6+
7+
- [k8s-operatorhub/community-operators](https://github.com/k8s-operatorhub/community-operators)
8+
- [redhat-openshift-ecosystem/community-operators-prod](https://github.com/redhat-openshift-ecosystem/community-operators-prod)
9+
- [redhat-openshift-ecosystem/certified-operators](https://github.com/redhat-openshift-ecosystem/certified-operators)
10+
11+
### Before using this action
12+
13+
You must fork the [operator repositories](#operator-repositories) you are willing to submit your operator to.
14+
15+
### Usage
16+
17+
```yaml
18+
name: Release
19+
20+
on:
21+
push:
22+
tags:
23+
- "*"
24+
25+
jobs:
26+
operator-pr:
27+
name: Version
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Fetch tags
36+
run: git fetch --force --tags
37+
38+
- name: Get Version
39+
id: version
40+
run: |
41+
VERSION=sha-${GITHUB_SHA::8}
42+
if [[ $GITHUB_REF == refs/tags/* ]]; then
43+
VERSION=${GITHUB_REF/refs\/tags\//}
44+
fi
45+
echo ::set-output name=version::${VERSION}
46+
47+
# TODO:
48+
# - Generate bundle
49+
# - Push bundle image to a registry
50+
51+
- name: Operator PR
52+
uses: mariadb-operator/openshift-operator-pr@v0.0.1
53+
with:
54+
name: "mariadb-operator"
55+
version: "${{ steps.version.outputs.version }}"
56+
fork-repo-name: "mariadb-operator/community-operators"
57+
upstream-repo-url: "https://github.com/k8s-operatorhub/community-operators"
58+
bundle-path-dir: "bundle"
59+
ci-path-file: "ci.yaml"
60+
user-name: "Martin Montes"
61+
user-email: "martin11lrx@gmail.com"
62+
```

action.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "OpenShift operator PR"
2+
description: "Submit PRs to OpenShift operator repositories"
3+
branding:
4+
icon: "git-pull-request"
5+
color: "red"
6+
inputs:
7+
name:
8+
description: "Operator name to submit."
9+
required: true
10+
version:
11+
description: "Operator version to submit."
12+
required: true
13+
fork-repo-name:
14+
description: "OpenShift operators fork repository name e.g.\"mariadb-operator/community-operators\"."
15+
required: true
16+
upstream-repo-url:
17+
description: "OpenShift operators upstream repository https URL e.g.\"https://github.com/k8s-operatorhub/community-operators\"."
18+
required: true
19+
bundle-path-dir:
20+
description: "Path to the OLM bundle directory."
21+
required: true
22+
ci-path-file:
23+
description: "Path to the ci.yaml file"
24+
required: true
25+
user-name:
26+
description: "User name to use in the commit."
27+
required: false
28+
default: "$GITHUB_ACTOR"
29+
user-email:
30+
description: "User email to use in the commit."
31+
required: false
32+
default: "$GITHUB_ACTOR@users.noreply.github.com"
33+
runs:
34+
using: 'composite'
35+
steps:
36+
- name: Check Runner OS
37+
if: ${{ runner.os != 'Linux' }}
38+
shell: bash
39+
run: |
40+
echo "::error title=⛔ error hint::Support Linux Only"
41+
exit 1
42+
43+
- name: Check GITHUB_TOKEN env
44+
if: ${{ env.GITHUB_TOKEN == '' }}
45+
shell: bash
46+
run: |
47+
echo "::error title=⛔ error hint::GITHUB_TOKEN environment variable is mandatory"
48+
exit 1
49+
50+
- name: Checkout fork
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
repository: "${{ inputs.fork-repo-name }}"
55+
path: "."
56+
token: "${{ secrets.GITHUB_TOKEN }}"
57+
58+
- name: Configure Git
59+
shell: bash
60+
run: |
61+
git config user.name "${{ inputs.user-name }}"
62+
git config user.email "${{ inputs.user-email }}"
63+
64+
- name: Upstream PR
65+
shell: bash
66+
env:
67+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
68+
run: |
69+
echo "🚀 Setting up upstream"
70+
git remote add upstream "${{ inputs.upstream-repo-url }}"
71+
git fetch --all
72+
git reset --hard upstream/main
73+
74+
echo "🚀 Copying bundle"
75+
mkdir -p "operators/${{ inputs.name }}/${{ inputs.version }}"
76+
cp -Tr "${{ inputs.bundle-path-dir }}" "operators/${{ inputs.name }}/${{ inputs.version }}"
77+
78+
echo "🚀 Copying ci.yaml"
79+
cp "${{ inputs.ci-path-file }}" "operators/${{ inputs.name }}/"
80+
81+
echo "🚀 Submitting PR"
82+
git add .
83+
git commit -m "operator ${{ inputs.name }}(${{ inputs.version }})" --signoff
84+
git push -f
85+
gh pr create --repo $UPSTREAM_REPO \
86+
--title "operator ${{ inputs.name }} (${{ inputs.version }})" \
87+
--body "Added operator ${{ inputs.name }} (${{ inputs.version }})"

0 commit comments

Comments
 (0)