diff --git a/.github/workflows/.ci_cd.yml b/.github/workflows/.ci_cd.yml deleted file mode 100644 index 949b22042..000000000 --- a/.github/workflows/.ci_cd.yml +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2022, Backblaze Inc. All Rights Reserved. -# License https://www.backblaze.com/using_b2_code.html - -name: b2-sdk-java ci/cd - -on: - push: - pull_request: - branches: - - master - -env: - PYTHON_DEFAULT_VERSION: 3.8 - OUTPUT_DIR: $GITHUB_WORKSPACE/build/outputs - OUTPUT_ZIP: b2-sdk-build-${GITHUB_RUN_NUMBER}.zip - BUILD_NUMBER: ${{ github.run_number }} - # This token was generated under rhryckewicz account - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # These are stored in Bitwarden - B2_ACCOUNT_ID: ${{ secrets.B2_ACCOUNT_ID }} - B2_UPLOAD_BUCKET: ${{ secrets.B2_UPLOAD_BUCKET }} - B2_APPLICATION_KEY: ${{ secrets.B2_APPLICATION_KEY }} - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Use jdk8 - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: '8' - cache: 'gradle' - - - uses: gradle/wrapper-validation-action@v1 - - name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }} - uses: actions/setup-python@v2 - with: - python-version: ${{ env.PYTHON_DEFAULT_VERSION }} - - - name: Install dependencies - run: | - mkdir -p ~/.gradle && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties - # upgrade pip and setuptools so that b2 CLI can be properly installed - python -m pip install --upgrade pip setuptools - python -m pip install b2 - - - name: Build the distribution - run: | - $GITHUB_WORKSPACE/gradlew build - # - # Prepare the outputs - # - - # make the directory - mkdir -p ${{ env.OUTPUT_DIR }} - cp -v */build/libs/b2-sdk-*.{jar,pom,module} ${{ env.OUTPUT_DIR }} - - # zip up the outputs - cd ${{ env.OUTPUT_DIR }} - zip -r $GITHUB_WORKSPACE/build/${{ env.OUTPUT_ZIP }} * - - - name: Deploy to internal Maven repo - if: github.ref == 'refs/heads/master' && github.repository == 'Backblaze/b2-sdk-java-private' - run: $GITHUB_WORKSPACE/gradlew publishMavenPublicationToBzGithubPackagesRepository - env: - ORG_GRADLE_PROJECT_bzGithubPackagesUsername: ${{ secrets.PACKAGES_USERNAME }} - ORG_GRADLE_PROJECT_bzGithubPackagesPassword: ${{ secrets.PACKAGES_TOKEN }} - - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -fr ~/.gradle/caches/*/plugin-resolution/ - - - name: Upload to b2 - if: github.ref == 'refs/heads/master' - # upload to b2 (if credentials are provided, as they will be for backblaze's builds, but not pull requests) - # This should be using python 3.4 - run: $GITHUB_WORKSPACE/maybe_upload_build_results ${{ env.OUTPUT_ZIP }} - - - name: Check GitHub Pages status - if: github.ref == 'refs/heads/master' - uses: crazy-max/ghaction-github-status@v2 - with: - pages_threshold: major_outage - - - name: Deploy - # note that i'm only uploading the javadocs for b2-sdk-core. - # that's because i'm lame and building separate javadocs for - # each jar and only uploading one set of javadocs. - if: github.ref == 'refs/heads/master' && success() - uses: crazy-max/ghaction-github-pages@v2 - with: - target_branch: gh-pages - build_dir: core/build/docs/javadoc - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 000000000..710c03bc8 --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,104 @@ +# Copyright 2022, Backblaze Inc. All Rights Reserved. +# License https://www.backblaze.com/using_b2_code.html + +name: b2-sdk-java ci/cd + +on: + push: + pull_request: + branches: + - master + - api-v2 + - 7.x # TODO: This is temporary and will be removed once we merge this branch to master branch + +env: + OUTPUT_DIR: $GITHUB_WORKSPACE/build/outputs + OUTPUT_ZIP: b2-sdk-build-${GITHUB_RUN_NUMBER}.zip + BUILD_NUMBER: ${{ github.run_number }} + # These are stored in Bitwarden + B2_ACCOUNT_ID: ${{ secrets.B2_ACCOUNT_ID }} + B2_UPLOAD_BUCKET: ${{ secrets.B2_UPLOAD_BUCKET }} + B2_APPLICATION_KEY: ${{ secrets.B2_APPLICATION_KEY }} + +jobs: + build: + runs-on: ${{ github.repository == 'Backblaze/b2-sdk-java-private' && 'self-hosted'|| 'ubuntu-latest' }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - uses: gradle/actions/wrapper-validation@v4 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Set up Python + run: | + python3.8 -m venv env + source env/bin/activate + echo "VIRTUAL ENV:" $VIRTUAL_ENV + # upgrade pip and setuptools so that b2 CLI can be properly installed + pip install --upgrade pip setuptools + pip install b2 pysqlite3 + + - name: Build the distribution + run: | + $GITHUB_WORKSPACE/gradlew build + # + # Prepare the outputs + # + + # make the directory + mkdir -p ${{ env.OUTPUT_DIR }} + cp -v */build/libs/b2-sdk-*.{jar,pom,module} ${{ env.OUTPUT_DIR }} + + # zip up the outputs + cd ${{ env.OUTPUT_DIR }} + zip -r $GITHUB_WORKSPACE/build/${{ env.OUTPUT_ZIP }} * + + - name: Deploy to internal Maven repo + if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/api-v2' || github.ref == 'refs/heads/7.x') && github.repository == 'Backblaze/b2-sdk-java-private' + run: $GITHUB_WORKSPACE/gradlew publishMavenPublicationToRemoteRepository + env: + ORG_GRADLE_PROJECT_remoteUsername: ${{ secrets.ARTIFACTORY_USERNAME }} + ORG_GRADLE_PROJECT_remotePassword: ${{ secrets.ARTIFACTORY_TOKEN }} + ORG_GRADLE_PROJECT_publishingUrl: "${{ secrets.JF }}/maven-private/" + + - name: Deploy to GH packages + if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/api-v2' || github.ref == 'refs/heads/7.x') && github.repository == 'Backblaze/b2-sdk-java-private' + run: $GITHUB_WORKSPACE/gradlew publishMavenPublicationToRemoteRepository + env: + ORG_GRADLE_PROJECT_remoteUsername: ${{ secrets.PACKAGES_USERNAME }} + ORG_GRADLE_PROJECT_remotePassword: ${{ secrets.PACKAGES_TOKEN }} + ORG_GRADLE_PROJECT_publishingUrl: "https://maven.pkg.github.com/Backblaze/repo" + + - name: Upload to b2 + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/api-v2' || github.ref == 'refs/heads/7.x' + # upload to b2 (if credentials are provided, as they will be for backblaze's builds, but not pull requests) + # This should be using python 3.8 + run: | + source $GITHUB_WORKSPACE/env/bin/activate + $GITHUB_WORKSPACE/maybe_upload_build_results ${{ env.OUTPUT_ZIP }} + + - name: Check GitHub Pages status + if: github.ref == 'refs/heads/master' + uses: crazy-max/ghaction-github-status@v4 + with: + pages_threshold: major_outage + + - name: Deploy Javadoc + # note that i'm only uploading the javadocs for b2-sdk-core. + # that's because i'm lame and building separate javadocs for + # each jar and only uploading one set of javadocs. + if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/api-v2' || github.ref == 'refs/heads/7.x') && success() + uses: crazy-max/ghaction-github-pages@v3 + with: + target_branch: gh-pages + build_dir: core/build/docs/javadoc + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 947e4d73e..49d6dfcea 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,18 +12,19 @@ jobs: if: github.repository == 'Backblaze/b2-sdk-java' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Use jdk8 - uses: actions/setup-java@v2 + - uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: '8' - cache: 'gradle' + distribution: 'temurin' + java-version: '11' + + - uses: gradle/actions/wrapper-validation@v4 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - - uses: gradle/wrapper-validation-action@v1 - name: Deploy to Maven Central run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository createBundle --no-daemon --stacktrace env: @@ -33,21 +34,15 @@ jobs: ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -fr ~/.gradle/caches/*/plugin-resolution/ - - name: Get tag name id: get_tag shell: bash run: | tag_name="$(echo $GITHUB_REF | cut -d / -f 3)" echo ::set-output name=tag::$tag_name + - name: Create GitHub Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/buildSrc/src/main/kotlin/b2sdk.gradle.kts b/buildSrc/src/main/kotlin/b2sdk.gradle.kts index a53ab6284..d791bb93f 100644 --- a/buildSrc/src/main/kotlin/b2sdk.gradle.kts +++ b/buildSrc/src/main/kotlin/b2sdk.gradle.kts @@ -90,10 +90,10 @@ publishing { groupId = project.group.toString() artifactId = project.name - if (System.getenv("RELEASE_BUILD") != null) { - version = project.version.toString() + version = if (System.getenv("RELEASE_BUILD") != null) { + project.version.toString() } else { - version = when (val buildNum = System.getenv("BUILD_NUMBER")) { + when (val buildNum = System.getenv("BUILD_NUMBER")) { null -> project.version.toString() else -> "${project.version}+$buildNum" } @@ -134,8 +134,13 @@ publishing { } repositories { - maven("https://maven.pkg.github.com/Backblaze/repo") { - name = "bzGithubPackages" + var publishingUrl = findProperty("publishingUrl") + if (publishingUrl == null) { + publishingUrl = "https://maven.pkg.github.com/Backblaze/repo" + } + + maven(publishingUrl.toString()) { + name = "remote" credentials(PasswordCredentials::class) } } @@ -144,8 +149,8 @@ publishing { val sonatypeUsername = findProperty("sonatypeUsername") val sonatypePassword = findProperty("sonatypePassword") -val gpgSigningKey = System.getenv("GPG_SIGNING_KEY") -val gpgPassphrase = System.getenv("GPG_PASSPHRASE") +val gpgSigningKey: String? = System.getenv("GPG_SIGNING_KEY") +val gpgPassphrase: String? = System.getenv("GPG_PASSPHRASE") if (sonatypeUsername != null && sonatypePassword != null) { signing { diff --git a/core/src/main/java/com/backblaze/b2/client/structures/B2Capabilities.java b/core/src/main/java/com/backblaze/b2/client/structures/B2Capabilities.java index ce3575c78..c25a9507c 100644 --- a/core/src/main/java/com/backblaze/b2/client/structures/B2Capabilities.java +++ b/core/src/main/java/com/backblaze/b2/client/structures/B2Capabilities.java @@ -37,6 +37,9 @@ public interface B2Capabilities { String READ_BUCKET_ENCRYPTION = "readBucketEncryption"; String WRITE_BUCKET_ENCRYPTION = "writeBucketEncryption"; + + String READ_BUCKET_LOGGING = "readBucketLogging"; + String WRITE_BUCKET_LOGGING = "writeBucketLogging"; String BYPASS_GOVERNANCE = "bypassGovernance"; String READ_BUCKET_RETENTIONS = "readBucketRetentions"; diff --git a/core/src/test/java/com/backblaze/b2/client/structures/B2ApplicationKeyTest.java b/core/src/test/java/com/backblaze/b2/client/structures/B2ApplicationKeyTest.java index a074b81a9..6b15fc7dd 100644 --- a/core/src/test/java/com/backblaze/b2/client/structures/B2ApplicationKeyTest.java +++ b/core/src/test/java/com/backblaze/b2/client/structures/B2ApplicationKeyTest.java @@ -28,6 +28,8 @@ public void testEquals() { capabilities.add(B2Capabilities.WRITE_BUCKET_RETENTIONS); capabilities.add(B2Capabilities.READ_FILE_RETENTIONS); capabilities.add(B2Capabilities.WRITE_FILE_RETENTIONS); + capabilities.add(B2Capabilities.READ_BUCKET_LOGGING); + capabilities.add(B2Capabilities.WRITE_BUCKET_LOGGING); capabilities.add(B2Capabilities.READ_FILE_LEGAL_HOLDS); capabilities.add(B2Capabilities.WRITE_FILE_LEGAL_HOLDS); capabilities.add(B2Capabilities.READ_BUCKET_REPLICATIONS); diff --git a/httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java b/httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java index 141305121..adae523c0 100644 --- a/httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java +++ b/httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/HttpClientFactoryImpl.java @@ -76,6 +76,10 @@ public CloseableHttpClient create() throws B2Exception { .setUserAgent(APACHE_HTTP_CLIENT_USER_AGENT) .setConnectionManager(connectionManager) .setDefaultRequestConfig(requestConfig) + // Allow connections to be idle for up to 4 seconds before not reusing. This strategy is needed + // because we are seeing connections being closed by the server after 4 seconds, then when we attempt + // to use, the call fails. + .setKeepAliveStrategy((httpResponse, httpContext) -> 4000) .build(); }