From d11444289d6e9f244d1f2b18be2529ad850cc326 Mon Sep 17 00:00:00 2001 From: Gitesh Koli Date: Thu, 21 Apr 2022 19:01:14 -0400 Subject: [PATCH] #526 : Release binaries for Registry Tools (#537) * #526 : Binary release for registry tool * Authentication shell script * Windows Batch file * Added README file for using with APIHUB --- .github/workflows/release.yml | 49 +++++++++++++++++++++++++++++++++++ .goreleaser.yml | 48 ++++++++++++++++++++++++++++++++++ auth/HOSTED.bat | 43 ++++++++++++++++++++++++++++++ cmd/registry/APIHUB-README.md | 21 +++++++++++++++ cmd/registry/cmd/root.go | 9 +++++-- 5 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100755 auth/HOSTED.bat create mode 100644 cmd/registry/APIHUB-README.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..5a292eceb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +# Copyright 2022 Google LLC +# +# 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. + +name: Publish registry tool binaries + +on: + push: + tags: + - 'v*.*.*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Prepare + id: prep + run: | + echo ::set-output name=version::${GITHUB_REF#refs/tags/} + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.18 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_VERSION: ${{ steps.prep.outputs.version }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 000000000..dd7515027 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,48 @@ +# Copyright 2022 Google LLC +# +# 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. + +builds: +- id: default + dir: cmd/registry + main: main.go + binary: registry + goos: + - linux + - windows + - darwin + goarch: + - amd64 + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X "github.com/apigee/registry/cmd/registry/cmd.Version={{.Env.RELEASE_VERSION}}" + +archives: +- id: default + format: tar.gz + files: + - LICENSE + - src: cmd/registry/APIHUB-README.md + dst: . + strip_parent: true + - auth/HOSTED.sh + - auth/HOSTED.bat + builds: + - default + format_overrides: + - goos: windows + format: zip +release: + draft: true + prerelease: true diff --git a/auth/HOSTED.bat b/auth/HOSTED.bat new file mode 100755 index 000000000..4bd5374c2 --- /dev/null +++ b/auth/HOSTED.bat @@ -0,0 +1,43 @@ +:: +:: Copyright 2022 Google LLC. All Rights Reserved. +:: +:: 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. +:: + + +:: +:: Configure an environment to run Apigee Registry clients with a Google-hosted service. +:: +:: The following assumes you have run `gcloud auth login` and that the current +:: gcloud project is the one with your Apigee Registry instance. +:: + +WHERE gcloud >nul 2>nul +IF %ERRORLEVEL% NEQ 0 ( +echo 'ERROR: This script requires the gcloud command. Please install it to continue.' +goto :eof +) + +:: Calls to the hosted service are secure. +set APG_REGISTRY_INSECURE= + +:: Get the service address. +set APG_REGISTRY_AUDIENCES=https://apigeeregistry.googleapis.com +set APG_REGISTRY_ADDRESS=apigeeregistry.googleapis.com:443 + +:: The auth token is generated for the gcloud logged-in user. +FOR /F %%g IN ('gcloud config list account --format "value(core.account)"') DO set APG_REGISTRY_CLIENT_EMAIL=%%g +FOR /F %%g IN ('gcloud auth print-access-token %APG_REGISTRY_CLIENT_EMAIL%') DO set APG_REGISTRY_TOKEN=%%g + +:: Calls don't use an API key. +set APG_REGISTRY_API_KEY= diff --git a/cmd/registry/APIHUB-README.md b/cmd/registry/APIHUB-README.md new file mode 100644 index 000000000..d88b80d5d --- /dev/null +++ b/cmd/registry/APIHUB-README.md @@ -0,0 +1,21 @@ +#Registry tool + +To run the binary on MacOS, you will need to unquarantine the binary. +> xattr -d com.apple.quarantine registry + +###How to use registry command with Apigee API hub instance + +Steps: +1. Make sure you have gcloud command installed. +2. Setup the GCP_PROJECT variable. +3. Set you API hub project + > gcloud config set project $GCP_PROJECT +4. Generate the token and set it in the environment variable using + > source auth/HOSTED.sh + + >For windows execute the `auth/HOSTED.bat` file +5. To list all the APIs in your API hub instance run the below command: + > registry list projects/$GCP_PROJECT/locations/global/apis/- + +6. Find a list of other supported commands + > registry help diff --git a/cmd/registry/cmd/root.go b/cmd/registry/cmd/root.go index e1474b642..476807a7d 100644 --- a/cmd/registry/cmd/root.go +++ b/cmd/registry/cmd/root.go @@ -32,10 +32,15 @@ import ( "github.com/spf13/cobra" ) +// Version value will be replaced by the release tag when the binaries are +// generated by GoReleaser. +var Version = "dev" + func Command() *cobra.Command { var cmd = &cobra.Command{ - Use: "registry", - Short: "A simple and eclectic utility for working with the API Registry", + Use: "registry", + Version: Version, + Short: "A simple and eclectic utility for working with the API Registry", } cmd.AddCommand(annotate.Command())