-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from fmuyassarov/auto-release
Automate Helm charts releasing process via GitHub action
- Loading branch information
Showing
5 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
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
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 |
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
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 |
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
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
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
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" |