Custom package for project branches #11
Workflow file for this run
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: Builds and pushes Docker Images and Helm charts to Github Registry | |
on: | |
push: | |
branches: | |
- develop | |
- feature/* # Delete this | |
- project/* | |
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: Install Helm | |
uses: azure/setup-helm@v3 | |
- 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 | |
run: | | |
SHA_SHORT=$(git rev-parse --short HEAD) | |
sed -i "s/SET-BY-CICD/$SHA_SHORT/g" helm/Chart.yaml | |
helm package ./helm -d .helm-charts | |
- name: Push Helm Chart | |
env: | |
IMAGE: ${{ needs.ci.outputs.docker_image }} | |
OCI_REPO: oci://ghcr.io/${{ github.repository }} | |
run: | | |
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//') | |
# Check if there is a slash in the BRANCH_NAME eg: project/add-docker | |
if [[ "$BRANCH_NAME" == *"/"* ]]; then | |
# Replace slashes with hyphens for TAG | |
OCI_REPO="$IMAGE_NAME-beta" | |
fi | |
PACKAGE_FILE=$(ls .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 >> $GITHUB_STEP_SUMMARY | |
echo '```' >> $GITHUB_STEP_SUMMARY |