ci: install nix together with Bazel

This commit is contained in:
Malte Poll 2023-10-04 13:55:38 +02:00 committed by Malte Poll
parent e74dbda64e
commit e80e6076b4
11 changed files with 89 additions and 25 deletions

View File

@ -16,7 +16,7 @@ runs:
using: "composite" using: "composite"
steps: steps:
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "true" useCache: "true"
buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }} buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }}

View File

@ -30,7 +30,7 @@ runs:
terraform_wrapper: false terraform_wrapper: false
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "true" useCache: "true"
buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }} buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }}

View File

@ -120,7 +120,7 @@ runs:
echo "hostArch=$(go env GOARCH)" | tee -a "$GITHUB_OUTPUT" echo "hostArch=$(go env GOARCH)" | tee -a "$GITHUB_OUTPUT"
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: ${{ inputs.buildBuddyApiKey != '' }} useCache: ${{ inputs.buildBuddyApiKey != '' }}
buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }} buildBuddyApiKey: ${{ inputs.buildBuddyApiKey }}

View File

@ -1,5 +1,5 @@
name: Setup bazel name: Setup bazel and Nix
description: Setup Bazel for CI builds and tests description: Setup Bazel and Nix for CI builds and tests
inputs: inputs:
useCache: useCache:
@ -14,6 +14,7 @@ runs:
using: "composite" using: "composite"
steps: steps:
- name: Check inputs - name: Check inputs
id: check_inputs
shell: bash shell: bash
run: | run: |
echo "::group::Check inputs" echo "::group::Check inputs"
@ -25,6 +26,60 @@ runs:
echo "BuildBuddy API key is required when cache is enabled." echo "BuildBuddy API key is required when cache is enabled."
exit 1 exit 1
fi fi
if command -v nix; then
echo "nixPreinstalled=true" | tee -a "$GITHUB_OUTPUT"
else
echo "nixPreinstalled=false" | tee -a "$GITHUB_OUTPUT"
fi
if command -v bazel; then
echo "bazelPreinstalled=true" | tee -a "$GITHUB_OUTPUT"
else
echo "bazelPreinstalled=false" | tee -a "$GITHUB_OUTPUT"
fi
if [[ -f /etc/NIXOS ]]; then
echo "nixOS=true" | tee -a "$GITHUB_OUTPUT"
else
echo "nixOS=false" | tee -a "$GITHUB_OUTPUT"
fi
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo "os=linux" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_OS" == "Windows" ]]; then
echo "os=windows" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_OS" == "macOS" ]]; then
echo "os=darwin" | tee -a "$GITHUB_OUTPUT"
else
echo "$RUNNER_OS not supported"
exit 1
fi
if [[ "$RUNNER_ARCH" == "X64" ]]; then
echo "arch=amd64" | tee -a "$GITHUB_OUTPUT"
elif [[ "$RUNNER_ARCH" == "ARM64" ]]; then
echo "arch=arm64" | tee -a "$GITHUB_OUTPUT"
else
echo "$RUNNER_ARCH not supported"
exit 1
fi
echo "::endgroup::"
- name: Install nix
if: steps.check_inputs.outputs.nixPreinstalled == 'false'
uses: cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac # v22
# - uses: cachix/cachix-action@6a9a34cdd93d0ae4b4b59fd678660efb08109f2f # v12
# with:
# name: katexochen
# extraPullNames: nix-community
- name: Install Bazelisk
if: steps.check_inputs.outputs.bazelPreinstalled == 'false' && steps.check_inputs.outputs.nixOS == 'false'
shell: bash
env:
OS: ${{ steps.check_inputs.outputs.os }}
ARCH: ${{ steps.check_inputs.outputs.arch }}
run: |
echo "::group::Install Bazelisk"
curl -fsSLo /usr/local/bin/bazel "https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/bazelisk-${OS}-${ARCH}"
chmod +x /usr/local/bin/bazel
echo "::endgroup::" echo "::endgroup::"
- name: Free up space (Ubuntu) - name: Free up space (Ubuntu)
@ -65,8 +120,8 @@ runs:
echo "::endgroup::" echo "::endgroup::"
- name: Configure Bazel (rw) - name: Configure Bazel (rw)
shell: bash
if: inputs.useCache == 'true' || inputs.useCache == 'readonly' if: inputs.useCache == 'true' || inputs.useCache == 'readonly'
shell: bash
env: env:
BUILDBUDDY_ORG_API_KEY: ${{ inputs.buildBuddyApiKey }} BUILDBUDDY_ORG_API_KEY: ${{ inputs.buildBuddyApiKey }}
WORKSPACE: ${{ github.workspace }} WORKSPACE: ${{ github.workspace }}
@ -87,8 +142,8 @@ runs:
echo "::endgroup::" echo "::endgroup::"
- name: Configure Bazel (readonly) - name: Configure Bazel (readonly)
shell: bash
if: inputs.useCache == 'readonly' if: inputs.useCache == 'readonly'
shell: bash
env: env:
WORKSPACE: ${{ github.workspace }} WORKSPACE: ${{ github.workspace }}
run: | run: |
@ -97,8 +152,8 @@ runs:
echo "::endgroup::" echo "::endgroup::"
- name: Configure Bazel (logs) - name: Configure Bazel (logs)
shell: bash
if: inputs.useCache == 'logs' if: inputs.useCache == 'logs'
shell: bash
env: env:
BUILDBUDDY_ORG_API_KEY: ${{ inputs.buildBuddyApiKey }} BUILDBUDDY_ORG_API_KEY: ${{ inputs.buildBuddyApiKey }}
WORKSPACE: ${{ github.workspace }} WORKSPACE: ${{ github.workspace }}
@ -116,16 +171,12 @@ runs:
echo "::endgroup::" echo "::endgroup::"
- name: Disable disk cache on GitHub Actions runners - name: Disable disk cache on GitHub Actions runners
if: startsWith(runner.name , 'GitHub Actions')
shell: bash shell: bash
env: env:
WORKSPACE: ${{ github.workspace }} WORKSPACE: ${{ github.workspace }}
if: startsWith(runner.name , 'GitHub Actions')
run: | run: |
echo "::group::Configure Bazel (disk cache)" echo "::group::Configure Bazel (disk cache)"
echo "common --disk_cache=" >> "${WORKSPACE}/.bazeloverwriterc" echo "common --disk_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
echo "common --repository_cache=" >> "${WORKSPACE}/.bazeloverwriterc" echo "common --repository_cache=" >> "${WORKSPACE}/.bazeloverwriterc"
echo "::endgroup::" echo "::endgroup::"
- name: Check bazel version
shell: bash
run: bazel version

