diff --git a/action/action.yml b/action/action.yml index d88786ee..83c5843c 100644 --- a/action/action.yml +++ b/action/action.yml @@ -16,23 +16,24 @@ inputs: description: "Alternative location for the Flux binary, defaults to path relative to $RUNNER_TOOL_CACHE." required: false token: - description: "Token used to authentication against the GitHub.com API. Defaults to the token from the GitHub context of the workflow." + description: "Token used to authenticate against the GitHub.com API." required: false runs: using: composite steps: - name: "Download the binary to the runner's cache dir" shell: bash + env: + VERSION: "${{ inputs.version }}" + FLUX_TOOL_DIR: "${{ inputs.bindir }}" + TOKEN: "${{ inputs.token }}" run: | - VERSION=${{ inputs.version }} - - TOKEN=${{ inputs.token }} - if [[ -z "$TOKEN" ]]; then - TOKEN=${{ github.token }} - fi - if [[ -z "$VERSION" ]] || [[ "$VERSION" = "latest" ]]; then - VERSION=$(curl -fsSL -H "Authorization: token ${TOKEN}" https://api.github.com/repos/fluxcd/flux2/releases/latest | grep tag_name | cut -d '"' -f 4) + if [[ "${TOKEN}" != '' ]]; then + VERSION=$(curl -fsSL -H "Authorization: token ${TOKEN}" https://api.github.com/repos/fluxcd/flux2/releases/latest | grep tag_name | cut -d '"' -f 4) + else + VERSION=$(curl -w "%{url_effective}\n" -IsSL https://github.com/fluxcd/flux2/releases/latest -o /dev/null | sed 's$^.*/$$') + fi fi if [[ -z "$VERSION" ]]; then echo "Unable to determine Flux CLI version" @@ -59,7 +60,6 @@ runs: FLUX_EXEC_FILE="${FLUX_EXEC_FILE}.exe" fi - FLUX_TOOL_DIR=${{ inputs.bindir }} if [[ -z "$FLUX_TOOL_DIR" ]]; then FLUX_TOOL_DIR="${RUNNER_TOOL_CACHE}/flux2/${VERSION}/${OS}/${ARCH}" fi