Skip to content

Commit

Permalink
Update publish-charts.yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Feruzjon Muyassarov <feruzjon.muyassarov@intel.com>
  • Loading branch information
fmuyassarov committed Sep 19, 2023
1 parent 46dff5d commit 93bda9c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Helm charts
name: Package Helm charts

on:
push:
Expand All @@ -8,7 +8,6 @@ on:
env:
CHARTS_DIR: deployment/helm/resource-management-policies/


jobs:
release:
permissions:
Expand All @@ -26,12 +25,16 @@ jobs:
- 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
#mv nri-resource-policy-balloons* $(echo nri-resource-policy-balloons* | sed 's/v/helm-chart-v/g')
done
- name: Upload Helm packages to GitHub
- 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-*.tgz
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
files: nri-resource-policy-*helm-chart*.tgz
40 changes: 0 additions & 40 deletions .github/workflows/publish-charts.yaml

This file was deleted.

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

jobs:
release:
concurrency:
group: ${{ github.event.release.tag_name }}
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
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
shell: bash
run: |
git push https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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
40 changes: 24 additions & 16 deletions scripts/build/helm-publisher.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
#!/bin/bash
set -e

owner="fmuyassarov"
repo="nri-plugins"
index_file="index.yaml"
browser_download_url="$@"

# Fetch browser download URLs for releases
releases=$(curl -s "https://api.github.com/repos/$owner/$repo/releases" | jq -r '.[].assets[].browser_download_url')
git checkout gh-pages

# Check if index.yaml exists, if not create it
if [ ! -f "$index_file" ]; then
touch "$index_file"
fi
# 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 releases were found
if [ -n "$releases" ]; then
# Check if Helm release assets were found
if [ -n "$charts_urls" ]; then
# Loop through the URLs
for url in $releases; do
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 "$url" "$index_file"; then
wget "$url"
base_url=$(dirname "$url")
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 releases found. Exiting..."
echo "No Helm packages were found in the release: $RELEASE_VERSION"
exit 1
fi

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

echo "Committing changes..."

git commit -m "$commit_msg" -- index.yaml

echo "gh-pages branch successfully updated"

0 comments on commit 93bda9c

Please sign in to comment.