-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
103 lines (95 loc) · 3.39 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: "OpenShift operator PR"
description: "Submit PRs to OpenShift operator repositories"
branding:
icon: "git-pull-request"
color: "red"
inputs:
name:
description: "Operator name to submit."
required: true
version:
description: "Operator version to submit."
required: true
fork-repo-name:
description: "OpenShift operators fork repository name e.g.\"mariadb-operator/community-operators\"."
required: true
upstream-repo-name:
description: "OpenShift operators upstream repository name e.g.\"k8s-operatorhub/community-operators\"."
required: true
bundle-path-dir:
description: "Path to the OLM bundle directory."
required: true
ci-path-file:
description: "Path to the ci.yaml file."
required: true
user-name:
description: "User name to use in the commit."
required: false
default: "$GITHUB_ACTOR"
user-email:
description: "User email to use in the commit."
required: false
default: "[email protected]"
dry-run:
description: "Enable dry run mode."
required: false
default: "false"
draft:
description: "Enable draft mode."
required: false
default: "false"
runs:
using: 'composite'
steps:
- name: Check Runner OS
if: ${{ runner.os != 'Linux' }}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Linux Only"
exit 1
- name: Check GITHUB_TOKEN env
if: ${{ !env.GITHUB_TOKEN }}
shell: bash
run: |
echo "::error title=⛔ error hint::GITHUB_TOKEN environment variable is mandatory"
exit 1
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: "${{ inputs.fork-repo-name }}"
path: "fork-repo"
token: "${{ env.GITHUB_TOKEN }}"
- name: Upstream PR
shell: bash
env:
GITHUB_TOKEN: "${{ env.GITHUB_TOKEN }}"
run: |
echo "🚀 Switching directory"
ROOT_DIR=$(pwd)
cd "fork-repo"
echo "🚀 Setting up fork repo"
git config user.name "${{ inputs.user-name }}"
git config user.email "${{ inputs.user-email }}"
git remote add upstream "https://github.com/${{ inputs.upstream-repo-name }}"
git fetch --all
git reset --hard upstream/main
echo "🚀 Copying bundle"
mkdir -p "operators/${{ inputs.name }}/${{ inputs.version }}"
rsync -av --exclude="ci.yaml" "${ROOT_DIR}/${{ inputs.bundle-path-dir }}/" "operators/${{ inputs.name }}/${{ inputs.version }}"
echo "🚀 Copying ci.yaml"
cp "${ROOT_DIR}/${{ inputs.ci-path-file }}" "operators/${{ inputs.name }}/"
echo "🚀 Submitting PR"
git add .
git commit -m "operator ${{ inputs.name }}(${{ inputs.version }})" --signoff
git push -f
PR_CMD="gh pr create --repo '${{ inputs.upstream-repo-name }}' --title 'operator ${{ inputs.name }} (${{ inputs.version }})' --body 'Added operator ${{ inputs.name }} (${{ inputs.version }})'"
if [ "${{ inputs.dry-run }}" == "true" ]; then
PR_CMD="${PR_CMD} --dry-run"
fi
if [ "${{ inputs.draft }}" == "true" ]; then
PR_CMD="${PR_CMD} --draft"
fi
eval "${PR_CMD}"
echo "🚀 Switching back to root directory"
cd "${ROOT_DIR}"