Skip to content

Commit

Permalink
feat: github_host option defaulting to github.com (#13)
Browse files Browse the repository at this point in the history
* add github_host option defaulting to github.com

* use full github url instead

* use url

* clarify
  • Loading branch information
jsirianni authored Apr 10, 2024
1 parent da47e02 commit c33fec8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ BindPlane requires a license. You can request a free license [here](https://obse
| enable_otel_config_write_back | `false` | Whether or not the action should write the raw OpenTelemetry configurations back to the repository. |
| configuration_output_dir | | When write back is enabled, this is the path that will be written to. |
| configuration_output_branch | | The branch to write the OTEL configuration resources to. If unset, target_branch will be used. |
| token | | The Github token that will be used to write to the repo. Usually secrets.GITHUB_TOKEN is sufficient. Requires the `contents.write` permission. |
| token | | The Github token that will be used to write to the repo. Usually secrets.GITHUB_TOKEN is sufficient. Requires the `contents.write` permission. Alternatively, you can set `github_url`, which should contain your access token. |
| enable_auto_rollout | `false` | When enabled, the action will trigger a rollout for any configuration that has been updated. |
| tls_ca_cert | | The contents of a TLS certificate authority, usually from a secret. See the [TLS](#tls) section. |
| github_url | | Optional URL to use when closing the repository. Should be of the form `"https://{GITHUB_ACTOR}:{TOKEN}@{GITHUB_HOST}/{GITHUB_REPOSITORY}.git`. When set, `token` will not be used. |


## Usage

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ inputs:
default: false
tls_ca_cert:
description: 'The CA certificate to use when connecting to BindPlane OP'
github_url:
description: 'The GitHub URL to use when connecting to GitHub'

runs:
using: 'docker'
Expand All @@ -58,3 +60,4 @@ runs:
- ${{ inputs.tls_ca_cert }}
- ${{ inputs.source_path }}
- ${{ inputs.processor_path }}
- ${{ inputs.github_url }}
16 changes: 13 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configuration_output_branch=${12}
tls_ca_cert=${13}
source_path=${14}
processor_path=${15}
github_url=${16}

# This branch name will be compared to target_branch to determine if the action
# should apply or write back configurations.
Expand Down Expand Up @@ -89,9 +90,12 @@ validate() {
exit 1
fi

# A token or github_url are required when target_branch is set.
if [ -z "$token" ]; then
echo "token is required when target_branch is set."
exit 1
if [ -z "$github_url" ]; then
echo "token or github_url are required when target_branch is set."
exit 1
fi
fi

# GITHUB_ACTOR and GITHUB_REPOSITORY are set by the github actions runtime
Expand Down Expand Up @@ -127,12 +131,18 @@ write_back() {
# write back branch will be the same as the target branch.
write_back_branch=${configuration_output_branch:-$target_branch}

# if the github_url is set, use it, otherwise default to github.com
github_url=${github_url:-github.com}
if [ -z "$github_host" ]; then
github_url="https://${GITHUB_ACTOR}:${token}@github.com/${GITHUB_REPOSITORY}.git"
fi

# Clone the repo on the current branch
# and use depth 1 to avoid cloning the entire history.
git clone \
--depth 1 \
--branch "$write_back_branch" \
"https://${GITHUB_ACTOR}:${token}@github.com/${GITHUB_REPOSITORY}.git" \
"${github_url}" \
../out_repo

cd "../out_repo"
Expand Down

0 comments on commit c33fec8

Please sign in to comment.