Skip to content

Check and Publish Helm Charts #16

Check and Publish Helm Charts

Check and Publish Helm Charts #16

name: Check and Publish Helm Charts
on:
workflow_dispatch:
schedule:
- cron: '0 2 * * 1' # At 02:00 on Monday
jobs:
matrix-setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Matrix
id: matrix
uses: Surnet/get-json-matrix@v1
with:
filepath: ./repositories.json
check-and-publish-helm-charts:
name: ${{ matrix.key }}
needs: matrix-setup
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.matrix-setup.outputs.matrix) }}
steps:
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Login to OCI Registry
uses: docker/login-action@v3
with:
registry: registry-1.docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: ${{ matrix.key }} > Check if latest tag exist
id: check-exist
env:
REPO_INFO: ${{ toJSON(matrix.value) }} # path to repositories, chart_paths, and tag_regex
run: |
set -x
set +e
OCI_REGISTRY='oci://registry-1.docker.io/ez4devcharts' # modify this if your registry differs
# Ensure jq is installed
sudo apt-get update && sudo apt-get install -y jq
# Parse repo info
REPO_NAME=${{ matrix.key }}
CHART_PATH=$(echo $REPO_INFO | jq -r '.chart_path')
CHART_NAME=$(echo $REPO_INFO | jq -r '.chart_name')
TAG_REGEX=$(echo $REPO_INFO | jq -r '.tag_regex')
# Fetch latest tag matching the regex
TAG_REFS=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP 'refs/.*')
LATEST_TAG=$(echo $TAG_REFS | grep -oP "$TAG_REGEX" | sort -rV | head -n1)
TAG_REFS=$(echo $TAG_REFS | grep $LATEST_TAG)
echo "tag-ref=$TAG_REFS" >> $GITHUB_OUTPUT
# Check if Helm chart is published
helm show chart "$OCI_REGISTRY/$CHART_NAME" --version "$LATEST_TAG" &> /dev/null
if [ $? -ne 0 ]; then
echo "helm-ver=$LATEST_TAG" >> $GITHUB_OUTPUT
exit 0
fi
echo "Stop here"
exit 1
shell: bash
- name: Clone repo ${{ matrix.key }}
id: clone-repo
uses: actions/checkout@v3
with:
repository: ${{ matrix.key }}
ref: ${{ steps.check-exist.output.tag-ref }}
path: ./target_repo
- name: Publish chart ${{ matrix.key }}
id: publish-new-chart
env:
REPO_INFO: ${{ toJSON(matrix.value) }} # path to repositories, chart_paths, and tag_regex
run: |
set -x
OCI_REGISTRY='oci://registry-1.docker.io/ez4devcharts' # modify this if your registry differs
# Parse repo info
REPO_NAME=${{ matrix.key }}
CHART_PATH=$(echo $REPO_INFO | jq -r '.chart_path')
CHART_NAME=$(echo $REPO_INFO | jq -r '.chart_name')
TAG_REGEX=$(echo $REPO_INFO | jq -r '.tag_regex')
# Fetch latest tag matching the regex
LATEST_TAG=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP "$TAG_REGEX" | sort -rV | head -n1)
# Pack and push the chart
echo "Packaging and pushing the chart for $CHART_NAME with tag $LATEST_TAG"
helm dep build target_repo/$CHART_PATH
helm package target_repo/$CHART_PATH --version $LATEST_TAG
CHART_FILE=$CHART_NAME-$LATEST_TAG.tgz
helm push $CHART_FILE $OCI_REGISTRY