diff --git a/.gitignore b/.gitignore index db5e9cd1..9e40d703 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ completion # Dependency directories (remove the comment below to include it) # vendor/ +/.goreleaser.vendor.yaml diff --git a/.goreleaser.vendor.yaml.tpl b/.goreleaser.vendor.yaml.tpl new file mode 100644 index 00000000..241c74f0 --- /dev/null +++ b/.goreleaser.vendor.yaml.tpl @@ -0,0 +1,97 @@ +# GoReleaser configuration for the ${VENDOR_NAME} CLI. +project_name: ${VENDOR_BINARY} + +before: + hooks: + - go generate ./... + - bash scripts/generate_completions.sh + +builds: + - binary: ${VENDOR_BINARY} + id: ${VENDOR_BINARY} + env: + - CGO_ENABLED=0 + tags: + - vendor + goos: + - linux + - windows + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.vendor=${VENDOR_BINARY}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + - binary: ${VENDOR_BINARY} + id: ${VENDOR_BINARY}-macos + env: + - CGO_ENABLED=0 + tags: + - vendor + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.vendor=${VENDOR_BINARY}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + +checksum: + name_template: checksums.txt + +snapshot: + name_template: '{{ incpatch .Version }}-{{ .Now.Format "2006-01-02" }}-{{ .ShortCommit }}-next' + +universal_binaries: + - id: ${VENDOR_BINARY}-macos + name_template: ${VENDOR_BINARY} + replace: true + +archives: + - name_template: "${VENDOR_BINARY}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - README.md + - completion/* + format_overrides: + - goos: windows + format: zip + +nfpms: + - homepage: https://docs.platform.sh/administration/cli.html + package_name: ${VENDOR_BINARY}-cli + description: ${VENDOR_NAME} CLI + maintainer: Antonis Kalipetis + license: MIT + vendor: Platform.sh + builds: + - ${VENDOR_BINARY} + formats: + - apk + - deb + - rpm + contents: + - src: completion/bash/${VENDOR_BINARY}.bash + dst: /etc/bash_completion.d/${VENDOR_BINARY} + - src: completion/zsh/_${VENDOR_BINARY} + dst: /usr/local/share/zsh/site-functions/_${VENDOR_BINARY} + +release: + disable: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..05c2cada --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,337 @@ +# GoReleaser configuration for the Platform.sh CLI. +project_name: platform + +before: + hooks: + - go generate ./... + - bash scripts/generate_completions.sh + +builds: + - binary: platform + id: platform + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + - binary: platform + id: platform-macos + env: + - CGO_ENABLED=0 + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + + - binary: upsun + id: upsun + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + tags: + - vendor + - upsun + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + - binary: upsun + id: upsun-macos + env: + - CGO_ENABLED=0 + goos: + - darwin + goarch: + - amd64 + - arm64 + tags: + - vendor + - upsun + ldflags: + - -s -w + - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" + - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" + - -X "github.com/platformsh/cli/commands.version={{.Version}}" + - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" + - -X "github.com/platformsh/cli/commands.date={{.Date}}" + - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" + main: ./cmd/platform + +checksum: + name_template: checksums.txt + +snapshot: + name_template: '{{ incpatch .Version }}-{{ .Now.Format "2006-01-02" }}-{{ .ShortCommit }}-next' + +changelog: + sort: asc + use: github-native + +universal_binaries: + - id: platform-macos + name_template: plaform + replace: true + - id: upsun-macos + name_template: upsun + replace: true + +release: + github: + owner: platformsh + name: cli + footer: | + * * * + **Legacy CLI release Notes**: https://github.com/platformsh/legacy-cli/releases/v{{ .Tag }} + **Full Legacy CLI changelog**: https://github.com/platformsh/legacy-cli/compare/v{{ .PreviousTag }}...v{{ .Tag }} + * * * + ## Upgrade + +
+ + Platform.sh + + Upgrade using the same tool you used for installing the CLI: + + ### HomeBrew + + ```console + brew update && brew upgrade platformsh/tap/platformsh-cli + ``` + + ### Scoop + + ```console + scoop update platform + ``` + + ### Bash installer + + ```console + curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash + ``` + +
+ +
+ + Upsun + + Upgrade using the same tool you used for installing the CLI: + + ### HomeBrew + + ```console + brew update && brew upgrade platformsh/tap/upsun-cli + ``` + + ### Scoop + + ```console + scoop update upsun + ``` + + ### Bash installer + + ```console + curl -fsSL https://raw.githubusercontent.com/platformsh/upsun-cli/main/installer.sh | bash + ``` + + + +archives: + - id: platform + name_template: "platform_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - README.md + - completion/* + format_overrides: + - goos: windows + format: zip + builds: + - platform + - platform-macos + + - id: upsun + name_template: "upsun_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - README.md + - completion/* + format_overrides: + - goos: windows + format: zip + builds: + - upsun + - upsun-macos + +brews: + - name: platformsh-cli + repository: + owner: platformsh + name: homebrew-tap + token: "{{ .Env.GITHUB_TOKEN }}" + ids: + - platform + + goarm: "7" + folder: Formula + + commit_author: + name: Antonis Kalipetis + email: antonis.kalipetis@platform.sh + + homepage: https://docs.platform.sh/administration/cli.html + description: Platform.sh CLI + license: MIT + + dependencies: + - name: git + type: optional + + install: | + bin.install "platform" + generate_completions_from_executable(bin/"platform", "completion", shells: [:bash, :zsh]) + + test: | + system "#{bin}/platform --version" + + - name: upsun-cli + repository: + owner: platformsh + name: homebrew-tap + token: "{{ .Env.GITHUB_TOKEN }}" + ids: + - upsun + + goarm: "7" + folder: Formula + + commit_author: + name: Antonis Kalipetis + email: antonis.kalipetis@platform.sh + + homepage: https://docs.deployfriday.net/administration/cli.html + description: Upsun CLI + license: MIT + + dependencies: + - name: git + type: optional + + install: | + bin.install "upsun" + generate_completions_from_executable(bin/"upsun", "completion", shells: [:bash, :zsh]) + + test: | + system "#{bin}/upsun --version" + +scoops: + - name: platform + repository: + owner: platformsh + name: homebrew-tap + token: "{{ .Env.GITHUB_TOKEN }}" + ids: + - platform + + folder: Scoops + commit_author: + name: Antonis Kalipetis + email: antonis.kalipetis@platform.sh + + homepage: https://docs.platform.sh/administration/cli.html + description: Platform.sh CLI + license: MIT + + - name: upsun + repository: + owner: platformsh + name: homebrew-tap + token: "{{ .Env.GITHUB_TOKEN }}" + ids: + - upsun + + folder: Scoops + commit_author: + name: Antonis Kalipetis + email: antonis.kalipetis@platform.sh + + homepage: https://docs.deployfriday.net/administration/cli.html + description: Upsun CLI + license: MIT + +nfpms: + - id: platform + homepage: https://docs.platform.sh/administration/cli.html + package_name: platformsh-cli + description: Platform.sh CLI + maintainer: Antonis Kalipetis + license: MIT + vendor: Platform.sh + builds: + - platform + formats: + - apk + - deb + - rpm + contents: + - src: completion/bash/platform.bash + dst: /etc/bash_completion.d/platform + - src: completion/zsh/_platform + dst: /usr/local/share/zsh/site-functions/_platform + + - id: upsun + homepage: https://docs.deployfriday.net/administration/cli.html + package_name: upsun-cli + description: Upsun CLI + maintainer: Antonis Kalipetis + license: MIT + vendor: Platform.sh + builds: + - upsun + formats: + - apk + - deb + - rpm + contents: + - src: completion/bash/upsun.bash + dst: /etc/bash_completion.d/upsun + - src: completion/zsh/_upsun + dst: /usr/local/share/zsh/site-functions/_upsun diff --git a/Makefile b/Makefile index 054f9b7f..04cc6389 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,10 @@ PHP_VERSION = 8.0.30 LEGACY_CLI_VERSION = 4.10.2 -# Override these environment variables to build with alternative configuration. -CLI_CONFIG_FILE ?= config/platformsh-cli.yaml -GORELEASER_CONFIG_FILE ?= config/platformsh-cli-goreleaser.yaml +GORELEASER_ID ?= platform ifeq ($(GOOS), darwin) - GORELEASER_ID=platform-macos -else - GORELEASER_ID=platform + GORELEASER_ID=$(GORELEASER_ID)-macos endif # The OpenSSL version must be compatible with the PHP version. @@ -67,21 +63,21 @@ php: $(PHP_BINARY_PATH) goreleaser: go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) -.PHONY: copy-config-file -copy-config-file: - cp "$(CLI_CONFIG_FILE)" internal/config/embedded-config.yaml +.PHONY: single +single: goreleaser internal/legacy/archives/platform.phar php ## Build a single target release for Platform.sh or Upsun + PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser build --single-target --id=$(GORELEASER_ID) --snapshot --clean -single: goreleaser internal/legacy/archives/platform.phar php copy-config-file - PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser build --single-target --config="$(GORELEASER_CONFIG_FILE)" --id=$(GORELEASER_ID) --snapshot --clean +.PHONY: snapshot ## Build a snapshot release for Platform.sh and Upsun +snapshot: goreleaser internal/legacy/archives/platform.phar php + PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser build --snapshot --clean -snapshot: goreleaser internal/legacy/archives/platform.phar php copy-config-file - PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser build --snapshot --clean --config="$(GORELEASER_CONFIG_FILE)" - -clean-phar: +.PHONY: clean-phar +clean-phar: ## Clean up the legacy CLI phar rm -f internal/legacy/archives/platform.phar -release: goreleaser clean-phar internal/legacy/archives/platform.phar php copy-config-file - PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser release --clean --config="$(GORELEASER_CONFIG_FILE)" +.PHONY: release +release: goreleaser clean-phar internal/legacy/archives/platform.phar php ## Release the Platform.sh and Upsun CLIs + PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) goreleaser release --clean VERSION=$(VERSION) bash cloudsmith.sh .PHONY: test @@ -95,3 +91,23 @@ golangci-lint: .PHONY: lint lint: golangci-lint ## Run linter golangci-lint run --timeout=10m --verbose + +.goreleaser.vendor.yaml: check-vendor + cat .goreleaser.vendor.yaml.tpl | envsubst > .goreleaser.vendor.yaml + +.PHONY: check-vendor +check-vendor: ## Check that the vendor CLI variables are set +ifndef VENDOR_NAME + $(error VENDOR_NAME is undefined) +endif +ifndef VENDOR_BINARY + $(error VENDOR_BINARY is undefined) +endif + +.PHONY: vendor-release +vendor-release: check-vendor .goreleaser.vendor.yaml goreleaser clean-phar internal/legacy/archives/platform.phar php ## Release a vendor CLI + PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) VENDOR_BINARY="$(VENDOR_BINARY)" VENDOR_NAME="$(VENDOR_NAME)" goreleaser release --clean --config=.goreleaser.vendor.yaml + +.PHONY: vendor-snapshot +vendor-snapshot: .goreleaser.vendor.yaml goreleaser internal/legacy/archives/platform.phar php ## Build a vendor CLI snapshot + PHP_VERSION=$(PHP_VERSION) LEGACY_CLI_VERSION=$(LEGACY_CLI_VERSION) VENDOR_BINARY="$(VENDOR_BINARY)" VENDOR_NAME="$(VENDOR_NAME)" goreleaser build --snapshot --clean --config=.goreleaser.vendor.yaml diff --git a/README.md b/README.md index 67ef54ca..2766a3b6 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,43 @@ yum upgrade -y platformsh-cli The New Platform.sh CLI is built with backwards compatibility in mind. This is why we've embedded PHP, so that all Legacy PHP CLI commands can be executed in the exact same way, making sure that nothing breaks when you switch to it. +## Building binaries, snapshots and releases + +Build a single binary + +```console +# Build a single binary for Platform.sh +make single +# Build a single binary for Upsun +make single GORELEASER_ID=upsun +``` + +Build a snapshot + +```console +# Build and snapshot for Platform.sh and Upsun +make snapshot +# Build a snapshot for a vendor +# Download the config file at internal/config/embedded-config.yaml +make vendor-snapshot VENDOR_NAME='Upsun staging' VENDOR_BINARY='upsunstg' +``` + +Create a release + +```console +# First, create a new tag, if not already on a Git tag +git tag -f -m 'Release v5.0.0' '5.0.0' + +# Create a release for Platform.sh and Upsun +# Expose a GITHUB_TOKEN to use for the release +make release + +# Create a release for a vendor with the default .gorelease.vendor.yaml.tpl +# Download the config file at internal/config/embedded-config.yaml +# Optionally, download the .goreleaser.vendor.yaml file to use a custom one +make vendor-release VENDOR_NAME='Upsun staging' VENDOR_BINARY='upsunstg' +``` + ## Licenses This binary redistributes PHP in a binary form, which comes with the [PHP License](https://www.php.net/license/3_01.txt). - diff --git a/cloudsmith.sh b/cloudsmith.sh index e5d8dc95..b93c531f 100644 --- a/cloudsmith.sh +++ b/cloudsmith.sh @@ -1,3 +1,4 @@ +# Upload Platform.sh packages cloudsmith push deb platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_arm64.deb cloudsmith push deb platformsh/cli/any-distro/any-version dist/platformsh-cli_${VERSION}_linux_amd64.deb @@ -9,3 +10,16 @@ cloudsmith push rpm platformsh/cli/any-distro/any-version dist/platformsh-cli_${ cloudsmith push raw platformsh/cli dist/platform_${VERSION}_linux_amd64.tar.gz --version ${VERSION} cloudsmith push raw platformsh/cli dist/platform_${VERSION}_linux_arm64.tar.gz --version ${VERSION} + +# Upload Upsun packages +cloudsmith push deb platformsh/upsun-cli/any-distro/any-version dist/upsun-cli_${VERSION}_linux_arm64.deb +cloudsmith push deb platformsh/upsun-cli/any-distro/any-version dist/upsun-cli_${VERSION}_linux_amd64.deb + +cloudsmith push alpine platformsh/upsun-cli/alpine/any-version dist/upsun-cli_${VERSION}_linux_amd64.apk +cloudsmith push alpine platformsh/upsun-cli/alpine/any-version dist/upsun-cli_${VERSION}_linux_arm64.apk + +cloudsmith push rpm platformsh/upsun-cli/any-distro/any-version dist/upsun-cli_${VERSION}_linux_amd64.rpm +cloudsmith push rpm platformsh/upsun-cli/any-distro/any-version dist/upsun-cli_${VERSION}_linux_arm64.rpm + +cloudsmith push raw platformsh/upsun-cli dist/upsun_${VERSION}_linux_amd64.tar.gz --version ${VERSION} +cloudsmith push raw platformsh/upsun-cli dist/upsun_${VERSION}_linux_arm64.tar.gz --version ${VERSION} diff --git a/commands/root.go b/commands/root.go index be74347e..c98e2bc4 100644 --- a/commands/root.go +++ b/commands/root.go @@ -28,7 +28,7 @@ func Execute(cnf *config.Config) error { assets := &vendorization.VendorAssets{ Use: "project:init", Binary: cnf.Application.Executable, - ConfigFlavor: cnf.Application.Executable, + ConfigFlavor: cnf.Service.ProjectConfigFlavor, EnvPrefix: strings.TrimSuffix(cnf.Service.EnvPrefix, "_"), ServiceName: cnf.Service.Name, DocsBaseURL: cnf.Service.DocsURL, diff --git a/config/platformsh-cli-goreleaser.yaml b/config/platformsh-cli-goreleaser.yaml deleted file mode 100644 index c866ff25..00000000 --- a/config/platformsh-cli-goreleaser.yaml +++ /dev/null @@ -1,168 +0,0 @@ -# GoReleaser configuration for the Platform.sh CLI. -project_name: platform - -before: - hooks: - - go generate ./... - - bash scripts/generate_completions.sh - -builds: - - binary: platform - id: platform - env: - - CGO_ENABLED=0 - goos: - - linux - - windows - goarch: - - amd64 - - arm64 - ignore: - - goos: windows - goarch: arm64 - ldflags: - - -s -w - - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" - - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" - - -X "github.com/platformsh/cli/commands.version={{.Version}}" - - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" - - -X "github.com/platformsh/cli/commands.date={{.Date}}" - - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" - main: ./cmd/platform - - binary: platform - id: platform-macos - env: - - CGO_ENABLED=0 - goos: - - darwin - goarch: - - amd64 - - arm64 - ldflags: - - -s -w - - -X "github.com/platformsh/cli/internal/legacy.PHPVersion={{.Env.PHP_VERSION}}" - - -X "github.com/platformsh/cli/internal/legacy.LegacyCLIVersion={{.Env.LEGACY_CLI_VERSION}}" - - -X "github.com/platformsh/cli/commands.version={{.Version}}" - - -X "github.com/platformsh/cli/commands.commit={{.Commit}}" - - -X "github.com/platformsh/cli/commands.date={{.Date}}" - - -X "github.com/platformsh/cli/commands.builtBy=goreleaser" - main: ./cmd/platform - -checksum: - name_template: checksums.txt - -snapshot: - name_template: "{{ incpatch .Version }}-{{ .Commit }}-next" - -changelog: - sort: asc - use: github-native - -universal_binaries: - - id: platform-macos - name_template: "{{ .ProjectName }}" - replace: true - -release: - github: - owner: platformsh - name: cli - footer: | - * * * - **Legacy CLI release Notes**: https://github.com/platformsh/legacy-cli/releases/v{{ .Tag }} - **Full Legacy CLI changelog**: https://github.com/platformsh/legacy-cli/compare/v{{ .PreviousTag }}...v{{ .Tag }} - * * * - ## Upgrade - - Upgrade using the same tool you used for installing the CLI: - - ### HomeBrew - - ```console - brew update && brew upgrade platformsh/tap/platformsh-cli - ``` - - ### Scoop - - ```console - scoop update platform - ``` - - ### Bash installer - - ```console - curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash - ``` - -archives: - - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" - files: - - README.md - - completion/* - format_overrides: - - goos: windows - format: zip - rlcp: true - -brews: - - name: platformsh-cli - tap: - owner: platformsh - name: homebrew-tap - token: "{{ .Env.GITHUB_TOKEN }}" - - goarm: "7" - folder: Formula - - commit_author: - name: Antonis Kalipetis - email: antonis.kalipetis@platform.sh - - homepage: https://docs.platform.sh/administration/cli.html - description: Platform.sh CLI - license: MIT - - dependencies: - - name: git - type: optional - - install: | - bin.install "platform" - generate_completions_from_executable(bin/"platform", "completion", shells: [:bash, :zsh]) - - test: | - system "#{bin}/platform --version" - -scoops: - - bucket: - owner: platformsh - name: homebrew-tap - token: "{{ .Env.GITHUB_TOKEN }}" - - folder: Scoops - commit_author: - name: Antonis Kalipetis - email: antonis.kalipetis@platform.sh - - homepage: https://docs.platform.sh/administration/cli.html - description: Platform.sh CLI - license: MIT - -nfpms: - - homepage: https://docs.platform.sh/administration/cli.html - package_name: platformsh-cli - description: Platform.sh CLI - maintainer: Antonis Kalipetis - license: MIT - vendor: Platform.sh - builds: - - platform - formats: - - apk - - deb - - rpm - contents: - - src: completion/bash/platform.bash - dst: /etc/bash_completion.d/platform - - src: completion/zsh/_platform - dst: /usr/local/share/zsh/site-functions/_platform diff --git a/installer.sh b/installer.sh index 7c79f07a..50c5dffd 100644 --- a/installer.sh +++ b/installer.sh @@ -24,6 +24,9 @@ set -euo pipefail # GitHub token check : "${GITHUB_TOKEN:=}" +# Platform.sh CLI vendor to install +: "${VENDOR:=platformsh}" + # CI specifics : "${CI:=}" : "${BUILD_NUMBER:=}" @@ -31,6 +34,8 @@ set -euo pipefail # global variables binary="platform" +vendor_name="Platform.sh" +cloudsmith_repository="cli" cmd_shasum="" cmd_sudo="" dir_bin="/usr/bin" @@ -39,9 +44,21 @@ has_sudo="" kernel="" machine="" version="" +package="platformsh-cli" +docs_url="https://docs.platform.sh" +support_url="https://platform.sh/contact" + +if [ "$VENDOR" == "upsun" ]; then + BREW_FORMULA="platformsh/tap/upsun-cli" + binary="upsun" + vendor_name="Upsun" + package="upsun-cli" + docs_url="https://docs.upsun.com" + cloudsmith_repository="upsun-cli" +fi # create a log file where every output will be pipe to -pipe=/tmp/platformsh-install-$$.tmp +pipe=/tmp/$binary-install-$$.tmp mkfifo $pipe tee < $pipe $INSTALL_LOG & exec 1>&- @@ -86,10 +103,10 @@ function exit_with_error() { output "| |" "error" output "+--------------------------------------------------+" "error" - output "\nGet help with your Platform.sh CLI installation:" "heading" + output "\nGet help with your $vendor_name CLI installation:" "heading" output " Inspect the logs: ${INSTALL_LOG}" - output " Read the docs: https://docs.platform.sh/administration/cli.html" - output " Get help: https://platform.sh/support" + output " Read the docs: $docs_url/administration/cli.html" + output " Get help: $support_url" exit 1 } @@ -97,7 +114,7 @@ function exit_with_error() { function intro() { output "+--------------------------------------------------+" "heading" output "| |" "heading" - output "| Platform.sh CLI Installer |" "heading" + output "| $vendor_name CLI Installer |" "heading" output "| |" "heading" output "+--------------------------------------------------+" "heading" @@ -108,23 +125,23 @@ function outro() { output "" output "+--------------------------------------------------+" "success" output "| |" "success" - output "| Platform.sh CLI has been installed successfully. |" "success" + output "| $vendor_name CLI has been installed successfully. |" "success" output "| |" "success" output "+--------------------------------------------------+" "success" output "\nWhat's next?" "heading" - output " To use the CLI, run: platform" "output" + output " To use the CLI, run: $binary" "output" output "\nUseful links:" "heading" - output " CLI introduction: https://docs.platform.sh/get-started/introduction.html#cli" + output " CLI introduction: $docs_url/get-started/introduction.html#cli" if [ ! -z "$footer_notes" ]; then output "\nWarning during installation:" "heading" output "$footer_notes" "warning" fi - output "\nThank you for using Platform.sh!" + output "\nThank you for using $vendor_name!" } function add_footer_note() { @@ -345,7 +362,7 @@ function check_directories() { fi if ! echo $PATH | grep ${dir_bin} > /dev/null; then - binary="${dir_bin}/platform" + binary="${dir_bin}/$binary" output " [ ] ${dir_bin} is not in \$PATH.\n" "warning" add_footer_note " ⚠ The directory \"${dir_bin}\" is not in \$PATH" @@ -372,14 +389,14 @@ function check_directories() { output " Binary will be installed in ${dir_bin}" } -function install_platformsh_homebrew() { - output "\nInstalling the Platform.sh brew tap" "heading" +function install_homebrew() { + output "\nInstalling the $vendor_name brew tap" "heading" if ! call_user "brew tap ${BREW_TAP}"; then output " could not add tap to brew" "error" exit_with_error fi - output "\nInstalling the Platform.sh CLI formula" "heading" + output "\nInstalling the $vendor_name CLI formula" "heading" # running on Rosetta2? arch='' @@ -395,55 +412,55 @@ function install_platformsh_homebrew() { fi } -function install_platformsh_yum() { - output "\nSetting up the Platform.sh CLI yum repository" "heading" +function install_yum() { + output "\nSetting up the $vendor_name CLI yum repository" "heading" - call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.rpm.sh' > /tmp/setup.rpm.sh" + call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/$cloudsmith_repository/setup.rpm.sh' > /tmp/setup.rpm.sh" if ! call_root "bash -E /tmp/setup.rpm.sh"; then output " could not setup the RPM repository the CLI" "error" exit_with_error fi - output "\nInstalling the Platform.sh CLI" "heading" + output "\nInstalling the $vendor_name CLI" "heading" - if ! call_root "yum install -y platformsh-cli"; then + if ! call_root "yum install -y $package"; then output " could not install the CLI" "error" exit_with_error fi } -function install_platformsh_apt() { - output "\nSetting up the Platform.sh CLI apt repository" "heading" +function install_apt() { + output "\nSetting up the $vendor_name CLI apt repository" "heading" - call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.deb.sh' > /tmp/setup.deb.sh" + call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/$cloudsmith_repository/setup.deb.sh' > /tmp/setup.deb.sh" if ! call_root "bash -E /tmp/setup.deb.sh"; then output " could not setup the APT repository the CLI" "error" exit_with_error fi - output "\nInstalling the Platform.sh CLI" "heading" + output "\nInstalling the $vendor_name CLI" "heading" - if ! call_root "apt-get install -y platformsh-cli"; then + if ! call_root "apt-get install -y $package"; then output " could not install the CLI" "error" exit_with_error fi } -function install_platformsh_apk() { - output "\nSetting up the Platform.sh CLI apk repository" "heading" +function install_apk() { + output "\nSetting up the $vendor_name CLI apk repository" "heading" - call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/cli/setup.alpine.sh' > /tmp/setup.alpine.sh" + call_user "curl -1sLf 'https://dl.cloudsmith.io/public/platformsh/$cloudsmith_repository/setup.alpine.sh' > /tmp/setup.alpine.sh" if ! call_root "bash -E /tmp/setup.alpine.sh"; then output " could not setup the APK repository the CLI" "error" exit_with_error fi - output "\nInstalling the Platform.sh CLI" "heading" + output "\nInstalling the $vendor_name CLI" "heading" - if ! call_root "apk add platformsh-cli --update-cache"; then + if ! call_root "apk add $package --update-cache"; then output " could not install the CLI" "error" exit_with_error fi @@ -471,14 +488,14 @@ function is_ci { fi } -function install_platformsh_raw() { +function install_raw() { # Start downloading the right version - output "\nDownloading the Platform.sh CLI" "heading" + output "\nDownloading the $vendor_name CLI" "heading" - url="${URL}/${version}/platform_${version}_${kernel}_${machine}.tar.gz" + url="${URL}/${version}/${binary}_${version}_${kernel}_${machine}.tar.gz" output " Downloading ${url}"; tmp_dir=$(mktemp -d) - tmp_name="platformsh-"$(date +"%s") + tmp_name="$binary-"$(date +"%s") if ! github_curl $url > "${tmp_dir}/${tmp_name}.tgz"; then output " the download failed" "error" exit_with_error @@ -488,7 +505,7 @@ function install_platformsh_raw() { tar -C ${tmp_dir} -xzf "${tmp_dir}/${tmp_name}.tgz" output " Making the binary executable" - chmod 0755 "${tmp_dir}/platform" + chmod 0755 "${tmp_dir}/$binary" if [ ! -d $dir_bin ]; then output " Creating ${dir_bin} directory" @@ -496,21 +513,20 @@ function install_platformsh_raw() { fi output " Installing the binary under ${dir_bin}" - binary="${dir_bin}/platform" - call_try_user "mv '${tmp_dir}/platform' '${binary}'" "Failed to move the binary ${binary}" + call_try_user "mv '${tmp_dir}/$binary' '${dir_bin}/${binary}'" "Failed to move the binary ${binary}" } -function install_platformsh() { +function install() { if [ "homebrew" = "${INSTALL_METHOD}" ]; then - install_platformsh_homebrew + install_homebrew elif [ "yum" = "${INSTALL_METHOD}" ]; then - install_platformsh_yum + install_yum elif [ "apt" = "${INSTALL_METHOD}" ]; then - install_platformsh_apt + install_apt elif [ "apk" = "${INSTALL_METHOD}" ]; then - install_platformsh_apk + install_apk elif [ "raw" = "${INSTALL_METHOD}" ]; then - install_platformsh_raw + install_raw fi } @@ -529,5 +545,5 @@ if [ "raw" = "${INSTALL_METHOD}" ]; then elif [ "apt" = "${INSTALL_METHOD}" ] || [ "yum" = "${INSTALL_METHOD}" ] || [ "apk" = "${INSTALL_METHOD}" ]; then check_curl fi -install_platformsh +install outro diff --git a/internal/config/config.go b/internal/config/config.go index 9583cd49..fc8b3f4c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,7 +2,6 @@ package config import ( "context" - _ "embed" "fmt" "os" @@ -10,9 +9,6 @@ import ( "gopkg.in/yaml.v3" ) -//go:embed embedded-config.yaml -var embedded []byte - // LoadYAML reads the configuration file from the environment if specified, falling back to the embedded file. func LoadYAML() ([]byte, error) { if path := os.Getenv("CLI_CONFIG_FILE"); path != "" { diff --git a/internal/config/config_platformsh.go b/internal/config/config_platformsh.go new file mode 100644 index 00000000..052b5110 --- /dev/null +++ b/internal/config/config_platformsh.go @@ -0,0 +1,9 @@ +//go:build !vendor +// +build !vendor + +package config + +import _ "embed" + +//go:embed platformsh-cli.yaml +var embedded []byte diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 2cfa20d3..af901977 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -31,6 +31,7 @@ func TestFromYAML(t *testing.T) { assert.Equal(t, 3600, cnf.Updates.CheckInterval) assert.Equal(t, cnf.Application.UserConfigDir, cnf.Application.WritableUserDir) assert.Equal(t, "example-cli-tmp", cnf.Application.TempSubDir) + assert.Equal(t, "platform", cnf.Service.ProjectConfigFlavor) writableDir, err := cnf.WritableUserDir() assert.NoError(t, err) diff --git a/internal/config/config_upsun.go b/internal/config/config_upsun.go new file mode 100644 index 00000000..db71cf12 --- /dev/null +++ b/internal/config/config_upsun.go @@ -0,0 +1,9 @@ +//go:build vendor && upsun +// +build vendor,upsun + +package config + +import _ "embed" + +//go:embed upsun-cli.yaml +var embedded []byte diff --git a/internal/config/config_vendor.go b/internal/config/config_vendor.go new file mode 100644 index 00000000..0fb51d8c --- /dev/null +++ b/internal/config/config_vendor.go @@ -0,0 +1,9 @@ +//go:build vendor && !upsun +// +build vendor,!upsun + +package config + +import _ "embed" + +//go:embed embedded-config.yaml +var embedded []byte diff --git a/config/platformsh-cli.yaml b/internal/config/platformsh-cli.yaml similarity index 98% rename from config/platformsh-cli.yaml rename to internal/config/platformsh-cli.yaml index 36a75d89..15a04145 100644 --- a/config/platformsh-cli.yaml +++ b/internal/config/platformsh-cli.yaml @@ -35,6 +35,7 @@ service: project_config_dir: '.platform' app_config_file: '.platform.app.yaml' + project_config_flavor: 'platform' console_url: 'https://console.platform.sh' diff --git a/internal/config/schema.go b/internal/config/schema.go index 9cde7ba1..4a22ff45 100644 --- a/internal/config/schema.go +++ b/internal/config/schema.go @@ -52,12 +52,13 @@ type Config struct { SiteDomains []string `validate:"required" yaml:"site_domains"` // e.g. ["platformsh.site", "tst.site"] } `validate:"required,dive"` Service struct { - Name string `validate:"required"` // e.g. "Platform.sh" - Slug string `validate:"required,ascii"` // e.g. "platformsh" - EnvPrefix string `validate:"required" yaml:"env_prefix"` // e.g. "PLATFORM_" - ProjectConfigDir string `validate:"required" yaml:"project_config_dir"` // e.g. ".platform" - ConsoleURL string `validate:"omitempty,url" yaml:"console_url"` // e.g. "https://console.platform.sh" - DocsURL string `validate:"omitempty,url" yaml:"docs_url"` // e.g. "https://docs.platform.sh" + Name string `validate:"required"` // e.g. "Platform.sh" + Slug string `validate:"required,ascii"` // e.g. "platformsh" + EnvPrefix string `validate:"required" yaml:"env_prefix"` // e.g. "PLATFORM_" + ProjectConfigDir string `validate:"required" yaml:"project_config_dir"` // e.g. ".platform" + ProjectConfigFlavor string `validate:"omitempty" yaml:"project_config_flavor"` // default: "platform" + ConsoleURL string `validate:"omitempty,url" yaml:"console_url"` // e.g. "https://console.platform.sh" + DocsURL string `validate:"omitempty,url" yaml:"docs_url"` // e.g. "https://docs.platform.sh" } `validate:"required,dive"` } @@ -66,6 +67,7 @@ func (c *Config) applyDefaults() { c.Application.UserStateFile = "state.json" c.Updates.Check = true c.Updates.CheckInterval = 3600 + c.Service.ProjectConfigFlavor = "platform" } // applyDynamicDefaults applies defaults to config after parsing and validating. diff --git a/internal/config/upsun-cli.yaml b/internal/config/upsun-cli.yaml new file mode 100644 index 00000000..59d6af92 --- /dev/null +++ b/internal/config/upsun-cli.yaml @@ -0,0 +1,76 @@ +# Upsun CLI configuration +# +# Based on the legacy CLI config in https://github.com/platformsh/legacy-cli/blob/main/config.yaml +# +# See ../internal/config/schema.go for the required keys +wrapper: + homebrew_tap: platformsh/tap/upsun-cli + github_repo: platformsh/cli + +application: + name: "Upsun CLI" + slug: "upsun" + executable: "upsun" + env_prefix: "UPSUN_CLI_" + user_config_dir: ".upsun-cli" + + disabled_commands: + - self:install + - self:update + - local:build + - local:drush-aliases + - project:variable:delete + - project:variable:get + - project:variable:set + - variable:disable + - variable:enable + - variable:set + +service: + name: "Upsun" + slug: "upsun" + + env_prefix: "PLATFORM_" + header_prefix: "X-Upsun" + + project_config_dir: ".upsun" + project_config_flavor: "upsun" + + console_url: "https://console.upsun.com" + + docs_url: "https://docs.upsun.com" + docs_search_url: "https://docs.upsun.com/search.html?q={{ terms }}" + + register_url: "https://auth.upsun.com/register" + reset_password_url: "https://auth.upsun.com/reset-password" + + pricing_url: "https://upsun.com/pricing" + + activity_type_list_url: "https://docs.upsun.com/integrations/activity/reference.html#type" + + runtime_operations_help_url: "https://docs.upsun.com/create-apps/runtime-operations.html" + +api: + base_url: "https://proxy.upsun.com" + + auth_url: "https://auth.upsun.com" + oauth2_client_id: "upsun-cli" + + ssh_domain_wildcards: ["*.platform.sh", "*.upsun.com"] + + invitations: true + organizations: true + centralized_permissions: true + user_verification: true + metrics: true + sizing: true + projects_list_new: true + + vendor_filter: upsun + +detection: + git_remote_name: "upsun" + git_domain: "upsun.com" + site_domains: ["platformsh.site", "tst.site", "upsunapp.com"] + + api_domain_suffix: "upsun.com" diff --git a/scripts/generate_completions.sh b/scripts/generate_completions.sh index 10c47ade..ea32425e 100644 --- a/scripts/generate_completions.sh +++ b/scripts/generate_completions.sh @@ -4,3 +4,12 @@ rm -rf completion mkdir -p completion/bash completion/zsh go run cmd/platform/main.go completion bash > completion/bash/platform.bash go run cmd/platform/main.go completion zsh > completion/zsh/_platform + +go run --tags=vendor,upsun cmd/platform/main.go completion bash > completion/bash/upsun.bash +go run --tags=vendor,upsun cmd/platform/main.go completion zsh > completion/zsh/_upsun + +# if $VENDOR_BINARY is not empty +if [ -nz "$VENDOR_BINARY" ]; then + go run --tags=vendor cmd/platform/main.go completion bash > completion/bash/$VENDOR_BINARY.bash + go run --tags=vendor cmd/platform/main.go completion zsh > completion/zsh/_$VENDOR_BINARY +fi