diff --git a/.github/gitops-action-fleets/action.yml b/.github/gitops-action-fleets/action.yml new file mode 100644 index 0000000..bdb92fc --- /dev/null +++ b/.github/gitops-action-fleets/action.yml @@ -0,0 +1,59 @@ +name: fleetctl-gitops +description: Runs fleetctl gitops to apply configuration to Fleet + +inputs: + working-directory: + description: 'The working directory, which should be the root of the fleet-gitops repository.' + default: './' + dry-run-only: + description: 'Whether to only run the fleetctl gitops commands in dry-run mode.' + default: 'false' + delete-other-fleets: + description: 'Whether to delete other fleets in Fleet which are not part of the gitops config.' + default: 'true' + +runs: + using: "composite" + steps: + - name: Install fleetctl + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + FLEET_URL="${FLEET_URL%/}" + FLEET_VERSION="$(curl "$FLEET_URL/api/v1/fleet/version" --header "Authorization: Bearer $FLEET_API_TOKEN" --fail --silent | jq --raw-output '.version')" + DEFAULT_FLEETCTL_VERSION="4.82.0" + + # Decide which fleetctl version to install: + # If the server returns a clean version (e.g. 4.74.0), use that. + # If the server returns a snapshot (e.g. 0.0.0-SNAPSHOT-xxxxx) or is empty, pin to DEFAULT_FLEETCTL_VERSION. + if [[ -z "$FLEET_VERSION" ]]; then + INSTALL_VERSION="$DEFAULT_FLEETCTL_VERSION" + elif [[ "$FLEET_VERSION" == 0.0.0-SNAPSHOT* ]]; then + INSTALL_VERSION="$DEFAULT_FLEETCTL_VERSION" + elif [[ "$FLEET_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + INSTALL_VERSION="$FLEET_VERSION" + else + # Strip anything after + (e.g. 4.81.0+foobar -> 4.81.0) + FLEET_VERSION="${FLEET_VERSION%%\+*}" + if [[ "$FLEET_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + INSTALL_VERSION="$FLEET_VERSION" + else + INSTALL_VERSION="$DEFAULT_FLEETCTL_VERSION" + fi + fi + + echo "Installing fleetctl v$INSTALL_VERSION..." + npm install -g "fleetctl@$INSTALL_VERSION" || npm install -g fleetctl@latest + + - name: Configure fleetctl + shell: bash + working-directory: ${{ inputs.working-directory }} + run: fleetctl config set --address ${{ env.FLEET_URL }} --token ${{ env.FLEET_API_TOKEN }} + + - name: Run fleetctl gitops commands + shell: bash + working-directory: ${{ inputs.working-directory }} + env: + FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }} + FLEET_DELETE_OTHER_FLEETS: ${{ inputs.delete-other-fleets }} + run: ./gitops-fleets.sh diff --git a/.github/gitops-action-rc/action.yml b/.github/gitops-action-rc/action.yml index caeb94f..cfa560f 100644 --- a/.github/gitops-action-rc/action.yml +++ b/.github/gitops-action-rc/action.yml @@ -45,4 +45,4 @@ runs: env: FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }} FLEET_DELETE_OTHER_FLEETS: ${{ inputs.delete-other-fleets }} - run: ./gitops-rc.sh + run: ./gitops-fleets.sh diff --git a/.github/gitops-action/action.yml b/.github/gitops-action/action.yml index 234e89d..70bbaee 100644 --- a/.github/gitops-action/action.yml +++ b/.github/gitops-action/action.yml @@ -21,7 +21,7 @@ runs: run: | FLEET_URL="${FLEET_URL%/}" FLEET_VERSION="$(curl "$FLEET_URL/api/v1/fleet/version" --header "Authorization: Bearer $FLEET_API_TOKEN" --fail --silent | jq --raw-output '.version')" - DEFAULT_FLEETCTL_VERSION="4.81.2" + DEFAULT_FLEETCTL_VERSION="4.82.0" # Decide which fleetctl version to install: # If the server returns a clean version (e.g. 4.74.0), use that. diff --git a/gitops-rc.sh b/gitops-fleets.sh similarity index 100% rename from gitops-rc.sh rename to gitops-fleets.sh