Skip to content

Commit

Permalink
fix: semantic release, indexes, ci
Browse files Browse the repository at this point in the history
  • Loading branch information
chliddle committed Dec 18, 2024
1 parent a02ecec commit 86509b5
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 109 deletions.
29 changes: 12 additions & 17 deletions .github/chart-release.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const path = require('path');

module.exports = {
branches: ['main'],
tagFormat: '${CHART_NAME}-v${version}',
plugins: [
['@semantic-release/commit-analyzer', {
preset: 'conventionalcommits',
Expand All @@ -19,20 +16,18 @@ module.exports = {
assets: ['CHANGELOG.md', 'Chart.yaml'],
message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
}],
['@semantic-release/exec', {
prepareCmd: `
sed -i "s/^version:.*$/version: \${nextRelease.version}/" Chart.yaml && \
helm package . --version \${nextRelease.version} --app-version \${nextRelease.version} && \
mv ${process.env.CHART_NAME}-\${nextRelease.version}.tgz ${process.env.GITHUB_WORKSPACE}/release/ && \
ls -l ${process.env.GITHUB_WORKSPACE}/release/
`
}],
['@semantic-release/github', {
assets: [
{ path: '${CHART_NAME}-${nextRelease.version}.tgz', label: '${CHART_NAME} Chart' },
],
}],
],
prepare: [
{
path: '@semantic-release/exec',
cmd: 'sed -i "s/^version:.*$/version: ${nextRelease.version}/" Chart.yaml',
},
{
path: '@semantic-release/exec',
cmd: 'helm package . --version ${nextRelease.version} --app-version ${nextRelease.version}',
},
],
`${process.env.GITHUB_WORKSPACE}/release/${process.env.CHART_NAME}-*.tgz`
]
}]
]
};
91 changes: 52 additions & 39 deletions .github/workflows/release-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,32 @@ jobs:
node-version: '20'

- name: Install dependencies
run: npm install @semantic-release/git @semantic-release/changelog @semantic-release/exec conventional-changelog-conventionalcommits
run: npm install

- name: Release charts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p release
chart_dirs=$(find ./charts -name Chart.yaml -exec dirname {} \;)
for dir in $chart_dirs; do
echo "Checking for changes in ${dir}"
if git diff --quiet HEAD^ HEAD -- "${dir}"; then
echo "No changes in ${dir}, skipping release"
else
echo "Changes detected in ${dir}, releasing chart"
cd "${dir}"
# Download dependencies before semantic-release
helm dependency update .
helm dependency build .
export CHART_PATH=$(pwd)
export CHART_NAME=$(basename $(pwd))
npx semantic-release -e ../../.github/chart-release.config.js
helm package . --destination ../release/
cd $GITHUB_WORKSPACE
# 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:
Expand All @@ -109,38 +109,51 @@ jobs:
- name: Install Helm
uses: azure/setup-helm@v3

