9
9
matrix-setup :
10
10
runs-on : ubuntu-latest
11
11
outputs :
12
- matrix : ${{ steps.matrix.outputs.value }}
12
+ matrix : ${{ steps.matrix.outputs.matrix }}
13
13
steps :
14
- - name : Checkout code
15
- uses : actions/checkout@v4
16
- - id : matrix
17
- run : |
18
- echo "value=$(jq -c < repositories.json | jq -R | sed -e 's/^"//' -e 's/"$//')" >> $GITHUB_OUTPUT
19
- - run : |
20
- echo "${{ steps.matrix.outputs.value }}"
14
+ - name : Checkout
15
+ uses : actions/checkout@v3
16
+
17
+ - name : Get Matrix
18
+ id : matrix
19
+ uses : Surnet/get-json-matrix@v1
20
+ with :
21
+ filepath : ./repositories.json
21
22
22
23
check-and-publish-helm-charts :
23
- needs : ["matrix-setup"]
24
+ name : ${{ matrix.key }}
25
+ needs : matrix-setup
24
26
runs-on : ubuntu-latest
25
27
strategy :
26
- matrix :
27
- value : ${{fromJSON(needs.matrix-setup.outputs.matrix)}}
28
+ matrix : ${{ fromJson(needs.matrix-setup.outputs.matrix) }}
28
29
steps :
29
30
- name : Set up Helm
30
31
uses : azure/setup-helm@v4
@@ -36,33 +37,69 @@ jobs:
36
37
username : ${{ secrets.DOCKER_USERNAME }}
37
38
password : ${{ secrets.DOCKER_PASSWORD }}
38
39
39
- - name : Read repositories list and loop
40
+ - name : ${{ matrix.key }} > Check if latest tag exist
41
+ id : check-exist
42
+ env :
43
+ REPO_INFO : ${{ toJSON(matrix.value) }} # path to repositories, chart_paths, and tag_regex
40
44
run : |
41
- REPO_INFO=${{ matrix.value }} # path to repositories, chart_paths, and tag_regex
45
+ set -x
46
+ set +e
42
47
OCI_REGISTRY='oci://registry-1.docker.io/ez4devcharts' # modify this if your registry differs
43
48
44
49
# Ensure jq is installed
45
50
sudo apt-get update && sudo apt-get install -y jq
46
51
47
52
# Parse repo info
48
- REPO_NAME=$(echo $REPO_INFO | jq -r '.repository')
53
+ REPO_NAME=${{ matrix.key }}
49
54
CHART_PATH=$(echo $REPO_INFO | jq -r '.chart_path')
50
55
CHART_NAME=$(echo $REPO_INFO | jq -r '.chart_name')
51
56
TAG_REGEX=$(echo $REPO_INFO | jq -r '.tag_regex')
52
57
53
58
# Fetch latest tag matching the regex
54
- LATEST_TAG=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP "$TAG_REGEX" | sort -rV | head -n1)
59
+ TAG_REFS=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP 'refs/.*')
60
+ LATEST_TAG=$(echo $TAG_REFS | grep -oP "$TAG_REGEX" | sort -rV | head -n1)
61
+ TAG_REFS=$(echo $TAG_REFS | grep $LATEST_TAG)
62
+ echo "tag-ref=$TAG_REFS" >> $GITHUB_OUTPUT
55
63
56
64
# Check if Helm chart is published
57
65
helm show chart "$OCI_REGISTRY/$CHART_NAME" --version "$LATEST_TAG" &> /dev/null
58
66
if [ $? -ne 0 ]; then
59
- # Pack and push the chart
60
- echo "Packaging and pushing the chart for $CHART_NAME with tag $LATEST_TAG"
61
- helm package $CHART_PATH --version $LATEST_TAG
62
- CHART_FILE=$CHART_NAME-$LATEST_TAG.tgz
63
- helm chart save $CHART_FILE $OCI_REGISTRY/$CHART_NAME:$LATEST_TAG
64
- helm chart push $OCI_REGISTRY/$CHART_NAME:$LATEST_TAG
65
- else
66
- echo "Helm chart for $CHART_NAME with tag $LATEST_TAG is already published."
67
+ echo "helm-ver=$LATEST_TAG" >> $GITHUB_OUTPUT
68
+ exit 0
67
69
fi
70
+
71
+ echo "Stop here"
72
+ exit 1
68
73
shell : bash
74
+
75
+ - name : Clone repo ${{ matrix.key }}
76
+ id : clone-repo
77
+ uses : actions/checkout@v3
78
+ with :
79
+ repository : ${{ matrix.key }}
80
+ ref : refs/heads/master # [TODO] Use the parsed tag of previous step
81
+ path : ${{ steps.check-exist.output.tag-ref }}
82
+
83
+ - name : Publish chart ${{ matrix.key }}
84
+ id : publish-new-chart
85
+ env :
86
+ REPO_INFO : ${{ toJSON(matrix.value) }} # path to repositories, chart_paths, and tag_regex
87
+ run : |
88
+ set -x
89
+ OCI_REGISTRY='oci://registry-1.docker.io/ez4devcharts' # modify this if your registry differs
90
+
91
+ # Parse repo info
92
+ REPO_NAME=${{ matrix.key }}
93
+ CHART_PATH=$(echo $REPO_INFO | jq -r '.chart_path')
94
+ CHART_NAME=$(echo $REPO_INFO | jq -r '.chart_name')
95
+ TAG_REGEX=$(echo $REPO_INFO | jq -r '.tag_regex')
96
+
97
+ # Fetch latest tag matching the regex
98
+ LATEST_TAG=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP "$TAG_REGEX" | sort -rV | head -n1)
99
+
100
+ # Pack and push the chart
101
+ echo "Packaging and pushing the chart for $CHART_NAME with tag $LATEST_TAG"
102
+ helm dep build target_repo/$CHART_PATH
103
+ helm package target_repo/$CHART_PATH --version $LATEST_TAG
104
+ CHART_FILE=$CHART_NAME-$LATEST_TAG.tgz
105
+ helm push $CHART_FILE $OCI_REGISTRY
0 commit comments