diff --git a/.github/chart-release.config.js b/.github/chart-release.config.js index 1f04533..7b738a6 100644 --- a/.github/chart-release.config.js +++ b/.github/chart-release.config.js @@ -1,8 +1,5 @@ -const path = require('path'); - module.exports = { branches: ['main'], - tagFormat: '${CHART_NAME}-v${version}', plugins: [ ['@semantic-release/commit-analyzer', { preset: 'conventionalcommits', @@ -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` + ] + }] + ] }; diff --git a/.github/workflows/release-and-deploy.yml b/.github/workflows/release-and-deploy.yml index 699fd10..db81001 100644 --- a/.github/workflows/release-and-deploy.yml +++ b/.github/workflows/release-and-deploy.yml @@ -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: @@ -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+="
" - chart_info+="

${name}

" - chart_info+="

Version: ${version}

" - chart_info+="

Description: ${description}

" - chart_info+="
" - 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+="
" + chart_info+="

${entry}

" + chart_info+="

Version: ${version}

" + chart_info+="

Description: ${description}

" + chart_info+="
" 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 diff --git a/README.md b/README.md index 0c36dd4..d1ae822 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/charts/allora-worker/.releaserc.js b/charts/allora-worker/.releaserc.js index 25baedc..ba12c0d 100644 --- a/charts/allora-worker/.releaserc.js +++ b/charts/allora-worker/.releaserc.js @@ -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}' }; diff --git a/charts/allora-worker/values.yaml b/charts/allora-worker/values.yaml index 4547708..9394547 100644 --- a/charts/allora-worker/values.yaml +++ b/charts/allora-worker/values.yaml @@ -112,4 +112,3 @@ strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 0 - diff --git a/charts/cosmos-operator-rpc-node/.releaserc.js b/charts/cosmos-operator-rpc-node/.releaserc.js index 1928a4a..6980621 100644 --- a/charts/cosmos-operator-rpc-node/.releaserc.js +++ b/charts/cosmos-operator-rpc-node/.releaserc.js @@ -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}' }; diff --git a/charts/namada-indexer/.releaserc.js b/charts/namada-indexer/.releaserc.js index 6763f80..bd78819 100644 --- a/charts/namada-indexer/.releaserc.js +++ b/charts/namada-indexer/.releaserc.js @@ -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}' }; diff --git a/charts/namada-indexer/values.yaml b/charts/namada-indexer/values.yaml index 556894b..8359517 100644 --- a/charts/namada-indexer/values.yaml +++ b/charts/namada-indexer/values.yaml @@ -166,4 +166,3 @@ tolerations: [] # Affinity affinity: {} - diff --git a/docs/index.html.template b/docs/index.html.template index 8e93a4a..125f9d7 100644 --- a/docs/index.html.template +++ b/docs/index.html.template @@ -50,7 +50,7 @@ - +
diff --git a/package.json b/package.json new file mode 100644 index 0000000..4de4037 --- /dev/null +++ b/package.json @@ -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" + } +}