1+ #! /bin/bash
2+ set -e
3+
4+ # Configuration
5+ # These environment variables are available in the GitHub Actions context
6+ REPO_URL=" https://x-access-token:${GITHUB_TOKEN} @github.com/${GITHUB_REPOSITORY} .git"
7+ PAGES_BRANCH=" gh-pages"
8+ CHARTS_DIR=" .cr-release-packages"
9+ INDEX_DIR=" gh-pages-repo"
10+ GITHUB_PAGES_URL=" https://$( echo " $GITHUB_REPOSITORY " | cut -d' /' -f1) .github.io/$( echo " $GITHUB_REPOSITORY " | cut -d' /' -f2) /"
11+
12+ echo " Starting GitHub Pages publication..."
13+ echo " Repository: $GITHUB_REPOSITORY "
14+ echo " Pages URL: $GITHUB_PAGES_URL "
15+
16+ # Clone gh-pages branch
17+ echo " Cloning $PAGES_BRANCH branch..."
18+ rm -rf " $INDEX_DIR "
19+ git clone --branch " $PAGES_BRANCH " --single-branch --depth 1 " $REPO_URL " " $INDEX_DIR " || {
20+ echo " Branch $PAGES_BRANCH not found. Creating it..."
21+ mkdir -p " $INDEX_DIR "
22+ cd " $INDEX_DIR "
23+ git init
24+ git checkout -b " $PAGES_BRANCH "
25+ git remote add origin " $REPO_URL "
26+ cd ..
27+ }
28+
29+ # Copy charts
30+ echo " Indexing charts in $CHARTS_DIR ..."
31+ # The version is passed in the .releaserc.json environment, but we can extract it or assume standard tagging.
32+
33+ # Semantic release tag format: xwiki-helm-${nextRelease.version}
34+ # URL: https://github.com/${GITHUB_REPOSITORY}/releases/download/xwiki-helm-${VERSION}/${CHART_NAME}-${VERSION}.tgz
35+
36+ # We need to run helm repo index on the local charts dir, but with --url pointing to GitHub.
37+ # We merge with the existing index.yaml from gh-pages.
38+
39+ # Copy existing index.yaml to CHARTS_DIR for merging
40+ if [ -f " $INDEX_DIR /index.yaml" ]; then
41+ cp " $INDEX_DIR /index.yaml" " $CHARTS_DIR /index.yaml"
42+ fi
43+
44+ # Get the tag (assuming nextRelease.version is available or we parse it from the filename)
45+ # Actually, semantic-release ensures the version in Chart.yaml is correct at this point.
46+ VERSION=$( grep ' ^version:' charts/xwiki/Chart.yaml | awk ' {print $2}' )
47+ TAG=" xwiki-helm-$VERSION "
48+ RELEASE_URL=" https://github.com/$GITHUB_REPOSITORY /releases/download/$TAG "
49+
50+ echo " Using Release URL: $RELEASE_URL "
51+
52+ # Update index in CHARTS_DIR
53+ helm repo index " $CHARTS_DIR " --url " $RELEASE_URL " --merge " $CHARTS_DIR /index.yaml"
54+
55+ # Move ONLY index.yaml back to INDEX_DIR
56+ mv " $CHARTS_DIR /index.yaml" " $INDEX_DIR /"
57+
58+ # Push changes
59+ cd " $INDEX_DIR "
60+ echo " Committing and pushing changes..."
61+ if [ -z " $( git status --porcelain) " ]; then
62+ echo " No changes to commit."
63+ else
64+ git config user.name " $GITHUB_ACTOR "
65+ git config user.email " $GITHUB_ACTOR @users.noreply.github.com"
66+ git add index.yaml
67+ git commit -m " Update Helm repository index for $TAG [skip ci]"
68+ git push " $REPO_URL " " $PAGES_BRANCH "
69+ echo " Successfully pushed to $PAGES_BRANCH "
70+ fi
0 commit comments