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+="
Version: ${version}
" - chart_info+="Description: ${description}
" - chart_info+="Version: ${version}
" + chart_info+="Description: ${description}
" + chart_info+="