- name: Install yq
- 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: Generate Helm repo index and README
- name: Copy static assets
run: |
mkdir -p ./release/images
cp -r docs/images/* ./release/images/
helm repo index ./release --url https://${{ github.repository_owner }}.github.io/cosmos-helm-charts/
mkdir -p release/images
cp -r docs/images/* release/images/
# Get list of charts
charts=$(find ./charts -name Chart.yaml -exec dirname {} \; | sed 's/.\///')
- 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 chart info
# 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 chart in $charts; do
if [ -f "${chart}/Chart.yaml" ]; then
name=$(yq e '.name' ${chart}/Chart.yaml)
# Get the latest tag for this chart, sorting by version number
version=$(git tag -l "${name}-v*" | sort -V | tail -n 1)
version=${version#${name}-v}
description=$(yq e '.description' ${chart}/Chart.yaml)
chart_info+="<div class=\"chart\">"
chart_info+="<h3>${name}</h3>"
chart_info+="<p><strong>Version:</strong> ${version}</p>"
chart_info+="<p><strong>Description:</strong> ${description}</p>"
chart_info+="</div>"
fi
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
# Use the template to generate index.html
# 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|{{AVAILABLE_CHARTS}}|${chart_info}|g" ./release/index.html
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ To add a new chart to this repository, follow these steps:
4. Create a `.releaserc.js` file in your chart directory using an existing one as an example - you simply need to change these lines

```js
const chartName =
```

```js
tagFormat: 'cosmos-operator-rpc-node-v${version}',
module.exports = {
extends: '../../.github/chart-release.config.js',
tagFormat: 'your-chart-name-v${version}',
};
```

## Contributing
Expand Down
17 changes: 2 additions & 15 deletions charts/allora-worker/.releaserc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const chartName = 'allora-worker';
const chartPath = __dirname;

module.exports = {
extends: '../.github/chart-release.config.js',
tagFormat: 'allora-worker-v${version}',
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
'@semantic-release/git',
'@semantic-release/github',
['@semantic-release/exec', {
prepareCmd: 'sed -i "s/^version:.*$/version: ${nextRelease.version}/" Chart.yaml && helm package . --version ${nextRelease.version} --app-version ${nextRelease.version} && mv *.tgz ../'
}]
]
extends: '../../.github/chart-release.config.js',
tagFormat: 'allora-worker-v${version}'
};
1 change: 0 additions & 1 deletion charts/allora-worker/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,3 @@ strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0

17 changes: 2 additions & 15 deletions charts/cosmos-operator-rpc-node/.releaserc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const chartName = 'cosmos-operator-rpc-node';
const chartPath = __dirname;

module.exports = {
extends: '../.github/chart-release.config.js',
tagFormat: 'cosmos-operator-rpc-node-v${version}',
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
'@semantic-release/git',
'@semantic-release/github',
['@semantic-release/exec', {
prepareCmd: 'sed -i "s/^version:.*$/version: ${nextRelease.version}/" Chart.yaml && helm package . --version ${nextRelease.version} --app-version ${nextRelease.version} && mv *.tgz ../'
}]
]
extends: '../../.github/chart-release.config.js',
tagFormat: 'cosmos-operator-rpc-node-v${version}'
};
17 changes: 2 additions & 15 deletions charts/namada-indexer/.releaserc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const chartName = 'namada-indexer';
const chartPath = __dirname;

module.exports = {
extends: '../.github/chart-release.config.js',
tagFormat: 'namada-indexer-v${version}',
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
'@semantic-release/git',
'@semantic-release/github',
['@semantic-release/exec', {
prepareCmd: 'sed -i "s/^version:.*$/version: ${nextRelease.version}/" Chart.yaml && helm package . --version ${nextRelease.version} --app-version ${nextRelease.version} && mv *.tgz ../'
}]
]
extends: '../../.github/chart-release.config.js',
tagFormat: 'namada-indexer-v${version}'
};
1 change: 0 additions & 1 deletion charts/namada-indexer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,3 @@ tolerations: []

# Affinity
affinity: {}

2 changes: 1 addition & 1 deletion docs/index.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</style>
</head>
<body>
<img src="images/logo.png" alt="P2P Logo" class="logo">
<img src="https://raw.githubusercontent.com/${{ github.repository }}/main/docs/images/logo.png" alt="P2P Logo" class="logo">
<div class="badges">
<a href="https://x.com/P2Pvalidator"><img src="https://badgen.net/badge/twitter/@P2Pvalidator/1DA1F2?icon&label" /></a>
<a href="https://github.com/p2p-org/cosmos-helm-charts"><img src="https://badgen.net/github/stars/p2p-org/cosmos-helm-charts?icon=github" /></a>
Expand Down
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "cosmos-helm-charts",
"type": "commonjs",
"private": true,
"dependencies": {
"@semantic-release/changelog": "*",
"@semantic-release/exec": "*",
"@semantic-release/git": "*",
"@semantic-release/github": "*",
"conventional-changelog-conventionalcommits": "*",
"semantic-release": "^24.0.0"
}
}

0 comments on commit 86509b5

Please sign in to comment.