Check and Publish Helm Charts #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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 | |
LATEST_TAG=$(git ls-remote --tags https://github.com/$REPO_NAME.git | grep -oP "$TAG_REGEX" | sort -rV | head -n1) | |
# Check if Helm chart is published | |
helm show chart "$OCI_REGISTRY/$CHART_NAME" --version "$LATEST_TAG" &> /dev/null | |
shell: bash | |
- name: Clone repo ${{ matrix.key }} | |
id: clone-repo | |
if: failure() | |
uses: actions/checkout@v3 | |
with: | |
name: ${{ matrix.key }} | |
# [TODO] Use the parsed tag of previous step | |
ref: refs/heads/master | |
- name: Publish chart ${{ matrix.key }} | |
id: publish-new-chart | |
if: failure() | |
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 | |
# Pack and push the chart | |
echo "Packaging and pushing the chart for $CHART_NAME with tag $LATEST_TAG" | |
helm package $CHART_PATH --version $LATEST_TAG | |
CHART_FILE=$CHART_NAME-$LATEST_TAG.tgz | |
helm push $CHART_FILE $OCI_REGISTRY |