Skip to content

Commit 515996f

Browse files
committed
Use action
1 parent 41986a2 commit 515996f

File tree

2 files changed

+63
-27
lines changed

2 files changed

+63
-27
lines changed

.github/workflows/weekly-scanner.yaml

+60-23
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ jobs:
99
matrix-setup:
1010
runs-on: ubuntu-latest
1111
outputs:
12-
matrix: ${{ steps.matrix.outputs.value }}
12+
matrix: ${{ steps.matrix.outputs.matrix }}
1313
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
2122

2223
check-and-publish-helm-charts:
23-
needs: ["matrix-setup"]
24+
name: ${{ matrix.key }}
25+
needs: matrix-setup
2426
runs-on: ubuntu-latest
2527
strategy:
26-
matrix:
27-
value: ${{fromJSON(needs.matrix-setup.outputs.matrix)}}
28+
matrix: ${{ fromJson(needs.matrix-setup.outputs.matrix) }}
2829
steps:
2930
- name: Set up Helm
3031
uses: azure/setup-helm@v4
@@ -36,33 +37,69 @@ jobs:
3637
username: ${{ secrets.DOCKER_USERNAME }}
3738
password: ${{ secrets.DOCKER_PASSWORD }}
3839

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
4044
run: |
41-
REPO_INFO=${{ matrix.value }} # path to repositories, chart_paths, and tag_regex
45+
set -x
46+
set +e
4247
OCI_REGISTRY='oci://registry-1.docker.io/ez4devcharts' # modify this if your registry differs
4348
4449
# Ensure jq is installed
4550
sudo apt-get update && sudo apt-get install -y jq
4651
4752
# Parse repo info
48-
REPO_NAME=$(echo $REPO_INFO | jq -r '.repository')
53+
REPO_NAME=${{ matrix.key }}
4954
CHART_PATH=$(echo $REPO_INFO | jq -r '.chart_path')
5055
CHART_NAME=$(echo $REPO_INFO | jq -r '.chart_name')
5156
TAG_REGEX=$(echo $REPO_INFO | jq -r '.tag_regex')
5257
5358
# 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
5563
5664
# Check if Helm chart is published
5765
helm show chart "$OCI_REGISTRY/$CHART_NAME" --version "$LATEST_TAG" &> /dev/null
5866
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
6769
fi
70+
71+
echo "Stop here"
72+
exit 1
6873
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

repositories.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
[
2-
{
3-
"repository": "syseleven/designate-certmanager-webhook",
1+
{
2+
"syseleven/designate-certmanager-webhook": {
43
"chart_path": "helm/designate-certmanager-webhook",
54
"chart_name": "designate-certmanager-webhook",
65
"tag_regex": "helm-\\K[0-9]+\\.[0-9]+\\.[0-9]+"
76
}
8-
]
7+
}

0 commit comments

Comments
 (0)