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 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 any other fleets which exist in the database but are not defined as .yml.' 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.80.2" # 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: ./.github/fleet-gitops/gitops.sh