From 0b33fc8b8c73d4d8eb2c94570c871bf5262a5955 Mon Sep 17 00:00:00 2001 From: Davide Bianchi Date: Sun, 20 Oct 2024 20:43:56 +0200 Subject: [PATCH] feat: add support to create release on another repo Signed-off-by: Davide Bianchi --- README.md | 4 ++++ action.yml | 28 ++++++++++++++++++++++++++++ cr.sh | 10 +++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b14c4f3..5356589 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index b75c1dc..321aa49 100644 --- a/action.yml +++ b/action.yml @@ -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." @@ -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 }}") @@ -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 diff --git a/cr.sh b/cr.sh index 4897b65..5f7c0e3 100755 --- a/cr.sh +++ b/cr.sh @@ -38,6 +38,7 @@ Usage: $(basename "$0") --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 } @@ -55,6 +56,7 @@ main() { local mark_as_latest=true local packages_with_index=false local pages_branch= + local commit= parse_command_line "$@" @@ -218,6 +220,12 @@ parse_command_line() { shift fi ;; + -c | --commit) + if [[ -n "${2:-}" ]]; then + commit="$2" + shift + fi + ;; *) break ;; @@ -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