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 the support to release to a different repository #215

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi
- `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)
- `owner`: The owner of the repository. This is used to create the GitHub release. If not set, the owner will be inferred from the repository URL.
- `repo`: The name of the repository. This is used to create the GitHub release. If not set, the repository will be inferred from the repository URL.
- `commit`: The commit sha or the branch to use for the release. If not set, the commit hash will be inferred from the GitHub Actions environment.
- `workdir`: The working directory where the action will be executed. Useful if you have multiple repository checkouts in your workflow.

### Outputs

Expand Down
28 changes: 28 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ inputs:
pages_branch:
description: "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)"
required: false
owner:
description: "Owner of the repository where to push the index and artifacts"
required: false
repo:
description: "Repository where to push the index and artifacts"
required: false
commit:
description: "Commit SHA or branch to use for the release"
required: false
workdir:
description: "The working directory to run the action in"
required: false
outputs:
changed_charts:
description: "A comma-separated list of charts that were released on this run. Will be an empty string if no updates were detected, will be unset if `--skip_packaging` is used: in the latter case your custom packaging step is responsible for setting its own outputs if you need them."
Expand All @@ -69,8 +81,18 @@ runs:
steps:
- id: release
run: |
if [[ -n "${{ inputs.workdir }}" ]]; then
cd "${{ inputs.workdir }}"
fi

owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
if [[ -n "${{ inputs.owner }}" ]]; then
owners=${{ inputs.owner }}
fi
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
if [[ -n "${{ inputs.repo }}" ]]; then
repo=${{ inputs.repo }}
fi

args=(--owner "$owner" --repo "$repo")
args+=(--charts-dir "${{ inputs.charts_dir }}")
Expand Down Expand Up @@ -120,6 +142,12 @@ runs:
args+=(--pages-branch "${{ inputs.pages_branch }}")
fi

commit=$(git rev-parse HEAD)
if [[ -n "${{ inputs.commit }}" ]]; then
commit=${{ inputs.commit }}
fi
args+=(--commit "$commit")

"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"

if [[ -f changed_charts.txt ]]; then
Expand Down
10 changes: 9 additions & 1 deletion cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Usage: $(basename "$0") <options>
--skip-upload Skip package upload, just create the release. Not needed in case of OCI upload.
-l, --mark-as-latest Mark the created GitHub release as 'latest' (default: true)
--packages-with-index Upload chart packages directly into publishing branch
-c, --commit Target commit or branch for the release (default: latest tag on HEAD)
EOF
}

Expand All @@ -55,6 +56,7 @@ main() {
local mark_as_latest=true
local packages_with_index=false
local pages_branch=
local commit=

parse_command_line "$@"

Expand Down Expand Up @@ -218,6 +220,12 @@ parse_command_line() {
shift
fi
;;
-c | --commit)
if [[ -n "${2:-}" ]]; then
commit="$2"
shift
fi
;;
*)
break
;;
Expand Down Expand Up @@ -315,7 +323,7 @@ package_chart() {
}

release_charts() {
local args=(-o "$owner" -r "$repo" -c "$(git rev-parse HEAD)")
local args=(-o "$owner" -r "$repo" -c "$commit")
if [[ -n "$config" ]]; then
args+=(--config "$config")
fi
Expand Down