From d29a3060cbfa57402606520f2d6f63ba6e9bf563 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 10 Nov 2023 12:33:53 +0100 Subject: [PATCH 1/2] ci for golang --- .github/workflows/main.yml | 45 +++++++++++++++++++++++++++++++++++++- snippets/go/.gitignore | 5 ++++- snippets/go/README.md | 6 +++++ snippets/go/go.mod | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 snippets/go/README.md diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5cd677f2..e871ec75 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,7 @@ jobs: repository: breez/breez-sdk ref: ${{ needs.setup.outputs.sdk-ref }} package-version: ${{ needs.setup.outputs.package-version }} - packages-to-publish: '["csharp", "flutter"]' + packages-to-publish: '["csharp", "flutter", "golang"]' use-dummy-binaries: true check-rust: @@ -157,6 +157,49 @@ jobs: working-directory: snippets/csharp run: dotnet build + check-golang: + needs: + - setup + - build-packages + name: Check Go snippets + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Download archived package + uses: actions/download-artifact@v3 + with: + name: breez-sdk-go-${{ needs.setup.outputs.package-version }} + path: snippets/go/packages/breez-sdk-go + + - name: Format the Go snippets + working-directory: snippets/go + run: go fmt + + - name: Test formatted correctly + working-directory: snippets/go + run: | + status=$(git status --porcelain) + if [[ -n "$status" ]]; then + echo "Git status has changes" + echo "$status" + git diff + exit 1 + else + echo "No changes in git status" + fi + + - name: Build the Go snippets + working-directory: snippets/go + run: | + go get + go build . + build: name: Build mdbook runs-on: ubuntu-latest diff --git a/snippets/go/.gitignore b/snippets/go/.gitignore index 8867f65c..4f6c6d1e 100644 --- a/snippets/go/.gitignore +++ b/snippets/go/.gitignore @@ -23,4 +23,7 @@ go.work # Ignore Go binaries **/* !**/*.go -!**/ \ No newline at end of file +!**/*.md +!**/ + +breez-sdk-go \ No newline at end of file diff --git a/snippets/go/README.md b/snippets/go/README.md new file mode 100644 index 00000000..6a91a044 --- /dev/null +++ b/snippets/go/README.md @@ -0,0 +1,6 @@ +## Steps to compile the snippets locally +1. Build a golang package + - By running the publish-all-platforms CI in the breez-sdk repository (use dummy binaries) + - or by cloning https://github.com/breez/breez-sdk-go +2. Place the files in the folder `snippets/go/packages/breez-sdk-go` +3. Happy coding \ No newline at end of file diff --git a/snippets/go/go.mod b/snippets/go/go.mod index 1547ad9b..e49a1833 100644 --- a/snippets/go/go.mod +++ b/snippets/go/go.mod @@ -3,3 +3,4 @@ module main go 1.19 require github.com/breez/breez-sdk-go v0.2.7 +replace github.com/breez/breez-sdk-go => ./packages/breez-sdk-go From 5c2f2b7d4afb8690b93bc8250d04dd3dfd1e9787 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 10 Nov 2023 13:07:30 +0100 Subject: [PATCH 2/2] fix golang unused variables --- snippets/go/getting_started.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/go/getting_started.go b/snippets/go/getting_started.go index 51a4124c..b50264b1 100644 --- a/snippets/go/getting_started.go +++ b/snippets/go/getting_started.go @@ -14,7 +14,7 @@ func (BreezListener) OnEvent(e breez_sdk.BreezEvent) { log.Printf("received event %#v", e) } -func GettingStarted() { +func GettingStarted() *breez_sdk.BlockingBreezServices { // Create the default config seed, err := breez_sdk.MnemonicToSeed("") if err != nil { @@ -38,6 +38,8 @@ func GettingStarted() { if err != nil { log.Fatalf("Connect failed: %#v", err) } + + return sdk } // ANCHOR_END: init-sdk