Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip_release flag to bypass GitHub releases and tagging #219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi
- `skip_packaging`: This option, when populated, will skip the packaging step. This allows you to do more advanced packaging of your charts (for example, with the `helm package` command) before this action runs. This action will only handle the indexing and publishing steps.
- `skip_existing`: Skip package upload if release/tag already exists
- `skip_upload`: This option, when populated, will skip the upload step. This allows you to do more advanced uploading of your charts (for exemple with OCI based repositories) which doen't require the `index.yaml`.
- `skip_release`: Skip creating GitHub release and tag, only push artifacts to pages branch.
- `mark_as_latest`: When you set this to `false`, it will mark the created GitHub release not as 'latest'.
- `packages_with_index`: When you set this to `true`, it will upload chart packages directly into publishing branch.
- `pages_branch`: Name of the branch to be used to push the index and artifacts. (default to: gh-pages but it is not set in the action it is a default value for the chart-releaser binary)
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ inputs:
skip_upload:
description: "Skip package upload"
required: false
skip_release:
description: "Skip creating GitHub release and tag, only push artifacts to pages branch"
required: false
default: false
mark_as_latest:
description: Mark the created GitHub release as 'latest'
required: false
Expand Down Expand Up @@ -108,6 +112,10 @@ runs:
args+=(--skip-upload "${{ inputs.skip_upload }}")
fi

if [[ -n "${{ inputs.skip_release }}" ]]; then
args+=(--skip-release "${{ inputs.skip_release }}")
fi

if [[ -n "${{ inputs.mark_as_latest }}" ]]; then
args+=(--mark-as-latest "${{ inputs.mark_as_latest }}")
fi
Expand Down
91 changes: 70 additions & 21 deletions cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Usage: $(basename "$0") <options>
-s, --skip-packaging Skip the packaging step (run your own packaging before using the releaser)
--skip-existing Skip package upload if release exists
--skip-upload Skip package upload, just create the release. Not needed in case of OCI upload.
--skip-release Skip creating GitHub release and tag, only push artifacts to branch
-l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true)
--packages-with-index Upload chart packages directly into publishing branch
EOF
Expand All @@ -52,9 +53,11 @@ main() {
local skip_packaging=
local skip_existing=
local skip_upload=
local skip_release=false
local mark_as_latest=true
local packages_with_index=false
local pages_branch=
local latest_tag=""

parse_command_line "$@"

Expand All @@ -64,41 +67,60 @@ main() {
repo_root=$(git rev-parse --show-toplevel)
pushd "$repo_root" >/dev/null

if [[ -z "$skip_packaging" ]]; then
echo 'Looking up latest tag...'
local latest_tag
latest_tag=$(lookup_latest_tag)

echo "Discovering changed charts since '$latest_tag'..."
local changed_charts=()
readarray -t changed_charts <<<"$(lookup_changed_charts "$latest_tag")"

if [[ -n "${changed_charts[*]}" ]]; then
install_chart_releaser
install_chart_releaser

if [[ -z "$skip_packaging" ]]; then
if [[ "$skip_release" = true ]]; then
rm -rf .cr-release-packages
mkdir -p .cr-release-packages

rm -rf .cr-index
mkdir -p .cr-index

for chart in "${changed_charts[@]}"; do
for chart in "$charts_dir"/*; do
if [[ -d "$chart" ]]; then
package_chart "$chart"
else
echo "Nothing to do. No chart changes detected."
fi
done

release_charts
# Get the version from the packaged chart for output
latest_tag=$(ls .cr-release-packages/*.tgz | head -n1 | sed 's/.*\/\(.*\)\.tgz/\1/')

update_index
echo "changed_charts=$(
IFS=,
echo "${changed_charts[*]}"
)" >changed_charts.txt
else
echo "Nothing to do. No chart changes detected."
echo "changed_charts=" >changed_charts.txt
echo 'Looking up latest tag...'
local latest_tag
latest_tag=$(lookup_latest_tag)

echo "Discovering changed charts since '$latest_tag'..."
local changed_charts=()
readarray -t changed_charts <<<"$(lookup_changed_charts "$latest_tag")"

if [[ -n "${changed_charts[*]}" ]]; then
rm -rf .cr-release-packages
mkdir -p .cr-release-packages

rm -rf .cr-index
mkdir -p .cr-index

for chart in "${changed_charts[@]}"; do
if [[ -d "$chart" ]]; then
package_chart "$chart"
else
echo "Nothing to do. No chart changes detected."
fi
done

release_charts
update_index
echo "changed_charts=$(
IFS=,
echo "${changed_charts[*]}"
)" >changed_charts.txt
else
echo "Nothing to do. No chart changes detected."
echo "changed_charts=" >changed_charts.txt
fi
fi
else
install_chart_releaser
Expand Down Expand Up @@ -206,6 +228,12 @@ parse_command_line() {
shift
fi
;;
--skip-release)
if [[ -n "${2:-}" ]]; then
skip_release="$2"
shift
fi
;;
-l | --mark-as-latest)
if [[ -n "${2:-}" ]]; then
mark_as_latest="$2"
Expand Down Expand Up @@ -341,6 +369,27 @@ update_index() {
return
fi

# If skip_release is true, use helm directly
if [[ "$skip_release" = true ]]; then
echo "Using helm to update index..."
git checkout ${pages_branch:-gh-pages} || git checkout -b ${pages_branch:-gh-pages}

# Copy packages if needed
if [[ "$packages_with_index" = true ]]; then
cp .cr-release-packages/*.tgz .
fi

# Generate/update index
helm repo index . --url "https://$owner.github.io/$repo"

# Commit and push
git add .
git commit -m "Update Helm repository" || echo "No changes to commit"
git push origin ${pages_branch:-gh-pages}
return
fi

# Original cr index for non-skip_release case
local args=(-o "$owner" -r "$repo" --push)
if [[ -n "$config" ]]; then
args+=(--config "$config")
Expand Down