diff --git a/.github/workflows/bazel-noenv.yaml b/.github/workflows/bazel-noenv.yaml new file mode 100644 index 0000000000..068c7c661b --- /dev/null +++ b/.github/workflows/bazel-noenv.yaml @@ -0,0 +1,27 @@ +name: bazel-noenv + +on: + push + +jobs: + bazel-build-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Get Bazel + uses: bazel-contrib/setup-bazel@0.8.1 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Store build cache per workflow. + disk-cache: ${{ github.workflow }} + # Share repository cache between workflows. + repository-cache: true + - name: Bazel Build + run: bazel build ... + - name: Bazel Test + run: bazel test ... diff --git a/.github/workflows/lintformat.yaml b/.github/workflows/lintformat.yaml new file mode 100644 index 0000000000..30efe7d5ed --- /dev/null +++ b/.github/workflows/lintformat.yaml @@ -0,0 +1,18 @@ +name: lintformat + +on: + push + +jobs: + lintformat: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Bootstrap + run: pw_env_setup/run.sh bootstrap.sh + - name: python_format + run: pw presubmit --program lintformat --full --keep-going diff --git a/docs/infra/github.rst b/docs/infra/github.rst index be588b3534..8cbb1e16b8 100644 --- a/docs/infra/github.rst +++ b/docs/infra/github.rst @@ -4,9 +4,8 @@ GitHub =========== --------- Overview --------- +======== Pigweed itself uses `LUCI `_ for :abbr:`CI/CD (Continuous Integration/Continuous Deployment)`. LUCI is @@ -18,13 +17,12 @@ for `GitHub Actions `_ as well. Bazel ===== Configuring a Bazel builder that runs on pull requests is straightforward. -There are four steps: `checkout `_, -`get Bazel `_, build, and test. There are good -community-managed actions for the first two steps, and the last two steps are -trivial (and can even be combined). +There are four steps: `checkout`_, `get Bazel`_, build, and test. There +are good community-managed actions for the first two steps, and the last two +steps are trivial (and can even be combined). -.. _github-actions-checkout: https://github.com/marketplace/actions/checkout -.. _github-actions-bazel: https://github.com/marketplace/actions/setup-bazel-environment +.. _checkout: https://github.com/marketplace/actions/checkout +.. _get Bazel: https://github.com/marketplace/actions/setup-bazel-environment The Bazel version retrieved is configured through a ``.bazelversion`` file in the root of the checkout. @@ -63,5 +61,47 @@ the root of the checkout. ``pw presubmit`` ================ -Tests that require using `pw_env_setup `_ and -`pw_presubmit `_ are not yet supported. +Configuring a builder that uses `pw_env_setup `_ and +`pw_presubmit `_ is also relatively simple. When run +locally, ``bootstrap.sh`` has several checks to ensure it's "sourced" instead of +directly executed. A `trivial wrapper script` is included in ``pw_env_setup`` +that gets around this. + +.. _trivial wrapper script: https://cs.opensource.google/pigweed/pigweed/+/main:pw_env_setup/run.sh + +When ``pw_env_setup`` is run within a GitHub Action, it recognizes this from the +environment and writes the environment variables in a way +`understood by GitHub`_, and GitHub makes those variables available to +subsequent steps. + +.. _understood by GitHub: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable + +For Pigweed itself, the only ``pw_presubmit``-based action runs lintformat. To +test all of Pigweed requires more resources than the free GitHub runners +provide, but small projects using just part of Pigweed may be more successful. + +.. code-block:: yaml + + name: lintformat + + on: + pull_request: + types: [opened, synchronize, reopened] + + jobs: + bazel-build-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Bootstrap + run: pw_env_setup/run.sh bootstrap.sh + - name: python_format + run: pw presubmit --program lintformat --keep-going + +Note that Pigweed does not accept pull requests on GitHub, so we do not define +GitHub actions that trigger from pull requests. Instead, we trigger on pushes to +GitHub. diff --git a/pw_env_setup/run.sh b/pw_env_setup/run.sh new file mode 100755 index 0000000000..ba17d5c3f2 --- /dev/null +++ b/pw_env_setup/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Copyright 2024 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +# Helper script for when 'bootstrap.sh' needs to be executed instead of +# sourced. + +. "$1"