Skip to content

build

build #19678

Workflow file for this run

name: build
on:
pull_request:
types: [opened, synchronize]
merge_group:
types: [checks_requested]
push:
# Always run on push to main. The build cache can only be reused
# if it was saved by a run from the repository's default branch.
# The run result will be identical to that from the merge queue
# because the commit is identical, yet we need to perform it to
# seed the build cache.
branches:
- main
schedule:
- cron: '0 0,12 * * *' # Runs at 00:00 and 12:00 UTC daily
env:
GOTESTSUM_FORMAT: github-actions
jobs:
cleanups:
runs-on:
group: databricks-deco-testing-runner-group
labels: ubuntu-latest-deco
steps:
- name: Clean up cache if running on schedule
if: ${{ github.event_name == 'schedule' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh cache delete --all --repo databricks/cli || true
tests:
needs: cleanups
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- group: databricks-protected-runner-group-large
labels: linux-ubuntu-latest-large
- ${{ github.event_name != 'merge_group' && 'windows-latest' || null }}
deployment:
- "terraform"
- "direct"
exclude:
- os: null
steps:
- name: Checkout repository and submodules
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Create deployment-specific cache identifier
run: echo "${{ matrix.deployment }}" > deployment-type.txt
- name: Setup Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: go.mod
cache-dependency-path: |
go.sum
deployment-type.txt
- name: Setup Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: '3.13'
- name: Install uv
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
with:
version: "0.8.9"
- name: Install ruff (Python linter and formatter)
uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
with:
version: "0.9.1"
args: "--version"
- name: Pull external libraries
run: |
go mod download
pip3 install wheel==0.45.1
- name: Run tests without coverage
# We run tests without coverage on PR, merge_group, and schedule because we don't make use of coverage information
# and would like to run the tests as fast as possible. We run it on schedule as well, because that is what
# populates the cache and cache may include test results.
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'schedule' }}
env:
ENVFILTER: DATABRICKS_BUNDLE_ENGINE=${{ matrix.deployment }}
run: make test
- name: Run tests with coverage
# Only run 'make cover' on push to main to make sure it does not get broken.
if: ${{ github.event_name == 'push' }}
env:
ENVFILTER: DATABRICKS_BUNDLE_ENGINE=${{ matrix.deployment }}
run: make cover
- name: Analyze slow tests
run: make slowest
linters:
needs: cleanups
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: go.mod
# Use different schema from regular job, to avoid overwriting the same key
cache-dependency-path: |
go.sum
.golangci.yaml
- name: Run go mod tidy
run: |
go mod tidy
- name: Fail on differences
run: |
# Exit with status code 1 if there are differences (i.e. unformatted files)
git diff --exit-code
- name: Run Go lint checks (does not include formatting checks)
run: go tool -modfile=tools/go.mod golangci-lint run --timeout=15m
- name: Run ruff (Python linter and formatter)
uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
with:
version: "0.9.1"
args: "format --check"
- name: "make fmtfull: Python and Go formatting"
# This is already done by actions, but good to check that make command is working
run: |
make fmtfull
git diff --exit-code
- name: "make checks: custom checks outside of fmt and lint"
run: |
make checks
git diff --exit-code
validate-generated-is-up-to-date:
needs: cleanups
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: go.mod
# Use different schema from regular job, to avoid overwriting the same key
cache-dependency-path: |
go.sum
bundle/internal/schema/*.*
- name: Verify that the schema is up to date
run: |
if ! ( make schema && git diff --exit-code ); then
echo "The schema is not up to date. Please run 'make schema' and commit the changes."
exit 1
fi
- name: Verify that the generated enum and required fields are up to date
run: |
if ! ( make generate-validation && git diff --exit-code ); then
echo "The generated enum and required fields are not up to date. Please run 'make generate-validation' and commit the changes."
exit 1
fi
# Github repo: https://github.com/ajv-validator/ajv-cli
- name: Install ajv-cli
run: npm install -g [email protected]
# Assert that the generated bundle schema is a valid JSON schema by using
# ajv-cli to validate it against bundle configuration files.
# By default the ajv-cli runs in strict mode which will fail if the schema
# itself is not valid. Strict mode is more strict than the JSON schema
# specification. See for details: https://ajv.js.org/options.html#strict-mode-options
# The ajv-cli is configured to use the markdownDescription keyword which is not part of the JSON schema specification,
# but is used in editors like VSCode to render markdown in the description field
- name: Validate bundle schema
run: |
go run main.go bundle schema > schema.json
# Add markdownDescription keyword to ajv
echo "module.exports = function(a) {
a.addKeyword('deprecationMessage');
a.addKeyword('doNotSuggest');
a.addKeyword('markdownDescription');
a.addKeyword('x-databricks-preview');
}" >> keywords.js
for file in ./bundle/internal/schema/testdata/pass/*.yml; do
ajv test -s schema.json -d $file --valid -c=./keywords.js
done
for file in ./bundle/internal/schema/testdata/fail/*.yml; do
ajv test -s schema.json -d $file --invalid -c=./keywords.js
done
validate-python-codegen:
needs: cleanups
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install uv
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
with:
version: "0.6.5"
- name: Verify that python/codegen is up to date
working-directory: python
run: |-
make codegen
if ! ( git diff --exit-code ); then
echo "Generated Python code is not up-to-date. Please run 'pushd python && make codegen' and commit the changes."
exit 1
fi