Skip to content

Merge pull request #155 from IFRCGo/feature/ifrc_dref #18

Merge pull request #155 from IFRCGo/feature/ifrc_dref

Merge pull request #155 from IFRCGo/feature/ifrc_dref #18

Workflow file for this run

name: Helm
on:
workflow_dispatch:
# Build and push Docker image and Helm charts on every push to develop branch
# and on every tag push
push:
branches:
- develop
- project/*
- chore/*
tags:
- "**"
permissions:
packages: write
jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yml
with:
push_docker_image: true
build:
name: Publish Helm
needs: ci
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🐳 Helm dependency
run: |
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./helm/Chart.lock | sh --
helm dependency build ./helm/
- name: Tag docker image in Helm Chart values.yaml
env:
IMAGE_NAME: ${{ needs.ci.outputs.docker_image_name }}
IMAGE_TAG: ${{ needs.ci.outputs.docker_image_tag }}
run: |
# Update values.yaml with latest docker image
sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" ./helm/values.yaml
sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" ./helm/values.yaml
- name: Package Helm Chart
id: set-variables
env:
IMAGE_TAG: ${{ needs.ci.outputs.docker_image_tag }}
run: |
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
if [[ "$GITHUB_REF_NAME" == *"/"* ]]; then
# XXX: Change the helm chart to <chart-name>-alpha
sed -i 's/^name: \(.*\)/name: \1-alpha/' ./helm/Chart.yaml
fi
sed -i "s/SET-BY-CICD/$IMAGE_TAG/g" ./helm/Chart.yaml
helm package ./helm/ -d ./helm/.helm-charts
- name: Push Helm Chart
env:
IMAGE: ${{ needs.ci.outputs.docker_image }}
OCI_REPO: oci://ghcr.io/${{ github.repository }}
run: |
OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]')
PACKAGE_FILE=$(ls ./helm/.helm-charts/*.tgz | head -n 1)
echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Helm push output" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
helm push "$PACKAGE_FILE" $OCI_REPO 2>> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY