diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fa3927..f0db9eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,6 +103,7 @@ jobs: # Token should have contents: write permissions token: ${{ secrets.GITHUB_TOKEN }} enable_otel_config_write_back: true + enable_auto_rollout: true - name: Get Resources if: always() diff --git a/Dockerfile b/Dockerfile index b0c2834..085168b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Container image that runs your code FROM alpine:3.10 -RUN apk add --no-cache bash curl git +RUN apk add --no-cache bash curl git jq COPY --chmod=0755 entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index ca59726..8eb3e7f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ server. It also supports exporting the OpenTelemetry configurations back to the | 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. | | token | | The Github token that will be used to write to the repo. Usually secrets.GITHUB_TOKEN is sufficient. Requires the `contents.write` permission. | +| enable_auto_rollout | `false` | When enabled, the action will trigger a rollout for any configuration that has been updated. | ## Usage @@ -80,6 +81,7 @@ jobs: enable_otel_config_write_back: true configuration_output_dir: otel/ token: ${{ secrets.GITHUB_TOKEN }} + enable_auto_rollout: true ``` After the action is executed, you can expect to see OTEL configurations diff --git a/action.yml b/action.yml index 513ee8d..dcffaf9 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,9 @@ inputs: description: 'Path to the directory which will contain the rendered OTEL format of the configuration resources' token: description: 'The GitHub token used to authenticate to GitHub when writing OTEL configs back to the repo' + enable_auto_rollout: + description: 'When enabled, the action will trigger a rollout for all configurations that have been updated' + default: false runs: using: 'docker' @@ -42,3 +45,4 @@ runs: - ${{ inputs.enable_otel_config_write_back }} - ${{ inputs.configuration_output_dir }} - ${{ inputs.token }} + - ${{ inputs.enable_auto_rollout }} diff --git a/entrypoint.sh b/entrypoint.sh index 7399f51..6bb66e7 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,6 +13,7 @@ configuration_path=${7} enable_otel_config_write_back=${8} configuration_output_dir=${9} token=${10} +enable_auto_rollout=${11} # This branch name will be compared to target_branch to determine if the action # should apply or write back configurations. @@ -157,7 +158,29 @@ main() { bindplane apply "$destination_path" echo "Applying configuration path: $configuration_path" - bindplane apply "$configuration_path" + bindplane apply "$configuration_path" > configuration.out + cat configuration.out + + # When auto rollout is enabled + if [ "$enable_auto_rollout" = true ]; then + echo "Auto rollout enabled." + awk '{print $2}' < configuration.out | while IFS= read -r config + do + status=$(bindplane rollout status "${config}" -o json | jq .status) + case "$status" in + 0) + echo "Configuration ${config} has a pending rollout, triggering rollout." + bindplane rollout start "$config" + ;; + 4) + echo "Configuration ${config} is stable, skipping rollout." + ;; + *) + echo "Configuration ${config} has an unknown status, skipping rollout." + ;; + esac + done + fi # When write back is enabled, write the raw otel configs # back to the repository.