Skip to content

Commit

Permalink
github: Add basic workflow and docs
Browse files Browse the repository at this point in the history
Bug: b/340900493
Change-Id: I4ef402c655e8a0ad32104b88885fef8f13d07dd2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/212952
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
  • Loading branch information
mohrr authored and CQ Bot Account committed Jun 3, 2024
1 parent ff81e38 commit 778137c
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/bazel-noenv.yaml
Original file line number Diff line number Diff line change
@@ -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 ...
18 changes: 18 additions & 0 deletions .github/workflows/lintformat.yaml
Original file line number Diff line number Diff line change
@@ -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
60 changes: 50 additions & 10 deletions docs/infra/github.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
GitHub
===========

--------
Overview
--------
========

Pigweed itself uses `LUCI <luci>`_ for
:abbr:`CI/CD (Continuous Integration/Continuous Deployment)`. LUCI is
Expand All @@ -18,13 +17,12 @@ for `GitHub Actions <github-actions>`_ as well.
Bazel
=====
Configuring a Bazel builder that runs on pull requests is straightforward.
There are four steps: `checkout <github-actions-checkout>`_,
`get Bazel <github-actions-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.
Expand Down Expand Up @@ -63,5 +61,47 @@ the root of the checkout.
``pw presubmit``
================
Tests that require using `pw_env_setup <module-pw_env_setup>`_ and
`pw_presubmit <module-pw_presubmit>`_ are not yet supported.
Configuring a builder that uses `pw_env_setup <module-pw_env_setup>`_ and
`pw_presubmit <module-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.
19 changes: 19 additions & 0 deletions pw_env_setup/run.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 778137c

Please sign in to comment.