CD #8003
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- "main" | |
workflow_dispatch: | |
inputs: | |
ctf-branch: | |
description: "Run the CTF on a branch" | |
default: "main" | |
schedule: | |
- cron: "0 */1 * * *" # Runs every hour | |
name: CD | |
jobs: | |
release-charts: | |
name: Release Helm Charts | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ctf branch | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
with: | |
repository: smartcontractkit/chainlink-testing-framework | |
ref: ${{ github.event.inputs.ctf-branch }} | |
path: main | |
fetch-depth: 0 | |
- name: Checkout gh-pages branch | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
with: | |
ref: gh-pages | |
path: gh-pages | |
- name: Install Helm | |
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 | |
with: | |
version: v3.13.1 | |
- name: "Setup yq" | |
uses: dcarbone/install-yq-action@64b1b9eb28920bb1a4c13c05321df284f9a8f940 # v1.1.1 | |
- name: Create packages and repo index | |
shell: bash | |
env: | |
GITHUB_WORKSPACE: ${{ github.workspace }} | |
run: | | |
#!/bin/bash | |
charts_dir="$GITHUB_WORKSPACE/main/lib/charts" | |
package_dir="$GITHUB_WORKSPACE/gh-pages" | |
# Fetch list of currently packaged charts from gh-pages branch | |
pushd "${package_dir}" | |
packaged_charts=($(ls *.tgz)) | |
popd | |
echo "packaged charts ${packaged_charts[@]}" | |
# Loop over each chart in the charts directory to build a list of | |
# charts that have changed | |
changed_charts=() | |
for chart_dir in "${charts_dir}"/*; do | |
echo "chart dir ${chart_dir}" | |
if [ -d "${chart_dir}" ]; then | |
# Extract the chart name and version from Chart.yaml | |
chart_name=$(yq e '.name' "${chart_dir}/Chart.yaml") | |
current_version=$(yq e '.version' "${chart_dir}/Chart.yaml") | |
# Build the expected packaged chart filename | |
expected_package_name="${chart_name}-${current_version}.tgz" | |
echo "${expected_package_name}" | |
# Check if the expected package file exists in the packaged charts | |
if ! [[ -f "${package_dir}/${expected_package_name}" ]]; then | |
echo "Packaging ${chart_name}, version ${current_version} as it does not exist." | |
changed_charts+=("${chart_dir}") | |
else | |
echo "Package ${expected_package_name} already exists, no need to re-package." | |
fi | |
fi | |
done | |
# Now package the changed charts | |
tmp_package_dir="${package_dir}/packages" | |
mkdir -p "${tmp_package_dir}" | |
for changed_chart_path in "${changed_charts[@]}"; do | |
echo "Packaging ${changed_chart_path}..." | |
helm dependency update "${changed_chart_path}" | |
helm package "${changed_chart_path}" --destination "${tmp_package_dir}" | |
done | |
# After packaging the changed charts, you should be in the package_dir | |
cd "$package_dir" | |
# Now, move the new chart packages to the helm directory and re-index | |
# if [ -n "$CHANGED_CHARTS" ]; then | |
if [ "${#changed_charts[@]}" -ne 0 ]; then | |
if [ -f index.yaml ]; then | |
echo "Charts have changed re-indexing..." | |
# The fancy mv's are so that we preserve the creation | |
# timestamps of packages that have not been modified by | |
# this commit. See https://github.com/helm/helm/issues/7363 | |
helm repo index --merge index.yaml packages/ | |
mv -f packages/*.tgz . | |
mv -f packages/index.yaml index.yaml | |
else | |
echo "Initializing index..." | |
mv -f packages/*.tgz . | |
helm repo index . | |
fi | |
# Add the new packages and updated index file | |
# then push them up to the gh-pages branch to be | |
# published | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add . | |
git status | |
git commit -m "Update charts" | |
git push | |
else | |
echo "No chart changes detected." | |
fi |