diff --git a/.circleci/build_lib.sh b/.circleci/build_lib.sh index b60122ebec..726997165f 100755 --- a/.circleci/build_lib.sh +++ b/.circleci/build_lib.sh @@ -10,7 +10,7 @@ unamestr=`uname` export ARCH=$2 export CMAKE=cmake export PATH=$PATH:~/cmake_folder/bin -export PG_INCLUDE_DIR=`[[ "$unamestr" = "Darwin" ]] && echo -n "/usr/local/opt/postgresql/include" || echo -n "/usr/include/postgresql"` +export PG_INCLUDE_DIR=`[[ "$unamestr" = "Darwin" ]] && echo -n "/usr/local/opt/postgresql@13/include" || echo -n "/usr/include/postgresql"` echo "Use $PG_INCLUDE_DIR for PGSQL" diff --git a/.circleci/config.yml b/.circleci/config.yml index b8d343055f..4175569890 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -242,6 +242,8 @@ workflows: - build_linux_release: <<: *default_context filters: + branches: + only: main tags: only: /.*/ - build_linux_jni_release: @@ -250,27 +252,37 @@ workflows: tags: only: /.*/ branches: - only: /^(?!pull\/).*$/ + only: main - build_macos_release: <<: *default_context filters: tags: only: /.*/ + branches: + only: main - build_macos_jni_release: <<: *default_context filters: tags: only: /.*/ branches: - only: /^(?!pull\/).*$/ + only: main - build_linux_debug: <<: *default_context + filters: + branches: + only: main - build_macos_debug: <<: *default_context + filters: + branches: + only: main - publish_jar: requires: - build_linux_jni_release - build_macos_jni_release filters: tags: - only: /.*/ \ No newline at end of file + only: /.*/ + branches: + only: main diff --git a/.circleci/setup_macos.sh b/.circleci/setup_macos.sh index f917696d5e..921d66e72a 100755 --- a/.circleci/setup_macos.sh +++ b/.circleci/setup_macos.sh @@ -33,8 +33,8 @@ brew install --build-from-source cmake echo "========> Install PostgreSQL" # Install with verbose otherwise the setup may timeout the CI because it doesn't log. -brew install --verbose postgresql -export CPLUS_INCLUDE_PATH="/usr/local/Cellar/postgresql/12.3_4/include:$CPLUS_INCLUDE_PATH" +brew install --verbose postgresql@13 +brew link --overwrite postgresql@13 echo "========> Install Sqlite" diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh new file mode 100755 index 0000000000..5a1fe696bc --- /dev/null +++ b/.github/scripts/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir _build_tests +cd _build_tests +cmake .. -DTARGET_JNI=${BUILD_JNI-OFF} -DBUILD_TESTS=ON -DNIX_BUILD=OFF -DCCACHE=ON -DSYS_OPENSSL=ON -DOPENSSL_USE_STATIC_LIBS=TRUE -GNinja +echo "========= Building libcore" +cmake --build . --parallel --target ledger-core-static +cmake --build . --parallel --target ledger-core +cmake --build . --parallel diff --git a/.github/scripts/publish_to_wd.sh b/.github/scripts/publish_to_wd.sh new file mode 100755 index 0000000000..d9098e4c64 --- /dev/null +++ b/.github/scripts/publish_to_wd.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd $GITHUB_WORKSPACE/ledger-wallet-daemon + +# Bump libcore version +sed -i -E 's/(val libcore *= *\")(.*)\"/\1'$VERSION'\"/' build.sbt + +# Commit & push changes +git checkout -b bump_libcore_$VERSION +git add lib # libcore +git config --global user.name "${GITHUB_ACTOR}" +git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" +git commit -m "Bump libcore to $VERSION" +git push --set-upstream origin bump_libcore_$VERSION +gh pr create --title "Bump libcore to $VERSION" \ + --body "Automatic update from libcore release" \ + --base main \ + --head bump_libcore_$VERSION \ No newline at end of file diff --git a/.github/scripts/test.sh b/.github/scripts/test.sh new file mode 100755 index 0000000000..24238372e8 --- /dev/null +++ b/.github/scripts/test.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd _build_tests +ctest --output-on-failure diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 05fa483028..ce38ce37b1 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -1,10 +1,19 @@ name: clang-format Check -on: [push, pull_request] +on: + pull_request: + paths: + - core/** + - .clang-format + - .github/workflows/clang-format-check.yml jobs: formatting-check: name: Formatting Check runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@v2 - name: Run clang-format style check for C/C++/Protobuf programs. uses: jidicula/clang-format-action@v4.5.0 diff --git a/.github/workflows/clang-tidty-review.yml b/.github/workflows/clang-tidty-review.yml index 2b4abcd314..261bea9e46 100644 --- a/.github/workflows/clang-tidty-review.yml +++ b/.github/workflows/clang-tidty-review.yml @@ -1,5 +1,10 @@ name: "Clang-tidy Code Review" -on: [pull_request] +on: + pull_request: + paths: + - core/** + - .clang-tidy + - .github/workflows/clang-tidy-review.yml jobs: build: diff --git a/.github/workflows/nix_release_builds.yml b/.github/workflows/nix_release_builds.yml index bbc5e48dbe..e98aaf7caf 100644 --- a/.github/workflows/nix_release_builds.yml +++ b/.github/workflows/nix_release_builds.yml @@ -1,30 +1,28 @@ -name: "Nix Release builds" +name: "Package libcore" on: - pull_request: - branches: - - main - - release/4.0.0 - - release/4.1.0 - - release/4.2.0 - - develop - push: - branches: - - main - - release/4.0.0 - - release/4.1.0 - - release/4.2.0 - - develop - tags: - - '*' - workflow_run: - workflows: ["Release libcore"] - types: - - completed + workflow_dispatch: + inputs: + release: + description: Create Release JAR package (instead of SNAPSHOT). Version number will be taken from CMakeLists.txt + required: true + type: boolean + default: false + version: + description: Custom version of jar package (applies only if `release` is true) + required: false + type: string + workflow_call: + inputs: + release: + required: false + type: boolean + version: + required: false + type: string jobs: libcore_version: name: Compute libcore version runs-on: ubuntu-latest - if: ${{ github.event_name != "workflow_run" || github.event.workflow_run.conclusion == 'success' }} outputs: lib_version: ${{ steps.lib_version.outputs.lib_version }} deploy_dynlibs: ${{ steps.lib_version.outputs.deploy_dynlibs }} @@ -38,53 +36,25 @@ jobs: # https://github.com/actions/checkout/blob/v2.3.4/README.md - name: Set version slug and push_to_S3 flags id: lib_version - run: bash nix/scripts/export_libcore_version.sh ${{ github.event.pull_request.head.ref }} - Ubuntu_jni: - name: Linux (with JNI) - needs: libcore_version - runs-on: ubuntu-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@v2.3.4 - with: - submodules: 'recursive' - - uses: cachix/install-nix-action@v14.1 - with: - nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/5f746317f10f7206f1dbb8dfcfc2257b04507eee.tar.gz - - run: nix-build - - uses: actions/upload-artifact@v2 - with: - name: ${{ needs.libcore_version.outputs.lib_version }}-linux-libledgercore - path: result/lib/libledger-core.so - retention-days: 30 - MacOS_jni: - name: MacOS (with JNI) - needs: libcore_version - runs-on: macos-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.9.1 - with: - access_token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@v2.3.4 - with: - submodules: 'recursive' - - uses: cachix/install-nix-action@v14.1 - with: - nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/5f746317f10f7206f1dbb8dfcfc2257b04507eee.tar.gz - - run: nix-build - - uses: actions/upload-artifact@v2 - with: - name: ${{ needs.libcore_version.outputs.lib_version }}-macos-libledgercore - path: result/lib/libledger-core.dylib - retention-days: 30 + run: bash nix/scripts/export_libcore_version.sh + env: + RELEASE: ${{ inputs.release || 'false' }} + VERSION: ${{ inputs.version }} + Build_Release_JNI: + name: Build Release with JNI + uses: ./.github/workflows/tests.yml + secrets: inherit # pass all secrets + with: + buildJni: 'ON' JAR: name: Jar build (MacOS + Linux) - needs: [Ubuntu_jni, MacOS_jni, libcore_version] + needs: [libcore_version, Build_Release_JNI] runs-on: ubuntu-latest + container: + image: ghcr.io/ledgerhq/lib-ledger-core-build-env/lib-ledger-core-build-env:1.0.3 + credentials: + username: ${{ secrets.CI_BOT_USERNAME }} + password: ${{ secrets.CI_BOT_TOKEN }} steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.9.1 @@ -93,23 +63,19 @@ jobs: - uses: actions/checkout@v2.3.4 with: submodules: 'recursive' - - uses: cachix/install-nix-action@v14.1 - with: - nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/5f746317f10f7206f1dbb8dfcfc2257b04507eee.tar.gz - run: mkdir -p jar_build/src/main/resources/resources/djinni_native_libs - name: Fetch Linux so uses: actions/download-artifact@v2 with: - name: ${{ needs.libcore_version.outputs.lib_version }}-linux-libledgercore + name: linux-ubuntu-22.04-libledgercore path: jar_build/src/main/resources/resources/djinni_native_libs - name: Fetch MacOS dylib uses: actions/download-artifact@v2 with: - name: ${{ needs.libcore_version.outputs.lib_version }}-macos-libledgercore + name: macos-libledgercore path: jar_build/src/main/resources/resources/djinni_native_libs - - run: nix-shell --run "bash nix/scripts/build_jar.sh" nix/libcore-jar.nix + - run: bash nix/scripts/build_jar.sh env: - LIB_VERSION: ${{ needs.libcore_version.outputs.lib_version }} GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} JAR_VERSION: ${{ needs.libcore_version.outputs.jar_version }} - uses: actions/upload-artifact@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9bed46d91c..e59c3150f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,20 +3,32 @@ on: workflow_dispatch: inputs: version: - description: "Release version" + description: "Release version (tag)" required: true type: string releaseNote: - description: "Should create a Release" + description: "Create a Github Release note" required: true type: boolean default: true + preRelease: + description: "This is a pre-release" + required: true + type: boolean + default: false + draft: + description: "Save Release as draft" + required: true + type: boolean + default: false jobs: Release: runs-on: ubuntu-22.04 env: VERSION: ${{ github.event.inputs.version }} RELEASE_NOTE: ${{ github.event.inputs.releaseNote }} + PRE_RELEASE: ${{ github.event.inputs.preRelease }} + DRAFT: ${{ github.event.inputs.draft }} steps: - uses: actions/checkout@v2.3.4 - name: Set version number @@ -37,14 +49,42 @@ jobs: script: | try { await github.rest.repos.createRelease({ - draft: false, + draft: process.env.DRAFT, generate_release_notes: true, name: process.env.RELEASE_TAG, owner: context.repo.owner, - prerelease: false, + prerelease: process.env.PRE_RELEASE, repo: context.repo.repo, tag_name: process.env.VERSION, }); } catch (error) { core.setFailed(error.message); - } \ No newline at end of file + } + Build: + name: Build Release with JNI + uses: ./.github/workflows/nix_release_builds.yml + secrets: inherit # pass all secrets + needs: [ Release ] + with: + release: true + version: ${{ github.event.inputs.version }} + Publish: + name: Publish to WD + needs: [Build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + name: Checkout libcore + - uses: actions/checkout@v3 + name: Checkout wallet-daemont + with: + token: ${{ secrets.CI_BOT_TOKEN }} + repository: LedgerHQ/ledger-wallet-daemon + submodules: true + path: ledger-wallet-daemon + - name: Publish to WD + env: + GH_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + VERSION: ${{ github.event.inputs.version }} + run: .github/scripts/publish_to_wd.sh + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index deeef3e00a..ca8309c096 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,47 +1,110 @@ -name: "Nix Tests" +name: "Build & Test" on: - pull_request: - branches: - - main - - release/4.0.0 - - release/4.1.0 - - release/4.2.0 - - develop push: - branches: - - main - - release/4.0.0 - - release/4.1.0 - - release/4.2.0 - - develop + workflow_call: + inputs: + buildJni: + required: false + type: string + default: 'OFF' jobs: Unixes: runs-on: ${{ matrix.os }} + container: + image: ghcr.io/ledgerhq/lib-ledger-core-build-env/lib-ledger-core-build-env:1.0.3 + credentials: + username: ${{ secrets.CI_BOT_USERNAME }} + password: ${{ secrets.CI_BOT_TOKEN }} + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: libcore + POSTGRES_PASSWORD: libcore_pwd + POSTGRES_DB: test_db + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 strategy: fail-fast: false matrix: - os: [ubuntu-18.04, ubuntu-20.04, macos-latest] + os: [ubuntu-20.04, ubuntu-22.04] + env: + BUILD_JNI: ${{ inputs.buildJni || 'OFF' }} steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.9.1 with: access_token: ${{ secrets.GITHUB_TOKEN }} - - name: Disable Linux TCP/UDP offload - if: ${{ startsWith(matrix.os, 'ubuntu') }} - run: | - sudo ethtool -K eth0 tx off rx off - - name: Disable MacOS TCP/UDP offload - if: ${{ startsWith(matrix.os, 'macos') }} - run: | - sudo sysctl -w net.link.generic.system.hwcksum_tx=0 - sudo sysctl -w net.link.generic.system.hwcksum_rx=0 - uses: actions/checkout@v2.3.4 with: submodules: 'recursive' - - uses: cachix/install-nix-action@v14.1 + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 with: - nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/5f746317f10f7206f1dbb8dfcfc2257b04507eee.tar.gz - - name: Build and run tests - run: nix-shell --run "bash nix/scripts/build_run_tests.sh" default.nix + key: ${{ matrix.os }} + max-size: "3G" + - name: Build + run: .github/scripts/build.sh + - name: Tests + if: env.BUILD_JNI == 'OFF' + run: .github/scripts/test.sh env: - BUILD_LOAD_LIMIT: 2 + POSTGRES_HOST: postgres + POSTGRES_PORT: 5432 + POSTGRES_USER: libcore + POSTGRES_PASSWORD: libcore_pwd + POSTGRES_DB: test_db + - uses: actions/upload-artifact@v2 + with: + name: linux-${{ matrix.os }}-libledgercore + path: _build_tests/core/src/libledger-core.so + retention-days: 30 + + Macos: + runs-on: macos-12 + env: + BUILD_JNI: ${{ inputs.buildJni || 'OFF' }} + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v2.3.4 + with: + submodules: 'recursive' + - name: Setup Macos + run: | + brew install ninja + brew install openssl + brew install postgresql@13 + brew link --overwrite postgresql@13 + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: macos + max-size: "3G" + - name: Prepare DB + run: | + mkdir test_db + initdb -D test_db + pg_ctl start -D test_db -l db_log -o "-i -h localhost -p 5432" + createdb -h localhost -p 5432 test_db + - name: Build + run: .github/scripts/build.sh + env: + OPENSSL_ROOT_DIR: /usr/local/opt/openssl/ + - name: Tests + if: env.BUILD_JNI == 'OFF' + run: .github/scripts/test.sh + env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_DB: test_db + - uses: actions/upload-artifact@v2 + with: + name: macos-libledgercore + path: _build_tests/core/src/libledger-core.dylib + retention-days: 30 diff --git a/README.md b/README.md index 4473170d57..f7ac74159a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Core library which will be used by Ledger applications. - [Nix build](#nix-build) - [Non nix builds](#non-nix-builds) - [Build library with PostgreSQL](#build-library-with-postgresql) + - [Publish libcore JAR into local repository](#publish-libcore-JAR-into-local-repository) - [Build production-like version of the library](#build-production-like-version-of-the-library) - [Documentation](#documentation) - [Binding to node.js](#binding-to-nodejs) @@ -24,6 +25,7 @@ Core library which will be used by Ledger applications. - [Developement guidelines](#developement-guidelines) - [Local tests](#local-tests) - [CI](#ci) + - [Release process](#release-process) - [Q/A and troubleshooting](#qa-and-troubleshooting) - [I have updated an include file and test code doesn’t see the changes!](#i-have-updated-an-include-file-and-test-code-doesnt-see-the-changes) - [I have upgraded my macOSX system and now I can’t compile anymore.](#i-have-upgraded-my-macosx-system-and-now-i-cant-compile-anymore) @@ -223,6 +225,24 @@ if you want to run only one specific unit test. (e.g. the test case `BitcoinLike ``` ./core/test/integration/build/ledger-core-integration-tests "--gtest_filter=BitcoinLikeWalletSynchronization.MediumXpubSynchronization" ``` + +## Publish libcore JAR into local repository + +First you need to build the libcore with JNI enabled +```bash +mkdir build_lib_jni +cd build_lib_jni +cmake .. -DSYS_OPENSSL=ON -DOPENSSL_USE_STATIC_LIBS=TRUE -DTARGET_JNI=ON -DPG_SUPPORT=ON +cmake --build . --parallel +``` + +Then you can build & publish the jar with `sbt publishLocal`. A tool script wraps it: +```bash +./tools/publish-jar-local.sh ./lib_build_dir_jni +``` + +It will publish a maven artifact (available at ~/.ivy2/local/co.ledger/ledger-lib-core_2.12/local-SNAPSHOT) that can be used by any third party + ## Build production-like version of the library To build the production-like version of the library use script `tools/prod-like-build.sh`. This script requires @@ -340,26 +360,6 @@ sudo apt install clang-format-14 ### CI -#### Appveyor - -You are advised to link your GitHub account to both [CircleCI] and [Appveyor] by signing-in. Because -we are using shared runners and resources, we have to share CI power with other teams. It’s -important to note that we don’t always need to run the CI. Example of situations when we do not need -it: - - - When we are updating documentation. - - When we are changing a tooling script that is not part of any testing suite (yet). - - When we are making a *WIP* PR that doesn’t require running the CI until everyone has agreed on - the code (this is a tricky workflow but why not). - -In those cases, please include the `[skip ci]` or `[ci skip]` text **in your commit message’s -title**. You could tempted to put it in the body of your message but that will not work with -[Appveyor]. - -Finally, it’s advised to put it on every commit and rebase at the end to remove the `[skip ci]` tag -from your commits’ messags to have the CI re-enabled, but some runners might be smart enough to do -it for all commits in the PR. - #### Rebasing Rebasing is done easily. If your PR wants to merge `feature/stuff -> develop`, you can do something @@ -374,6 +374,20 @@ Change the `pick` to `r` or `reword` at the beginning of each lines **without ch the commits** — this has no effect. Save the file and quit. You will be prompted to change the commits’ messages one by one, allowing you to remove the `[skip ci]` tag from all commits. +### Release process + +To release the libcore, a Github action automates everything: +- Go to [Release libcore](https://github.com/LedgerHQ/lib-ledger-core/actions/workflows/release.yml) action +- Select "Run workflow" +- Set the version you want to tag + +It will automatically: +- Push the tag +- Create the Release note +- Build libcore release (ubuntu 22 & macos 12) +- Publish libcore jar +- Update WD + ## Q/A and troubleshooting ### I have updated an include file and test code doesn’t see the changes! diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index a12354e654..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,4 +0,0 @@ - -build: off - -deploy: off diff --git a/core/test/coin-integration/common/CoinIntegrationFixture.hpp b/core/test/coin-integration/common/CoinIntegrationFixture.hpp index a4c6c76ed2..7c293a5607 100644 --- a/core/test/coin-integration/common/CoinIntegrationFixture.hpp +++ b/core/test/coin-integration/common/CoinIntegrationFixture.hpp @@ -98,7 +98,7 @@ class CoinIntegrationFixture : public ::testing::Test { virtual std::shared_ptr newPool(std::string poolName = "my_pool") { std::shared_ptr configuration = api::DynamicObject::newInstance(); - configuration->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + configuration->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); return WalletPool::newInstance( poolName, diff --git a/core/test/common/test_config.h b/core/test/common/test_config.h index b717924510..bbc5caad4d 100644 --- a/core/test/common/test_config.h +++ b/core/test/common/test_config.h @@ -26,6 +26,31 @@ * */ -#define POSTGRES_ON_LOCALHOST "postgres://localhost:5432" -#define POSTGRES_TEST_DB "test_db" -#define POSTGRES_TEST_DB_ON_LOCALHOST POSTGRES_ON_LOCALHOST "/" POSTGRES_TEST_DB +#include +#include + +inline std::string getPostgresUrl() { + const char *host = getenv("POSTGRES_HOST"); + const std::string host_var(host ? host : "localhost"); + + const char *port = getenv("POSTGRES_PORT"); + const std::string port_var(port ? port : "5432"); + + const char *dbname = getenv("POSTGRES_DB"); + const std::string dbname_var(dbname ? dbname : "test_db"); + + const char *user = getenv("POSTGRES_USER"); + std::string user_var(user ? user : ""); + + const char *password = getenv("POSTGRES_PASSWORD"); + const std::string password_var(password ? password : ""); + + if (!user_var.empty()) { + if (!password_var.empty()) { + user_var.append(":").append(password_var); + } + user_var.append("@"); + } + + return std::string{"postgres://"} + user_var + host_var + ":" + port_var + "/" + dbname_var; +} \ No newline at end of file diff --git a/core/test/cosmos/db_test.cpp b/core/test/cosmos/db_test.cpp index 57feb306ab..03013b72ae 100644 --- a/core/test/cosmos/db_test.cpp +++ b/core/test/cosmos/db_test.cpp @@ -21,7 +21,7 @@ class CosmosDBTest : public BaseFixture { BaseFixture::SetUp(); auto poolConfig = DynamicObject::newInstance(); - poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); pool = newDefaultPool("postgres", "", poolConfig); backend->enableQueryLogging(true); diff --git a/core/test/database/BaseFixture.cpp b/core/test/database/BaseFixture.cpp index b602b989cf..d11957a714 100644 --- a/core/test/database/BaseFixture.cpp +++ b/core/test/database/BaseFixture.cpp @@ -72,7 +72,7 @@ void BaseFixture::TearDown() { std::shared_ptr BaseFixture::newDefaultPool(std::string poolName) { std::shared_ptr configuration = api::DynamicObject::newInstance(); - configuration->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + configuration->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); return WalletPool::newInstance( poolName, diff --git a/core/test/database/pool_tests.cpp b/core/test/database/pool_tests.cpp index a2437acbac..c1b85efad4 100644 --- a/core/test/database/pool_tests.cpp +++ b/core/test/database/pool_tests.cpp @@ -68,7 +68,7 @@ TEST(DatabaseSessionPool, OpenAndMigrateForTheFirstTime) { auto resolver = std::make_shared(); auto backend = std::static_pointer_cast(DatabaseBackend::getPostgreSQLBackend(api::ConfigurationDefaults::DEFAULT_PG_CONNECTION_POOL_SIZE, api::ConfigurationDefaults::DEFAULT_PG_CONNECTION_POOL_SIZE)); - DatabaseSessionPool::getSessionPool(dispatcher->getSerialExecutionContext("worker"), backend, resolver, nullptr, POSTGRES_TEST_DB_ON_LOCALHOST) + DatabaseSessionPool::getSessionPool(dispatcher->getSerialExecutionContext("worker"), backend, resolver, nullptr, getPostgresUrl()) .onComplete(dispatcher->getMainExecutionContext(), [&](const TryPtr &result) { EXPECT_TRUE(result.isSuccess()); if (result.isFailure()) { @@ -96,7 +96,7 @@ TEST(DatabaseSessionPool, InitializeCurrencies) { auto printer = std::make_shared(dispatcher->getMainExecutionContext()); std::shared_ptr configuration = api::DynamicObject::newInstance(); - configuration->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + configuration->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); auto pool = WalletPool::newInstance( "my_pool", diff --git a/core/test/integration/BaseFixture.cpp b/core/test/integration/BaseFixture.cpp index 2467e2a65a..b19ff39909 100644 --- a/core/test/integration/BaseFixture.cpp +++ b/core/test/integration/BaseFixture.cpp @@ -232,7 +232,7 @@ std::shared_ptr BaseFixture::newDefaultPool(const std::string &poolN // compilation flags. auto actualPoolName = poolName; - configuration->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + configuration->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); if (actualPoolName == "") { actualPoolName = randomDBName(); } diff --git a/core/test/integration/WalletFixture.hpp b/core/test/integration/WalletFixture.hpp index 53a306cf06..0c64e79a64 100644 --- a/core/test/integration/WalletFixture.hpp +++ b/core/test/integration/WalletFixture.hpp @@ -48,7 +48,7 @@ class WalletFixture : public BaseFixture { BaseFixture::SetUp(); auto poolConfig = DynamicObject::newInstance(); - poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); const auto dbName = randomDBName(); pool = newDefaultPool(dbName, "", poolConfig); diff --git a/core/test/integration/synchronization/cosmos_synchronization.cpp b/core/test/integration/synchronization/cosmos_synchronization.cpp index 335e90c28f..4cb5e02f3c 100644 --- a/core/test/integration/synchronization/cosmos_synchronization.cpp +++ b/core/test/integration/synchronization/cosmos_synchronization.cpp @@ -72,7 +72,7 @@ class CosmosLikeWalletSynchronization : public BaseFixture { api::CosmosConfigurationDefaults::COSMOS_DEFAULT_API_ENDPOINT, http, worker, threadpoolWorker); auto poolConfig = DynamicObject::newInstance(); - poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); pool = newDefaultPool("postgres", "", poolConfig); explorer = std::make_shared( @@ -310,7 +310,7 @@ TEST_F(CosmosLikeWalletSynchronization, DISABLED_MediumXpubSynchronization) { auto walletName = "8d99cc44-9061-43a4-9edd-f938d2007926"; auto poolConfig = DynamicObject::newInstance(); - poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); auto pool = newDefaultPool("postgres", "", poolConfig); backend->enableQueryLogging(true); diff --git a/core/test/integration/synchronization/cosmos_synchronization_benchmarks.cpp b/core/test/integration/synchronization/cosmos_synchronization_benchmarks.cpp index 6099bcca3e..7d0f19a3dc 100644 --- a/core/test/integration/synchronization/cosmos_synchronization_benchmarks.cpp +++ b/core/test/integration/synchronization/cosmos_synchronization_benchmarks.cpp @@ -94,7 +94,7 @@ class CosmosWalletSyncBenchmark : public BaseFixture { api::CosmosConfigurationDefaults::COSMOS_DEFAULT_API_ENDPOINT, http, worker, threadpoolWorker); auto poolConfig = DynamicObject::newInstance(); - poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + poolConfig->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); pool = newDefaultPool("postgres", "", poolConfig); explorer = std::make_shared( diff --git a/core/test/integration/synchronization/synchronization_tests.cpp b/core/test/integration/synchronization/synchronization_tests.cpp index 44b5a97fcb..770f64f559 100644 --- a/core/test/integration/synchronization/synchronization_tests.cpp +++ b/core/test/integration/synchronization/synchronization_tests.cpp @@ -49,7 +49,7 @@ class BitcoinLikeWalletSynchronization : public BaseFixture { TEST_F(BitcoinLikeWalletSynchronization, MediumXpubSynchronization) { auto configuration = DynamicObject::newInstance(); - configuration->putString(api::PoolConfiguration::DATABASE_NAME, POSTGRES_TEST_DB_ON_LOCALHOST); + configuration->putString(api::PoolConfiguration::DATABASE_NAME, getPostgresUrl()); auto pool = newDefaultPool("postgres", "", configuration); const auto walletName = randomWalletName(); diff --git a/nix/scripts/export_libcore_version.sh b/nix/scripts/export_libcore_version.sh index 9551befd1e..7f630e729c 100755 --- a/nix/scripts/export_libcore_version.sh +++ b/nix/scripts/export_libcore_version.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail +set -euo function match { sed -nr $* @@ -11,29 +11,32 @@ LIB_VERSION_MINOR=`cat CMakeLists.txt | match 's/set\(VERSION_MINOR.*([0-9]+).*\ LIB_VERSION_PATCH=`cat CMakeLists.txt | match 's/set\(VERSION_PATCH.*([0-9]+).*\)/\1/p'` LIB_VERSION=$LIB_VERSION_MAJOR.$LIB_VERSION_MINOR.$LIB_VERSION_PATCH -COMMIT_HASH=`echo $GITHUB_SHA | cut -c 1-6` -LIBCORE_VERSION="$LIB_VERSION-rc-$COMMIT_HASH" -LIBCORE_GIT_DESCRIBE=`git describe --tags --first-parent` - -echo "=====> Libcore version : $LIBCORE_VERSION" -# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter -echo "::set-output name=lib_version::$LIBCORE_VERSION" - printf "# github event is **${GITHUB_EVENT_NAME}**\n" -if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then +if [[ "${RELEASE}" == "true" ]]; then printf "\nMarking for deploy\n" echo "::set-output name=deploy_dynlibs::YES" - echo "::set-output name=jar_version::${LIB_VERSION}" -elif [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then + if [[ "${VERSION:=none}" != "none" ]]; then + LIBCORE_VERSION=${VERSION} + else + LIBCORE_VERSION=${LIB_VERSION} + fi + JAR_VERSION=${LIBCORE_VERSION} +else printf "\nMarking for snapshot\n" echo "::set-output name=deploy_dynlibs::NO" - echo "::set-output name=jar_version::${LIB_VERSION}-${LIBCORE_GIT_DESCRIBE}-SNAPSHOT" -elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then - printf "\nMarking for snapshot\n" - BRANCH_NAME=$1 - BRANCH_LENGTH=`git rev-list --count ^remotes/origin/${GITHUB_BASE_REF} remotes/origin/${BRANCH_NAME}` - ABBREV_COMMIT_HASH=`git rev-list ^remotes/origin/${GITHUB_BASE_REF} remotes/origin/${BRANCH_NAME} | head -n 1 | cut -c 1-6` - echo "::set-output name=deploy_dynlibs::NO" - echo "::set-output name=jar_version::${LIB_VERSION}-${BRANCH_NAME}-${BRANCH_LENGTH}-${ABBREV_COMMIT_HASH}-SNAPSHOT" + BRANCH_NAME=${GITHUB_REF_NAME} + echo "Branch name: " $BRANCH_NAME + echo "Base ref name: "${GITHUB_BASE_REF:=main} + BRANCH_LENGTH=`git rev-list --count ^remotes/origin/${GITHUB_BASE_REF:=main} remotes/origin/${BRANCH_NAME}` + echo "Branch length: " $BRANCH_LENGTH + # syntax (git ... ||:) is to avoid SIGPIPE error: https://stackoverflow.com/a/19120674 + ABBREV_COMMIT_HASH=`(git rev-list ^remotes/origin/${GITHUB_BASE_REF:=main} remotes/origin/${BRANCH_NAME} ||:) | head -n 1 | cut -c 1-6` + echo "Commit hash: " $ABBREV_COMMIT_HASH + LIBCORE_VERSION=${LIB_VERSION}-${BRANCH_NAME}-${BRANCH_LENGTH}-${ABBREV_COMMIT_HASH} + JAR_VERSION="${LIBCORE_VERSION}-SNAPSHOT" fi +echo "::set-output name=jar_version::${JAR_VERSION}" +echo "::set-output name=lib_version::${LIBCORE_VERSION}" +echo "=====> Libcore version : $LIBCORE_VERSION" +echo "=====> JAR version : $JAR_VERSION" diff --git a/nix/scripts/sbt/build.sbt b/nix/scripts/sbt/build.sbt index 8a5414b8ec..8ea49bd0b1 100644 --- a/nix/scripts/sbt/build.sbt +++ b/nix/scripts/sbt/build.sbt @@ -8,5 +8,5 @@ scalaVersion := "2.12.8" ThisBuild / githubOwner := "LedgerHQ" ThisBuild / githubRepository := "lib-ledger-core" -ThisBuild / githubTokenSource := TokenSource.Environment("GITHUB_TOKEN") +ThisBuild / githubTokenSource := TokenSource.Environment("GITHUB_TOKEN") || TokenSource.Environment("GH_TOKEN") || TokenSource.GitConfig("github.token") ThisBuild / versionScheme := Some("strict") diff --git a/tools/publish-jar-local.sh b/tools/publish-jar-local.sh new file mode 100644 index 0000000000..e4ef079114 --- /dev/null +++ b/tools/publish-jar-local.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -euo pipefail + +IFS=. read major minor patch <<<$(java -version 2>&1 | awk -F '"' '/version/ {print $2}') +if [ $major -ne 1 ] | [ $minor -ne 8 ]; then + printf "Openjdk should match version 1.8\n\n" + printf "Tip ! you can use:\n" + printf "$ jabba use adopt@1.8.0-292\n" + exit 1 +fi + +# This script works with a directory name as first parameter +# You need to have the libcore already built in this directory with JNI enabled +# e.g.: +# cd lib_build_dir_jni +# cmake .. -DSYS_OPENSSL=ON -DOPENSSL_USE_STATIC_LIBS=TRUE -DTARGET_JNI=ON -DPG_SUPPORT=ON +# cmake --build . --parallel +# +# And then you call the script: +# ./publish-jar-local.sh ./lib_build_dir_jni +LIB_BUILD_DIR=$1 + +JAR_BUILD_DIR=/tmp/build-jar +JAVA_API_DIR=api/core/java +SCALA_API_DIR=api/core/scala +SBT_DIR=nix/scripts/sbt +RESOURCE_DIR=$JAR_BUILD_DIR/src/main/resources/resources/djinni_native_libs + +rm -rf $JAR_BUILD_DIR +mkdir -v $JAR_BUILD_DIR + +mkdir -v -p $RESOURCE_DIR + +cp $JAVA_API_DIR/* $JAR_BUILD_DIR +cp $SCALA_API_DIR/* $JAR_BUILD_DIR +cp -r $SBT_DIR/* $JAR_BUILD_DIR + +cp $LIB_BUILD_DIR/core/src/libledger-core.so $RESOURCE_DIR + +cd $JAR_BUILD_DIR +export GITHUB_TOKEN="unused" # but mandatory + +# By default it will generate a package named local-SNAPSHOT, but you can override it by giving a 2nd parameter to the script +# e.g. ./publish-jar-local.sh ./lib_build_dir_jni custom_name +# -> will generate package custom_name-SNAPSHOT +# You may find it under ~/.ivy2/local/co.ledger/ledger-lib-core_2.12/local-SNAPSHOT +export JAR_VERSION=${2-local}-SNAPSHOT + +sbt publishLocal