From ed13067ff2ecbc427f83b969503ad676060448d1 Mon Sep 17 00:00:00 2001 From: Kingdon Barrett Date: Tue, 24 Jan 2023 11:09:46 -0500 Subject: [PATCH] test conditionals in a nested structure add an "else" branch (https://github.com/fluxcd/flux2/pull/3511 failed to fix #3509) * factor out sed and cut so we at least do not repeat the most complex part of the expression * eliminate intermediary array TOKEN * delete reassignment of token * wording Signed-off-by: Kingdon Barrett --- action/action.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/action/action.yml b/action/action.yml index 574936c9..19a47bb4 100644 --- a/action/action.yml +++ b/action/action.yml @@ -28,14 +28,18 @@ runs: VERSION=${{ inputs.version }} TOKEN=${{ inputs.token }} - if [ -n "${TOKEN}" ]; then - TOKEN=(-H "Authorization: token ${TOKEN}") - fi - if [ -z "${VERSION}" ]; then - VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL ${TOKEN[@]} | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-) + if [ -n "${TOKEN}" ]; then + VERSION_SLUG=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest --silent --location --header "Authorization: token ${TOKEN}" | grep tag_name) + else + # With no GITHUB_TOKEN you will experience occasional failures due to rate limiting + # Ref: https://github.com/fluxcd/flux2/issues/3509#issuecomment-1400820992 + VERSION_SLUG=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest --silent --location | grep tag_name) + fi fi + VERSION=$(echo "${VERSION_SLUG}" | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-) + BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_${ARCH}.tar.gz" curl --silent --fail --location "${BIN_URL}" --output /tmp/flux.tar.gz mkdir -p /tmp/flux