forked from EVOLVED-5G/NEF_emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
85 lines (69 loc) · 2.7 KB
/
publish-helm-chart.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
#
name: Publish Helm Chart
# Configures this workflow to run every time a change is pushed to the branch.
on:
push:
branches: ['main']
# Custom environment variables for the workflow.
env:
REGISTRY: atnog-harbor.av.it.pt
PROJECT: route25
# Jobs in this workflow.
jobs:
package-and-push-helm-chart:
runs-on: ubuntu-24.04
# Matrix to run job multiple times with different configurations.
strategy:
fail-fast: true # Stops the job as soon as one of the matrix entries fails.
matrix:
include:
- dir: helm-chart
# Steps in this job.
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to the Registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Helm Chart Package and Push
shell: bash
run: |
# Package the Helm Chart and capture the path
CHART_PATH=$(helm package ${{ matrix.dir }} -u | awk '{print $NF}')
# Run the helm push command and capture both stdout and stderr
OUTPUT=$(helm push $CHART_PATH oci://${{ env.REGISTRY }}/${{ env.PROJECT }} 2>&1)
echo "Raw Output: $OUTPUT"
# Check if the helm push command was successful
if [ $? -ne 0 ]; then
echo "Helm push failed."
exit 1
fi
# Extract the Digest from the output
DIGEST=$(echo "$OUTPUT" | grep "Digest:" | awk '{print $2}')
# Extract the Chart Name from the output
CHART_NAME=$(echo "$OUTPUT" | grep "Pushed:" | awk '{print $2}' | awk -F '/' '{print $NF}'| cut -d':' -f1)
# Print the results
echo "Digest: $DIGEST"
echo "Chart Name: $CHART_NAME"
# Add tags to the Helm Chart
for tag in ${{ github.ref_name == 'main' && 'latest' || '' }} ${{ github.ref_name }} ${{ github.sha }} ; do
# if tag is '' or empty, skip the tagging
if [ -z "$tag" ]; then
continue
fi
echo "Tagging $CHART_NAME with $tag"
curl -u '${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_PASSWORD }}' -X 'POST' \
"https://${{ env.REGISTRY }}/api/v2.0/projects/${{ env.PROJECT }}/repositories/$CHART_NAME/artifacts/$DIGEST/tags" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": 0,
"repository_id": 0,
"artifact_id": 0,
"name": "'$tag'",
"immutable": true
}'
done