diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f684baa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Bitrise Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e6bb0b9..41c128d 100644 --- a/README.md +++ b/README.md @@ -1 +1,44 @@ -# bitrise-step-activate-build-cache-for-bazel \ No newline at end of file +# Activate Bitrise Build Cache for Bazel + +[![Step changelog](https://shields.io/github/v/release/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel?include_prereleases&label=changelog&color=blueviolet)](https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel/releases) + +Activates Bitrise Remote Build Cache for subsequent Bazel builds in the workflows. + + +
+Description + +This Step activates Bitrise's remote build cache add-on for subsequent Bazel executions in the workflow. + +After this Step executes, Bazel builds will automatically read from the remote cache and push new entries if it's enabled. + +
+ +## 🧩 Get started + +Add this step directly to your workflow in the [Bitrise Workflow Editor](https://devcenter.bitrise.io/steps-and-workflows/steps-and-workflows-index/). + +You can also run this step directly with [Bitrise CLI](https://github.com/bitrise-io/bitrise). + +## ⚙️ Configuration + +
+Inputs +There are no inputs defined in this step +
+ +
+Outputs +There are no outputs defined in this step +
+ +## 🙋 Contributing + +We welcome [pull requests](https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel/pulls) and [issues](https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel/issues) against this repository. + +For pull requests, work on your changes in a forked repository and use the Bitrise CLI to [run step tests locally](https://devcenter.bitrise.io/bitrise-cli/run-your-first-build/). + +Learn more about developing steps: + +- [Create your own step](https://devcenter.bitrise.io/contributors/create-your-own-step/) +- [Testing your Step](https://devcenter.bitrise.io/contributors/testing-and-versioning-your-steps/) diff --git a/bitrise.yml b/bitrise.yml new file mode 100644 index 0000000..0423a70 --- /dev/null +++ b/bitrise.yml @@ -0,0 +1,20 @@ +format_version: "11" +default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git + +workflows: + check: + steps: + - git::https://github.com/bitrise-steplib/steps-check.git: + inputs: + - skip_go_checks: "yes" + - workflow: lint + + e2e: + steps: + - git::https://github.com/bitrise-steplib/steps-check.git: + inputs: + - workflow: e2e + + generate_readme: + steps: + - git::https://github.com/bitrise-steplib/steps-readme-generator.git: { } diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml new file mode 100644 index 0000000..f853e40 --- /dev/null +++ b/e2e/bitrise.yml @@ -0,0 +1,56 @@ +format_version: "11" +default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git + +workflows: + test_bazel_build: + title: livegrep sample currently supports Ubuntu 20.04 only, skipping on other stacks + steps: + - bitrise-run: + run_if: |- + {{ or (enveq "BITRISEIO_STACK_ID" "linux-docker-android-20.04") (not .IsCI) }} + is_skippable: true + inputs: + - workflow_id: utility_bazel_build + - bitrise_config_path: ./e2e/bitrise.yml + + utility_bazel_build: + envs: + - TEST_APP_URL: https://github.com/bitrise-samples/livegrep.git + - TEST_APP_BRANCH: main + before_run: + - _setup + steps: + - path::./: + title: Test Current Step + run_if: "true" + is_skippable: false + - change-workdir: + title: Switch working dir to _tmp + inputs: + - path: ./_tmp + - script: + title: Run Bazel build + deps: + brew: + - name: bazel + inputs: + - content: |- + #!/bin/env bash + if [ $(uname -s) = "Linux" ]; then + wget https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 + chmod +x bazelisk-linux-amd64 + mv bazelisk-linux-amd64 /usr/local/bin/bazel + fi + + bazel build --verbose_failures //... + _setup: + steps: + - script: + title: Delete _tmp dir + inputs: + - content: rm -rf _tmp + - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git: + inputs: + - repository_url: $TEST_APP_URL + - clone_into_dir: ./_tmp + - branch: $TEST_APP_BRANCH diff --git a/step.sh b/step.sh new file mode 100644 index 0000000..f125c02 --- /dev/null +++ b/step.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# 'read' has to be before 'set -e' +read -r -d '' UNAVAILABLE_MESSAGE << EOF_MSG +Bitrise Build Cache is not activated in this build. + +You have added the **Activate Bitrise Build Cache for Bazel** Step to your Workflow. + +However, you don't have an active Bitrise Build Cache Trial or Subscription for the current Workspace yet. + +You can activate a Trial at [app.bitrise.io/build-cache](https://app.bitrise.io/build-cache), +or contact us at [support@bitrise.io](mailto:support@bitrise.io) to activate it. +EOF_MSG + +set -eo pipefail + +echo "Checking whether Bitrise Build Cache is activated for the current Workspace..." +if [ "$BITRISEIO_BUILD_CACHE_ENABLED" != "true" ]; then + printf "\n%s\n" "$UNAVAILABLE_MESSAGE" + set -x + bitrise plugin install https://github.com/bitrise-io/bitrise-plugins-annotations.git + bitrise :annotations annotate "$UNAVAILABLE_MESSAGE" --style error || { + echo "Failed to create annotation" + exit 3 + } + exit 2 +fi +echo "Bitrise Build Cache is activated in this workspace, configuring the build environment ..." + +set -x + +# download the Bitrise Build Cache CLI +export BITRISE_BUILD_CACHE_CLI_VERSION="v0.9.0" +curl --retry 5 -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b /tmp/bin -d $BITRISE_BUILD_CACHE_CLI_VERSION + +# run the Bitrise Build Cache CLI +/tmp/bin/bitrise-build-cache enable-for bazel + diff --git a/step.yml b/step.yml new file mode 100644 index 0000000..9cddd52 --- /dev/null +++ b/step.yml @@ -0,0 +1,24 @@ +title: |- + Activate Bitrise Build Cache for Bazel +summary: | + Activates Bitrise Remote Build Cache for subsequent Bazel builds in the workflows. +description: | + This Step activates Bitrise's remote build cache add-on for subsequent Bazel executions in the workflow. + + After this Step executes, Bazel builds will automatically read from the remote cache and push new entries if it's enabled. + +website: https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel +source_code_url: https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel +support_url: https://github.com/bitrise-steplib/bitrise-step-activate-build-cache-for-bazel/issues + +type_tags: +- utility + +run_if: .IsCI +is_skippable: true + +toolkit: + bash: + entry_file: step.sh + +inputs: []