Skip to content

Commit b3d1338

Browse files
authored
make helm-publish workflow re-usable (#5682)
1 parent 08db8e9 commit b3d1338

File tree

2 files changed

+42
-79
lines changed

2 files changed

+42
-79
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -760,67 +760,18 @@ jobs:
760760

761761
publish-helm:
762762
name: Package and Publish Helm Chart
763-
runs-on: ubuntu-22.04
764763
needs: [checks, helm-tests]
765764
if: ${{ github.event_name == 'push' && ! startsWith(github.ref, 'refs/heads/release-') }}
766765
permissions:
767766
contents: write # for pushing to Helm Charts repository
768767
packages: write # for helm to push to GHCR
769-
steps:
770-
- name: Checkout Repository
771-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
772-
with:
773-
path: kic
774-
775-
- name: Login to GitHub Container Registry
776-
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
777-
with:
778-
registry: ghcr.io
779-
username: ${{ github.repository_owner }}
780-
password: ${{ secrets.GITHUB_TOKEN }}
781-
782-
- name: DockerHub Login
783-
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
784-
with:
785-
username: ${{ secrets.DOCKER_USERNAME }}
786-
password: ${{ secrets.DOCKER_PASSWORD }}
787-
788-
- name: Package
789-
id: package
790-
run: |
791-
helm_versions=""
792-
if [ ${{ github.ref_type }} != "tag" ]; then
793-
helm_versions="--app-version edge --version 0.0.0-edge"
794-
else
795-
helm_versions="--app-version ${{ needs.checks.outputs.ic_version }} --version ${{ needs.checks.outputs.chart_version }}"
796-
fi
797-
output=$(helm package ${helm_versions} kic/charts/nginx-ingress)
798-
echo "path=$(basename -- $(echo $output | cut -d: -f2))" >> $GITHUB_OUTPUT
799-
800-
- name: Push to OCI registries
801-
run: |
802-
helm push ${{ steps.package.outputs.path }} oci://ghcr.io/nginxinc/charts
803-
helm push ${{ steps.package.outputs.path }} oci://registry-1.docker.io/nginxcharts
804-
805-
- name: Checkout Repository
806-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
807-
with:
808-
repository: nginxinc/helm-charts
809-
fetch-depth: 1
810-
token: ${{ secrets.NGINX_PAT }}
811-
path: helm-charts
812-
if: github.ref_type == 'tag'
813-
814-
- name: Push Helm Chart to Helm Charts Repository
815-
run: |
816-
mv ${{ steps.package.outputs.path }} ${{ github.workspace }}/helm-charts/stable/
817-
cd ${{ github.workspace }}/helm-charts
818-
helm repo index stable --url https://helm.nginx.com/stable
819-
git add -A
820-
git -c user.name='NGINX Kubernetes Team' -c user.email='kubernetes@nginx.com' \
821-
commit -m "NGINX Ingress Controller - Release ${{ needs.checks.outputs.chart_version }}"
822-
git push -u origin master
823-
if: github.ref_type == 'tag'
768+
uses: ./.github/workflows/publish-helm.yml
769+
with:
770+
branch: ${{ github.ref_name }}
771+
ic_version: ${{ github.ref_type == 'tag' && needs.checks.outputs.ic_version || '0.0.0-edge' }}
772+
chart_version: ${{ github.ref_type == 'tag' && needs.checks.outputs.chart_version || 'edge' }}
773+
nginx_helm_repo: ${{ github.ref_type == 'tag' }}
774+
secrets: inherit
824775

825776
operator:
826777
name: Trigger PR for Operator

.github/workflows/publish-helm.yml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ on:
66
branch:
77
description: "Release Helm chart from branch"
88
required: true
9+
type: string
10+
ic_version:
11+
description: "Ingress Controller version"
12+
required: true
13+
type: string
14+
chart_version:
15+
description: "Helm Chart version"
16+
required: true
17+
type: string
18+
nginx_helm_repo:
19+
description: "Publish to the NGINX Helm repo"
20+
required: true
21+
type: boolean
22+
workflow_call:
23+
inputs:
24+
branch:
25+
description: "Release Helm chart from branch"
26+
required: true
27+
type: string
28+
ic_version:
29+
description: "Ingress Controller version"
30+
required: true
31+
type: string
32+
chart_version:
33+
description: "Helm Chart version"
34+
required: true
35+
type: string
36+
nginx_helm_repo:
37+
description: "Publish to the NGINX Helm repo"
38+
required: true
39+
type: boolean
940

1041
defaults:
1142
run:
@@ -19,30 +50,9 @@ permissions:
1950
contents: read
2051

2152
jobs:
22-
checks:
23-
name: Checks and variables
24-
runs-on: ubuntu-22.04
25-
outputs:
26-
chart_version: ${{ steps.vars.outputs.chart_version }}
27-
ic_version: ${{ steps.vars.outputs.ic_version }}
28-
steps:
29-
- name: Checkout Repository
30-
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
31-
with:
32-
ref: refs/heads/${{ inputs.branch }}
33-
34-
- name: Output Variables
35-
id: vars
36-
run: |
37-
source .github/data/version.txt
38-
echo "ic_version=${IC_VERSION}" >> $GITHUB_OUTPUT
39-
echo "chart_version=${HELM_CHART_VERSION}" >> $GITHUB_OUTPUT
40-
cat $GITHUB_OUTPUT
41-
4253
publish-helm:
4354
name: Package and Publish Helm Chart
4455
runs-on: ubuntu-22.04
45-
needs: [checks]
4656
permissions:
4757
contents: write # for pushing to Helm Charts repository
4858
packages: write # for helm to push to GHCR
@@ -69,7 +79,7 @@ jobs:
6979
- name: Package
7080
id: package
7181
run: |
72-
helm_versions="--app-version ${{ needs.checks.outputs.ic_version }} --version ${{ needs.checks.outputs.chart_version }}"
82+
helm_versions="--app-version ${{ inputs.ic_version }} --version ${{ inputs.chart_version }}"
7383
output=$(helm package ${helm_versions} kic/charts/nginx-ingress)
7484
echo "path=$(basename -- $(echo $output | cut -d: -f2))" >> $GITHUB_OUTPUT
7585
@@ -85,6 +95,7 @@ jobs:
8595
fetch-depth: 1
8696
token: ${{ secrets.NGINX_PAT }}
8797
path: helm-charts
98+
if: ${{ inputs.nginx_helm_repo == 'true' }}
8899

89100
- name: Push Helm Chart to Helm Charts Repository
90101
run: |
@@ -93,5 +104,6 @@ jobs:
93104
helm repo index stable --url https://helm.nginx.com/stable
94105
git add -A
95106
git -c user.name='NGINX Kubernetes Team' -c user.email='kubernetes@nginx.com' \
96-
commit -m "NGINX Ingress Controller - Release ${{ needs.checks.outputs.chart_version }}"
107+
commit -m "NGINX Ingress Controller - Release ${{ inputs.chart_version }}"
97108
git push -u origin master
109+
if: ${{ inputs.nginx_helm_repo == 'true' }}

0 commit comments

Comments
 (0)