Skip to content

Commit

Permalink
Merge pull request containers#112 from fmuyassarov/auto-release
Browse files Browse the repository at this point in the history
Automate Helm charts releasing process via GitHub action
  • Loading branch information
marquiz authored Sep 19, 2023
2 parents 9a8d984 + 4e9d1f9 commit 3e09cc0
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/package-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Package Helm charts

on:
push:
tags:
- "v*.*.*"

env:
CHARTS_DIR: deployment/helm/resource-management-policies/

jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Helm
uses: azure/setup-helm@v3

- name: Package Helm charts
run: |
helm package "$CHARTS_DIR"/*
find . -name '*.tgz' -print | while read SRC_FILE; do
DEST_FILE=$(echo $SRC_FILE | sed 's/v/helm-chart-v/g')
mv $SRC_FILE $DEST_FILE
done
- name: Upload Helm packages to GitHub releases
uses: softprops/action-gh-release@v1
with:
name: ${{ github.ref_name }}
draft: true
append_body: true
files: nri-resource-policy-*helm-chart*.tgz
35 changes: 35 additions & 0 deletions .github/workflows/publish-helm-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish Helm charts

on:
release:
types:
- published

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main

- name: Install Helm
uses: azure/setup-helm@v3

- name: Run chart publisher script
run: ./scripts/build/helm-publisher.sh ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
shell: bash

- name: Push
run: |
git push https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sources:
- https://github.com/containers/nri-plugins
home: https://github.com/containers/nri-plugins
type: application
version: 0.0.0
version: v0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sources:
- https://github.com/containers/nri-plugins
home: https://github.com/containers/nri-plugins
type: application
version: 0.0.0
version: v0.0.0
44 changes: 44 additions & 0 deletions scripts/build/helm-publisher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -e

index_file="index.yaml"
browser_download_url="$@"

git checkout gh-pages

# Verify if the release assets include Helm chart packages. If they do,
# we can proceed with updating the index.yaml file, otherwise throw an error.
charts_urls=$(echo "$browser_download_url" | grep '.*helm-chart-.*.tgz')

# Check if Helm release assets were found
if [ -n "$charts_urls" ]; then
# Loop through the URLs
for chart in $charts_urls; do
# Check if the URL path exists in index.yaml
# and if not, update the index.yaml accordingly
if ! grep -q "$chart" "$index_file"; then
wget "$chart"
base_url=$(dirname "$chart")
if ! helm repo index . --url "$base_url" --merge "$index_file"; then
echo "Failed to update "$index_file" for: $base_url"
fi
rm nri-resource-policy-*.tgz
fi
done
else
echo "No Helm packages were found on this release"
exit 1
fi

# Create a new commit
release=$(basename "$base_url")
commit_msg="Update Helm index for release $release"

echo "Committing changes..."

git config user.name "Github Actions"
git config user.email "[email protected]"
git add index.yaml
git commit -m "$commit_msg"

echo "gh-pages branch successfully updated"

0 comments on commit 3e09cc0

Please sign in to comment.