chore: image for github page fix #53
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: Release Charts and Deploy to GitHub Pages | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
changes_detected: ${{ steps.check.outputs.changes_detected }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Check for changes in Helm charts | |
id: check | |
run: | | |
# Find all directories containing Chart.yaml | |
chart_dirs=$(find ./charts -name Chart.yaml -exec dirname {} \;) | |
changes_detected=false | |
for dir in $chart_dirs; do | |
if git diff --quiet HEAD^ HEAD -- "$dir"; then | |
echo "No changes in $dir" | |
else | |
echo "Changes detected in $dir" | |
changes_detected=true | |
break | |
fi | |
done | |
echo "changes_detected=$changes_detected" >> $GITHUB_OUTPUT | |
release-charts: | |
needs: check-changes | |
if: needs.check-changes.outputs.changes_detected == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- name: Add dependency repositories | |
run: | | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
helm repo add zalando https://opensource.zalando.com/postgres-operator/charts/postgres-operator | |
helm repo update | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm install | |
- name: Release charts | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mkdir -p release | |
# Store changed directories first | |
changed_dirs=() | |
for dir in $(find ./charts -name Chart.yaml -exec dirname {} \;); do | |
if ! git diff --quiet HEAD^ HEAD -- "${dir}"; then | |
changed_dirs+=("$dir") | |
fi | |
done | |
# Process all changed directories | |
for dir in "${changed_dirs[@]}"; do | |
cd "${dir}" | |
helm dependency update . | |
helm dependency build . | |
export CHART_PATH=$(pwd) | |
export CHART_NAME=$(basename $(pwd)) | |
npx semantic-release | |
cd $GITHUB_WORKSPACE | |
done | |
- name: Upload release as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release | |
path: release | |
generate-index: | |
needs: release-charts | |
if: needs.check-changes.outputs.changes_detected == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- name: Install yq/jq | |
run: | | |
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 | |
sudo chmod +x /usr/local/bin/yq | |
sudo apt-get install -y jq | |
- name: Copy static assets | |
run: | | |
mkdir -p release/images | |
cp -r docs/images/* release/images/ | |
- name: Generate indexes | |
run: | | |
mkdir -p release | |
# Download all chart packages from GitHub releases | |
git fetch --tags | |
for tag in $(git tag -l "*-v*" | sort -V); do | |
chart_name=${tag%-v*} | |
version=${tag#*-v} | |
# Download the .tgz from GitHub release | |
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/octet-stream" \ | |
"https://github.com/${{ github.repository }}/releases/download/${tag}/${chart_name}-${version}.tgz" \ | |
-o "release/${chart_name}-${version}.tgz" | |
done | |
# Generate fresh index.yaml from all packages | |
helm repo index ./release --url https://${{ github.repository_owner }}.github.io/cosmos-helm-charts/ | |
# Generate HTML chart info | |
chart_info="" | |
for entry in $(yq e '.entries | keys | .[]' ./release/index.yaml); do | |
version=$(yq e ".entries.\"$entry\"[0].version" ./release/index.yaml) | |
description=$(yq e ".entries.\"$entry\"[0].description" ./release/index.yaml) | |
chart_info+="<div class=\"chart\">" | |
chart_info+="<h3>${entry}</h3>" | |
chart_info+="<p><strong>Version:</strong> ${version}</p>" | |
chart_info+="<p><strong>Description:</strong> ${description}</p>" | |
chart_info+="</div>" | |
done | |
# Generate index.html | |
cp docs/index.html.template ./release/index.html | |
sed -i "s|{{GITHUB_REPOSITORY_OWNER}}|${GITHUB_REPOSITORY_OWNER}|g" ./release/index.html | |
sed -i "s|\${{ github.repository }}|${GITHUB_REPOSITORY}|g" ./release/index.html | |
sed -i "s|{{AVAILABLE_CHARTS}}|${chart_info}|g" ./release/index.html | |
- name: Upload release as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release | |
path: release | |
deploy: | |
needs: generate-index | |
if: needs.check-changes.outputs.changes_detected == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Download release artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: release | |
path: release | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./release | |
force_orphan: true | |
verify-files: | |
needs: deploy | |
if: needs.check-changes.outputs.changes_detected == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Download release artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: release | |
path: release | |
- name: Verify files | |
run: | | |
ls -l ./release | |
echo "Content of index.yaml:" | |
cat ./release/index.yaml | |
echo "Content of index.html:" | |
cat ./release/index.html |