Skip to content

Commit 230fd55

Browse files
authored
HELM-75 feat:Provide automatic changelog on GH Releases (#49)
Release-As: 1.7.0
1 parent a28632a commit 230fd55

4 files changed

Lines changed: 134 additions & 51 deletions

File tree

.github/workflows/release.yml

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,28 @@ on:
44
push:
55
branches:
66
- master
7-
- v1.1
7+
- next
88
paths:
99
- '.github/**'
1010
- 'charts/**'
1111
- '!**.md'
1212

13-
jobs:
14-
15-
validate:
16-
runs-on: ubuntu-latest
17-
outputs:
18-
result: ${{ steps.changed.outputs.result }}
19-
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v3
22-
with:
23-
fetch-depth: 0
24-
# - id: changed
25-
# name: Changed
26-
# run: |
27-
# files_changed="$(git show --pretty="" --name-only)"
28-
# echo "$files_changed"
29-
# num_version_bumps="$(echo "$files_changed" | grep Chart.yaml | xargs git show | grep -c "+version" || true)"
30-
# if [[ "$num_version_bumps" -eq "1" ]]; then
31-
# echo "result=ok" >> $GITHUB_OUTPUT
32-
# else
33-
# echo "result=skip"
34-
# echo "::warning::Version not changed, skipping release job..."
35-
# fi
13+
permissions:
14+
contents: write
15+
packages: write
16+
issues: write
17+
pull-requests: write
3618

19+
jobs:
3720
release:
38-
needs: validate
39-
# if: ${{ needs.validate.outputs.result == 'ok' }}
40-
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
41-
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
42-
permissions:
43-
contents: write
44-
packages: write
45-
4621
runs-on: ubuntu-latest
4722
steps:
4823
- name: Checkout
4924
uses: actions/checkout@v3
5025
with:
5126
fetch-depth: 0
27+
repository: ${{ github.event.repository.full_name }}
28+
token: ${{ secrets.GITHUB_TOKEN }}
5229

5330
- name: Configure Git
5431
run: |
@@ -72,28 +49,21 @@ jobs:
7249
GPG_KEYRING_BASE64: "${{ secrets.GPG_KEYRING_BASE64 }}"
7350
GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}"
7451

75-
- name: Run chart-releaser
76-
uses: helm/chart-releaser-action@v1.6.0
77-
env:
78-
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
79-
CR_RELEASE_NAME_TEMPLATE: "xwiki-helm-{{ .Version }}"
80-
CR_SIGN: true
81-
CR_KEY: "XWiki SAS"
82-
# Values for CR_KEYRING and CR_PASSPHRASE_FILE was setup on Prepare GPG key
83-
8452
- name: Login to XWiki SAS Container Registry
8553
uses: docker/login-action@v1
8654
with:
8755
registry: ${{ vars.XWIKISAS_REGISTRY }}
8856
username: ${{ vars.XWIKISAS_REGISTRY_USER }}
8957
password: ${{ secrets.XWIKISAS_REGISTRY_TOKEN }}
58+
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v3
61+
with:
62+
node-version: 'lts/*'
9063

91-
- name: Push Charts to XWiki SAS
92-
run: |
93-
shopt -s nullglob
94-
for pkg in .cr-release-packages/*.tgz; do
95-
if [ -z "${pkg:-}" ]; then
96-
break
97-
fi
98-
helm push "${pkg}" oci://git.xwikisas.com:5050/xwikisas/swp/xwiki/contrib-xwiki-helm
99-
done
64+
- name: Run semantic-release
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
CR_KEYRING: ${{ env.CR_KEYRING }}
68+
CR_PASSPHRASE_FILE: ${{ env.CR_PASSPHRASE_FILE }}
69+
run: npx -p semantic-release -p @semantic-release/git -p @semantic-release/exec semantic-release

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
- name: Add repos
2929
run: |
3030
helm repo add bitnami https://charts.bitnami.com/bitnami
31-
helm plugin install https://github.com/helm-unittest/helm-unittest --version 0.3.4
3231
3332
- name: Set up chart-testing
3433
uses: helm/chart-testing-action@v2.3.1

.releaserc.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"branches": [
3+
"master",
4+
"next"
5+
],
6+
"tagFormat": "xwiki-helm-${version}",
7+
"plugins": [
8+
"@semantic-release/commit-analyzer",
9+
"@semantic-release/release-notes-generator",
10+
[
11+
"@semantic-release/exec",
12+
{
13+
"prepareCmd": "mkdir -p .cr-release-packages && sed -i \"s/^version: .*/version: ${nextRelease.version}/\" charts/xwiki/Chart.yaml && helm dependency update charts/xwiki && helm package charts/xwiki --destination .cr-release-packages --sign --key 'XWiki SAS' --keyring $CR_KEYRING --passphrase-file $CR_PASSPHRASE_FILE",
14+
"publishCmd": "helm push .cr-release-packages/xwiki-${nextRelease.version}.tgz oci://git.xwikisas.com:5050/xwikisas/swp/xwiki/contrib-xwiki-helm && ./scripts/publish-gh-pages.sh"
15+
}
16+
],
17+
[
18+
"@semantic-release/git",
19+
{
20+
"assets": [
21+
"charts/xwiki/Chart.yaml"
22+
],
23+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
24+
}
25+
],
26+
[
27+
"@semantic-release/github",
28+
{
29+
"assets": [
30+
{
31+
"path": ".cr-release-packages/*.tgz",
32+
"label": "Helm Chart"
33+
},
34+
{
35+
"path": ".cr-release-packages/*.prov",
36+
"label": "Provenance File"
37+
}
38+
],
39+
"successComment": false,
40+
"failComment": false
41+
}
42+
]
43+
]
44+
}

scripts/publish-gh-pages.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)