-
Notifications
You must be signed in to change notification settings - Fork 11
134 lines (124 loc) · 4.12 KB
/
push_trigger.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Publish OpenG2P Helm charts on
on:
push:
tags-ignore:
- '**'
branches:
- 1.*
- develop
- main
workflow_dispatch:
inputs:
forcePublishCharts:
description: "Force publish Charts?"
default: "*"
type: string
jobs:
generate-charts:
runs-on: ubuntu-latest
env:
SKIP: 'FALSE'
RANCHER_CHART_FILTER: "openg2p.org/add-to-rancher"
FORCE_PUBLISH_CHARTS: "${{ inputs.forcePublishCharts || '' }}"
defaults:
run:
shell: bash
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- id: files
if: env.FORCE_PUBLISH_CHARTS == ''
uses: jitterbit/get-changed-files@v1
- name: save helm/charts to tmp.txt file
run: |
touch charts-list.txt
if [ -n "${FORCE_PUBLISH_CHARTS}" ]; then
for chart in charts/${FORCE_PUBLISH_CHARTS}/; do
chart="${chart#charts/}"
chart="${chart%/}"
echo "$chart" >> charts-list.txt
done
else
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ ${changed_file} =~ ^charts ]]; then
chart_name=$(echo "${changed_file}" | awk -F/ '/^[charts]/{print $2}')
echo $chart_name >> charts-list.txt;
echo "Saved $chart_name chart to charts-list.txt"
fi
done
cat charts-list.txt | sort | uniq > charts-list-unique.txt
mv charts-list-unique.txt charts-list.txt
fi
echo "List of charts to be published";
cat charts-list.txt
- name: Generate tar files
run: |
if [[ ! -s charts-list.txt ]]; then
echo "::warning::No Charts to publish";
echo "SKIP=TRUE" >> $GITHUB_ENV
else
for chartpath in charts/*/; do
if [ -f ${chartpath}Chart.yaml ]; then
helm dep up $chartpath
fi
done
RANCHER_CHARTS=()
while IFS= read -r chartpath; do
echo "chartpath: $chartpath"
chartname=$(basename "$chartpath")
if [ -f charts/${chartname}/Chart.yaml ]; then
echo "Chartname: $chartname"
helm package charts/$chartpath
is_rancher_chart=$(grep "$RANCHER_CHART_FILTER" charts/${chartpath%*/}/Chart.yaml || true)
if [ -n "$is_rancher_chart" ]; then
RANCHER_CHARTS+=("$chartname")
fi
fi
done < charts-list.txt
echo "RANCHER_CHARTS=${RANCHER_CHARTS[@]}" >> $GITHUB_ENV
rm charts-list.txt
fi
shopt -s nocasematch
if [[ '${{ github.repository_owner }}' != 'OpenG2P' ]]; then
echo "SKIP=TRUE" >> $GITHUB_ENV
fi
- name: Upload tar as Artifact
uses: actions/upload-artifact@v4
with:
name: charts
path: ./*.tgz
if: env.SKIP != 'TRUE'
- name: Checkout branch for publishing
uses: actions/checkout@v3
with:
repository: 'openg2p/openg2p-helm'
ref: gh-pages
token: ${{ secrets.OPENG2P_BOT_GITHUB_PAT }}
if: env.SKIP != 'TRUE'
- name: Download tar from Artifacts
uses: actions/download-artifact@v4
with:
name: charts
path: ./
if: env.SKIP != 'TRUE'
- name: Update index.yaml
run: |
helm repo index --url https://openg2p.github.io/openg2p-helm/ .
for chartname in $RANCHER_CHARTS; do
cp ${chartname}*.tgz rancher/
done
helm repo index --url https://openg2p.github.io/openg2p-helm/ --merge rancher/index.yaml rancher
for chartname in $RANCHER_CHARTS; do
rm rancher/${chartname}*.tgz || true
done
if: env.SKIP != 'TRUE'
- name: Commit Changes to repository
uses: EndBug/add-and-commit@v7
with:
branch: gh-pages
author_name: openg2pbot
author_email: [email protected]
default_author: user_info
message: 'added common helm charts for publish openg2p/openg2p-deployment@${{ github.sha }}'
add: './*.tgz ./index.yaml rancher/index.yaml'
if: env.SKIP != 'TRUE'