Skip to content

Commit

Permalink
Bazel remote caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemnmez committed Sep 21, 2023
1 parent 6537fcb commit c012f00
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 83 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/bootstrap_bazel_remote_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env bash

echo "::group::Configure Bazel Remote Cache"

if [[ -z "${BAZEL_REMOTE_CACHE_URL}" ]]; then
echo "::warning file=.github/workflows/bootstrap_bazel_remote_cache.sh,line=3,endLine=3,title=Running without bazel cache!:: BAZEL_REMOTE_CACHE_URL was not specified, so tests will be doing all the work from scratch."
else
echo "Using bazel remote cache."
echo "build --remote_cache=${BAZEL_REMOTE_CACHE_URL}" > .bazelrc
echo "test --remote_cache=${BAZEL_REMOTE_CACHE_URL}" > .bazelrc
fi

echo "::endgroup::"

exit 0
62 changes: 10 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,12 @@ jobs:
large-packages: false
- name: Checkout code
uses: actions/checkout@v3
# example copied from:
# https://github.com/actions/cache/blob/04f198bf0b2a39f7230a4304bf07747a0bddf146/examples.md
- name: Cache Bazel
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
key: >
${{ runner.os }}-bazel-${{
hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Presubmit
run: |
./.github/workflows/bootstrap_bazel_remote_cache.sh
bazel run //ci:presubmit -- --skip-pulumi-deploy
env:
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
Staging:
# Pulumi doesn't like it when multiple deploys are attempted at once.
# This is also enforced at the pulumi layer, but i'm sure github actions
Expand All @@ -134,19 +124,6 @@ jobs:
docker-images: true
large-packages: false
swap-storage: true
# example copied from:
# https://github.com/actions/cache/blob/04f198bf0b2a39f7230a4304bf07747a0bddf146/examples.md
- name: Cache Bazel
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
key: >
${{ runner.os }}-bazel-${{
hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
# in order to determine if applying this patch would succeed
# *on the mainline branch*
# we have to set the Pulumi state to be the same.
Expand All @@ -163,18 +140,21 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_SECRET }}
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
- name: Switch back to candidate branch
uses: actions/checkout@v3
- name: Deploy candidate branch to Staging
# we can run this dirty since the next run will --overwrite anyway
run: |
./.github/workflows/bootstrap_bazel_remote_cache.sh
bazel run //ci:presubmit -- \
--skip-bazel-tests \
--dangerously-skip-pnpm-lockfile-validation --dirty
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_SECRET }}
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
Submit:
concurrency: pulumi_production
if: github.event_name == 'push'
Expand All @@ -192,23 +172,11 @@ jobs:
large-packages: false
- name: Checkout code
uses: actions/checkout@v3
# example copied from:
# https://github.com/actions/cache/blob/04f198bf0b2a39f7230a4304bf07747a0bddf146/examples.md
- name: Cache Bazel
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
key: >
${{ runner.os }}-bazel-${{
hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Submit
# Use npx to try to generate only
# bazel generated node_modules
run: |
./.github/workflows/bootstrap_bazel_remote_cache.sh
bazel run //ci:submit
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -217,6 +185,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_SECRET }}
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
Postsubmit:
runs-on: ubuntu-latest
if: github.event_name == 'push'
Expand All @@ -233,21 +202,9 @@ jobs:
swap-storage: true
- name: Checkout code
uses: actions/checkout@v3
# example copied from:
# https://github.com/actions/cache/blob/04f198bf0b2a39f7230a4304bf07747a0bddf146/examples.md
- name: Cache Bazel
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
key: >
${{ runner.os }}-bazel-${{
hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Postsubmit
run: |
./.github/workflows/bootstrap_bazel_remote_cache.sh
bazel run //ci:postsubmit
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -256,3 +213,4 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_SECRET }}
BAZEL_REMOTE_CACHE_URL: ${{ secrets.BAZEL_REMOTE_CACHE_URL }}
34 changes: 33 additions & 1 deletion ci/presubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,39 @@ const cmd = new Command('presubmit')
}
});

function logError(e: unknown) {
if (!(e instanceof Error)) return console.log(e);

const stack = e.stack ?? Error.prototype.stack;

if (!stack) return console.log(e);

const runfilesRoot = process.env['TEST_SRCDIR'];

if (!runfilesRoot) return console.log(e);

const runfilesRootIndex = stack.indexOf(runfilesRoot);

if (runfilesRootIndex == -1) return console.log(e);

const suffix = stack.slice(runfilesRootIndex + runfilesRoot.length);

const res = /^([A-Za-z0-9/._]+)\.(?:ts|js):(\d+):(\d+)/.exec(suffix);

if (res === null) return console.log(e);

const [, filePrefix, line, offset] = res;

console.error(
WorkflowCommand('error')({
file: filePrefix,
line: line,
col: offset,
})('' + e)
);
}

cmd.parseAsync(process.argv).catch(e => {
process.exitCode = 2;
console.error(e);
logError(e);
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@
"dependencies": {
"@commander-js/extra-typings": "^11.0.0",
"@pulumi/command": "4.5.0",
"@pulumi/github": "^5.17.0",
"@pulumi/random": "^4.13.4",
"@react-spring/rafz": "^9.7.3",
"@types/bcryptjs": "2.4.3",
"aws-sdk": "^2.1459.0",
"csstype": "^3.1.1",
"devtools-protocol": "^0.0.1193409",
"eslint-mdx": "^2.1.0",
Expand Down
Loading

0 comments on commit c012f00

Please sign in to comment.