11name : Publish to OperatorHub
22
33on :
4+ release :
5+ types : [published]
46 workflow_dispatch :
57 inputs :
6- version :
7- description : ' Operator version to publish (e.g., 0.88.0)'
8- required : false
9- type : string
108 tag :
11- description : ' Existing release tag to publish (e.g., v0.88.0)'
12- required : false
9+ description : ' Release tag to publish (e.g., v0.88.0)'
10+ required : true
1311 type : string
1412 create_pr :
1513 description : ' Create PR to OperatorHub (disable for testing)'
3129 contents : write
3230 pull-requests : write
3331 steps :
34- - name : Sanity check
35- if : ${{ github.event.inputs.tag == '' && github.event.inputs.version == '' }}
36- run : |
37- echo "You need to specify one parameter, version or a tag."
38- exit 1
39-
40- - name : Sanity check
41- if : ${{ github.event.inputs.tag != '' && github.event.inputs.version != '' }}
42- run : |
43- echo "You must not specify both version and a tag, only one of them."
44- exit 1
45-
4632 - name : Checkout kubernetes-nmstate
4733 uses : actions/checkout@v4
4834 with :
5440 go-version-file : ' go.mod'
5541
5642 - name : Extract version from tag
57- if : ${{ github.event.inputs.tag != '' }}
5843 id : version
5944 run : |
6045 if [ "${{ github.event_name }}" = "release" ]; then
7459
7560 echo "VERSION=$VERSION" >> $GITHUB_ENV
7661
77- - name : Validate version format
78- if : ${{ github.event.inputs.version != '' }}
79- run : |
80- VERSION="${{ github.event.inputs.version }}"
81- if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
82- echo "Error: Version must be in semver format (e.g., 0.88.0)"
83- exit 1
84- fi
85- echo "VERSION=$VERSION" >> $GITHUB_ENV
86-
8762 - name : Set image tags
8863 run : |
8964 echo "HANDLER_IMAGE_TAG=v${{ env.VERSION }}" >> $GITHUB_ENV
@@ -139,21 +114,21 @@ jobs:
139114 cat bundle/manifests/${{ env.OPERATOR_NAME }}.clusterserviceversion.yaml
140115
141116 - name : Checkout OperatorHub repository
142- if : ${{ github.event.inputs.create_pr == 'true' }}
117+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
143118 uses : actions/checkout@v4
144119 with :
145120 repository : k8s-operatorhub/community-operators
146121 path : operatorhub-repo
147122 token : ${{ secrets.OPERATORHUB_TOKEN }}
148123
149124 - name : Configure git
150- if : ${{ github.event.inputs.create_pr == 'true' }}
125+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
151126 run : |
152127 git config --global user.name "kubernetes-nmstate-bot"
153128 git config --global user.email "[email protected] " 154129
155130 - name : Create operator version directory
156- if : ${{ github.event.inputs.create_pr == 'true' }}
131+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
157132 run : |
158133 OPERATOR_DIR="operatorhub-repo/operators/${{ env.OPERATOR_NAME }}/${{ env.VERSION }}"
159134 mkdir -p "$OPERATOR_DIR"
@@ -170,7 +145,7 @@ jobs:
170145 echo "OPERATOR_DIR=$OPERATOR_DIR" >> $GITHUB_ENV
171146
172147 - name : Create and push PR branch
173- if : ${{ github.event.inputs.create_pr == 'true' }}
148+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
174149 working-directory : operatorhub-repo
175150 run : |
176151 BRANCH_NAME="kubernetes-nmstate-${{ env.VERSION }}"
@@ -181,7 +156,7 @@ jobs:
181156 echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
182157
183158 - name : Prepare PR body
184- if : ${{ github.event.inputs.create_pr == 'true' }}
159+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
185160 run : |
186161 cat > /tmp/pr-body.md <<'EOF'
187162 ## kubernetes-nmstate-operator version ${{ env.VERSION }}
@@ -205,7 +180,7 @@ jobs:
205180 EOF
206181
207182 - name : Create Pull Request
208- if : ${{ github.event.inputs.create_pr == 'true' }}
183+ if : ${{ github.event_name == 'release' || github. event.inputs.create_pr == 'true' }}
209184 env :
210185 GH_TOKEN : ${{ secrets.OPERATORHUB_TOKEN }}
211186 run : |
@@ -237,7 +212,7 @@ jobs:
237212 echo "- **Handler Image**: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.HANDLER_IMAGE_NAME }}:v${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
238213 echo "- **Operator Image**: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.OPERATOR_IMAGE_NAME }}:v${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
239214
240- if [ "${{ github.event.inputs.create_pr }}" = "true" ]; then
215+ if [ "${{ github.event_name }}" = "release" ] || [ "${{ github. event.inputs.create_pr }}" = "true" ]; then
241216 echo "- **Status**: PR created to OperatorHub - ${{ env.PR_URL }}" >> $GITHUB_STEP_SUMMARY
242217 else
243218 echo "- **Status**: Bundle generated (PR creation disabled)" >> $GITHUB_STEP_SUMMARY
0 commit comments