diff --git a/action/Dockerfile b/action/Dockerfile deleted file mode 100644 index 97429a0f..00000000 --- a/action/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM stefanprodan/alpine-base:latest - -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/action/README.md b/action/README.md index 6fa96dcf..09c0c50a 100644 --- a/action/README.md +++ b/action/README.md @@ -10,15 +10,20 @@ Usage: run: flux -v ``` -This action places the `flux` binary inside your repository root under `bin/flux`. -You should add `bin/flux` to your `.gitignore` file, as in the following example: +Note that this action can only be used on GitHub **Linux AMD64** runners. +The latest stable version of the `flux` binary is downloaded from +GitHub [releases](https://github.com/fluxcd/flux2/releases) +and placed at `/usr/local/bin/flux`. -```gitignore -# ignore flux binary -bin/flux -``` +You can download a specific version with: -Note that this action can only be used on GitHub **Linux AMD64** runners. +```yaml + steps: + - name: Setup Flux CLI + uses: fluxcd/flux2/action@main + with: + version: 0.8.0 +``` ### Automate Flux updates diff --git a/action/action.yml b/action/action.yml index d8be8a7a..bb562bb2 100644 --- a/action/action.yml +++ b/action/action.yml @@ -1,15 +1,38 @@ -name: 'kustomize' -description: 'A GitHub Action for running Flux commands' -author: 'Flux project' +name: Setup Flux CLI +description: A GitHub Action for running Flux commands +author: Stefan Prodan branding: - icon: 'command' - color: 'blue' + color: blue + icon: command inputs: version: - description: 'strict semver' + description: "Flux version e.g. 0.8.0 (defaults to latest stable release)" required: false runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.version }} + using: composite + steps: + - name: "Download flux binary to tmp" + shell: bash + run: | + VERSION=${{ inputs.version }} + + if [ -z $VERSION ]; then + VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-) + fi + + BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_amd64.tar.gz" + curl -sL ${BIN_URL} -o /tmp/flux.tar.gz + mkdir -p /tmp/flux + tar -C /tmp/flux/ -zxvf /tmp/flux.tar.gz + - name: "Add flux binary to /usr/local/bin" + shell: bash + run: | + sudo cp /tmp/flux/flux /usr/local/bin + - name: "Cleanup tmp" + shell: bash + run: | + rm -rf /tmp/flux/ /tmp/flux.tar.gz + - name: "Verify correct installation of binary" + shell: bash + run: | + flux -v diff --git a/action/entrypoint.sh b/action/entrypoint.sh deleted file mode 100755 index 4b87d14c..00000000 --- a/action/entrypoint.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Copyright 2020 The Flux authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -VERSION=$1 - -if [ -z $VERSION ]; then - # Find latest release if no version is specified - VERSION=$(curl https://api.github.com/repos/fluxcd/flux2/releases/latest -sL | grep tag_name | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-) -fi - -# Download linux binary -BIN_URL="https://github.com/fluxcd/flux2/releases/download/v${VERSION}/flux_${VERSION}_linux_amd64.tar.gz" -curl -sL $BIN_URL | tar xz - -# Copy binary to GitHub runner -mkdir -p $GITHUB_WORKSPACE/bin -mv ./flux $GITHUB_WORKSPACE/bin -chmod +x $GITHUB_WORKSPACE/bin/flux - -# Print version -$GITHUB_WORKSPACE/bin/flux -v - -# Add binary to GitHub runner path -echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH -echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" >> $GITHUB_PATH