-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
# General build options | ||
build --cxxopt='-std=c++17' | ||
build --host_cxxopt='-std=c++17' | ||
test --cxxopt='-std=c++17' | ||
test --host_cxxopt='-std=c++17' | ||
run --cxxopt='-std=c++17' | ||
run --host_cxxopt='-std=c++17' | ||
|
||
# To allow loops with int and comparison against a .size() that's size_t. | ||
build --copt='-Wno-error=sign-compare' | ||
build --host_copt='-Wno-error=sign-compare' | ||
test --copt='-Wno-error=sign-compare' | ||
test --host_copt='-Wno-error=sign-compare' | ||
run --copt='-Wno-error=sign-compare' | ||
run --host_copt='-Wno-error=sign-compare' | ||
|
||
# General test options | ||
test --test_output=errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,60 +2,52 @@ name: "build" | |
|
||
on: | ||
push: | ||
branches: [ master ] | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
# Run hourly, at minute 0. This is when the cache key changes, and | ||
# so this will ensure the new cache entry is generated on the master branch, | ||
# making CI fast on all branches. | ||
# https://crontab.guru/#0_*_*_*_* | ||
- cron: "0 * * * *" | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
bazelcmd: [build, test] | ||
name: ${{ matrix.bazelcmd }} | ||
name: Bazel Build and Test | ||
# We use Ubuntu 20.04 as it comes with GCC v9.3 by default. | ||
runs-on: ubuntu-20.04 | ||
env: | ||
BAZEL: bazelisk-linux-amd64 | ||
SWSS: https://x-token-auth:${{ secrets.PINS_GITHUB_BOT_PERSONAL_ACCESS_TOKEN }}@github.com/pins/sonic-swss-common.git | ||
BAZEL_CACHE_USER: github | ||
BAZEL_CACHE_PWD: ${{ secrets.BAZEL_CACHE_PWD }} | ||
BAZEL_CACHE_URL: pins-bazel-cache.onf.dev:9090 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Compute hour of the day. | ||
id: hour | ||
run: echo "::set-output name=number::$(date +%H)" | ||
|
||
- name: Mount bazel cache | ||
uses: actions/cache@v2 | ||
with: | ||
# See https://docs.bazel.build/versions/master/output_directories.html | ||
path: "~/.cache/bazel" | ||
path: "/tmp/repo-cache" | ||
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows | ||
key: ${{ matrix.bazelcmd }}-${{ runner.os }}-${{ hashFiles('**/*_deps.bzl', '.bazelrc') }}-${{ steps.hour.outputs.number }} | ||
key: bazel-repo-cache-v1-${{ runner.os }}-${{ hashFiles('**/*_deps.bzl', '.bazelrc', '.bazelversion') }} | ||
restore-keys: | | ||
${{ matrix.bazelcmd }}-${{ runner.os }}-${{ hashFiles('**/*_deps.bzl', '.bazelrc') }} | ||
${{ matrix.bazelcmd }}-${{ runner.os }}- | ||
bazel-repo-cache-v1-${{ runner.os }}- | ||
- name: Install system dependencies | ||
run: ./install_dependencies.sh | ||
|
||
- name: Install bazelisk | ||
run: | | ||
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/$BAZEL" | ||
chmod +x $BAZEL | ||
- name: Set up GitHub credentials for private repos | ||
run: git config --global url."${SWSS}".InsteadOf "[email protected]:pins/sonic-swss-common.git" | ||
|
||
- name: Build | ||
run: ./$BAZEL ${{ matrix.bazelcmd }} //... --test_output=errors --distinct_host_configuration=false | ||
|
||
- name: Compress cache | ||
# This deletes cached archives while keeping the build cache. | ||
run: rm -rf $(./$BAZEL info repository_cache) | ||
ARCH=$(dpkg --print-architecture) | ||
sudo curl -fsSL -o /usr/local/bin/bazel \ | ||
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH} | ||
sudo chmod +x /usr/local/bin/bazel | ||
# Authentication is enabled for R/W access for builds on main and branch PRs | ||
# Unauthenticated reads are allowed for PRs from forks | ||
- name: Build and Test | ||
run: | | ||
mkdir -p /tmp/repo-cache | ||
BAZEL_OPTS="--repository_cache=/tmp/repo-cache" | ||
[ ! -z "$BAZEL_CACHE_USER" ] && [ ! -z "$BAZEL_CACHE_PWD" ] && \ | ||
AUTH="${BAZEL_CACHE_USER}:${BAZEL_CACHE_PWD}@" | ||
BAZEL_OPTS+=" --remote_cache=https://${AUTH}${BAZEL_CACHE_URL}" | ||
BAZEL_OPTS+=" --remote_download_minimal" | ||
bazel build ${BAZEL_OPTS} //... | ||
bazel test ${BAZEL_OPTS} //... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# Copyright 2021 Google LLC | ||
# | ||
# 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 | ||
# | ||
# http://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. | ||
|
||
# Please read carefully before adding new dependencies: | ||
# | ||
# System dependencies are disallowed by default, and the bar for exceptions is | ||
# high. | ||
# | ||
# pins-infra strives for a hermetic build, i.e. one that is insensitive to the | ||
# libraries and other software installed on your machine, other than Bazel and | ||
# the compilers. This ensure the build is reproducible and portable. | ||
# | ||
# Before adding a new system dependency, consider the following: | ||
# | ||
# 1. Please read the note on dependencies in pins_infra_deps.bzl. | ||
# | ||
# 2. Can the dependency be avoided altogether? Consider that there is a | ||
# non-trival cost to maintaining dependencies over time. | ||
# | ||
# 3. Can the dependency be built with Bazel instead? | ||
# - For many libraries, there are existing Bazel BUILD files. Try a quick | ||
# Google search. | ||
# - If there is no existing BUILD file, can you write your own BUILD file? | ||
# See the bazel/ folder for examples. Ideally, we strive to upstream such | ||
# BUILD files so everyone can benefit and share the maintenance burden. | ||
# - If it's too hard to write a native BUILD file, try writing a BUILD file | ||
# using rules_foreign_cc (https://github.com/bazelbuild/rules_foreign_cc). | ||
#. See the bazel/ folder for examples. | ||
|
||
# TODO: Avoid system dependencies like libnl, currently these are | ||
# coming because Sonic swss common depends on them. | ||
sudo apt-get update | ||
sudo apt-get install bison flex libfl-dev libgmp-dev libhiredis-dev libnl-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-nf-3-dev libboost-dev |