View File

@ -27,7 +27,7 @@ jobs:
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }} ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "true" useCache: "true"
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}

View File

@ -157,12 +157,9 @@ jobs:
with: with:
ref: ${{ inputs.ref || github.head_ref }} ref: ${{ inputs.ref || github.head_ref }}
- uses: cachix/install-nix-action@6ed004b9ccb68dbc28e7c85bee15fa93dbd214ac # v22 - uses: ./.github/actions/setup_bazel_nix
- uses: cachix/cachix-action@6a9a34cdd93d0ae4b4b59fd678660efb08109f2f # v12
with: with:
name: katexochen useCache: "false"
extraPullNames: nix-community
- name: Build - name: Build
id: build id: build
@ -231,6 +228,10 @@ jobs:
with: with:
ref: ${{ inputs.ref || github.head_ref }} ref: ${{ inputs.ref || github.head_ref }}
- uses: ./.github/actions/setup_bazel_nix
with:
useCache: "false"
- name: Download OS image artifact - name: Download OS image artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with: with:
@ -385,6 +386,10 @@ jobs:
with: with:
name: image-${{ matrix.csp }}-${{ matrix.attestation_variant }} name: image-${{ matrix.csp }}-${{ matrix.attestation_variant }}
- uses: ./.github/actions/setup_bazel_nix
with:
useCache: "false"
- name: Install dependencies - name: Install dependencies
run: | run: |
echo "::group::Install dependencies" echo "::group::Install dependencies"
@ -620,6 +625,10 @@ jobs:
with: with:
ref: ${{ inputs.ref || github.head_ref }} ref: ${{ inputs.ref || github.head_ref }}
- uses: ./.github/actions/setup_bazel_nix
with:
useCache: "false"
- name: Download image lookup table - name: Download image lookup table
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
with: with:

View File

@ -134,6 +134,10 @@ jobs:
fetch-depth: 0 fetch-depth: 0
ref: ${{ inputs.gitRef }} ref: ${{ inputs.gitRef }}
- uses: ./.github/actions/setup_bazel_nix
with:
useCache: "false"
- name: Login to AWS - name: Login to AWS
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
with: with:

View File

@ -77,7 +77,7 @@ jobs:
ref: ${{ inputs.ref || github.head_ref }} ref: ${{ inputs.ref || github.head_ref }}
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "false" useCache: "false"
@ -125,7 +125,7 @@ jobs:
ref: ${{ inputs.ref || github.head_ref }} ref: ${{ inputs.ref || github.head_ref }}
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "false" useCache: "false"
@ -209,7 +209,7 @@ jobs:
uses: ./.github/actions/install_syft_grype uses: ./.github/actions/install_syft_grype
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "false" useCache: "false"

View File

@ -29,7 +29,7 @@ jobs:
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }} ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "logs" useCache: "logs"
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}

View File

@ -30,7 +30,7 @@ jobs:
echo "::endgroup::" echo "::endgroup::"
- name: Setup Bazel - name: Setup Bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "true" useCache: "true"
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}

View File

@ -49,7 +49,7 @@ jobs:
aws-region: eu-central-1 aws-region: eu-central-1
- name: Setup bazel - name: Setup bazel
uses: ./.github/actions/setup_bazel uses: ./.github/actions/setup_bazel_nix
with: with:
useCache: "true" useCache: "true"
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }} buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}