Skip to content

Commit

Permalink
#526 : Release binaries for Registry Tools (#537)
Browse files Browse the repository at this point in the history
* #526 : Binary release for registry tool

* Authentication shell script

* Windows Batch file

* Added README file for using with APIHUB
  • Loading branch information
giteshk authored Apr 21, 2022
1 parent b0715f5 commit d114442
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 2 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
48 changes: 48 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions auth/HOSTED.bat
Original file line number Diff line number Diff line change
@@ -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=
21 changes: 21 additions & 0 deletions cmd/registry/APIHUB-README.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions cmd/registry/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit d114442

Please sign in to comment.