Skip to content

Commit

Permalink
internal/ci: run pytest and mypy in CI
Browse files Browse the repository at this point in the history
Run the tests and the type-checker in CI.

Signed-off-by: Aram Hăvărneanu <[email protected]>
Change-Id: Id95c7ef3d3abd3ed3e9a22c8b9da82f8caea10fa
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue-py/+/1195427
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
4ad committed Jun 3, 2024
1 parent e5cbfc2 commit d1f4519
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 18 deletions.
73 changes: 72 additions & 1 deletion .github/workflows/trybot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ name: TryBot
workflow_dispatch: {}
jobs:
test:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
go-version:
- 1.22.x
python-version:
- "3.12"
runner:
- macos-14
runs-on: ${{ matrix.runner }}
defaults:
run:
shell: bash
Expand Down Expand Up @@ -110,3 +119,65 @@ jobs:
working-directory: ./internal/ci
- name: Check that git is clean at the end of the job
run: test -z "$(git status --porcelain)" || (git status; git diff; false)
- name: Install Go
uses: actions/setup-go@v5
with:
cache: false
go-version: ${{ matrix.go-version }}
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- id: go-mod-cache-dir
name: Get go mod cache directory
run: echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}
- id: go-cache-dir
name: Get go build/test cache directory
run: echo "dir=$(go env GOCACHE)" >> ${GITHUB_OUTPUT}
- if: |-
(((github.ref == 'refs/heads/main') && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test'))
uses: actions/cache@v4
with:
path: |-
${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download
${{ steps.go-cache-dir.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.go-version }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ matrix.go-version }}
- if: |-
! (((github.ref == 'refs/heads/main') && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test'))
uses: actions/cache/restore@v4
with:
path: |-
${{ steps.go-mod-cache-dir.outputs.dir }}/cache/download
${{ steps.go-cache-dir.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.go-version }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ matrix.go-version }}
- if: |-
github.repository == 'cue-lang/cue-py' && (((github.ref == 'refs/heads/main') && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || github.ref == 'refs/heads/ci/test')
run: go clean -testcache
- name: pip install
run: pip install -r requirements.txt
- name: Checkout libcue
uses: actions/checkout@v4
with:
repository: cue-lang/libcue
path: libcue-checkout
- name: Build libcue
run: |-
go build -o libcue.so -buildmode=c-shared
cp libcue.so libcue.dylib
cp libcue.so cue.dll
working-directory: libcue-checkout
- name: mypy
run: mypy .
- name: pytest
run: pytest
env:
LD_LIBRARY_PATH: ${{ github.workspace }}/libcue-checkout
DYLD_LIBRARY_PATH: ${{ github.workspace }}/libcue-checkout
- name: Check that git is clean at the end of the job
run: test -z "$(git status --porcelain)" || (git status; git diff; false)
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# CI might build libcue locally, in which case we want it ignored.
libcue-checkout/

# C extensions
*.a
*.so
Expand Down
110 changes: 94 additions & 16 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ workflows: trybot: _repo.bashWorkflow & {

jobs: {
test: {
"runs-on": _repo.linuxMachine
strategy: _testStrategy
"runs-on": "${{ matrix.runner }}"

let _setupGoActionsCaches = _repo.setupGoActionsCaches & {
#goVersion: goVersionVal
#os: runnerOSVal
_
}

// Only run the trybot workflow if we have the trybot trailer, or
// if we have no special trailers. Note this condition applies
Expand All @@ -60,28 +67,99 @@ workflows: trybot: _repo.bashWorkflow & {
},

_repo.checkGitClean,

_installGo,
_installPython,

// cachePre must come after installing Go,
// because the cache locations
// are established by running each tool.
for v in _setupGoActionsCaches {v},

_runPip,

_checkoutLibcue,
_buildLibcue,

_mypy,
_pytest,

_repo.checkGitClean,
]
}
}

_#goGenerate: json.#step & {
name: "Generate"
run: "go generate ./..."
let runnerOS = "runner.os"
let runnerOSVal = "${{ \(runnerOS) }}"
let goVersion = "matrix.go-version"
let goVersionVal = "${{ \(goVersion) }}"
let pythonVersion = "matrix.python-version"
let pythonVersionVal = "${{ \(pythonVersion) }}"

_testStrategy: {
"fail-fast": false
matrix: {
"go-version": [_repo.latestStableGo]
"python-version": [_repo.latestStablePython]

// TODO: Windows requires more configuration,
// see issue #3016 for Java.
//
// TODO: Linux doesn't work yet
// see issue #3190 for Linux.
runner: [_repo.macosMachine]
}
}

_installGo: _repo.installGo & {
with: "go-version": goVersionVal
}

_installPython: json.#step & {
name: "Install Python"
uses: "actions/setup-python@v5"
with: {
"python-version": pythonVersionVal
cache: "pip"
}
}

_runPip: json.#step & {
name: "pip install"
run: "pip install -r requirements.txt"
}

_checkoutLibcue: json.#step & {
name: "Checkout libcue"
uses: "actions/checkout@v4"
with: {
repository: "cue-lang/libcue"
path: "libcue-checkout"
}
}

_buildLibcue: json.#step & {
name: "Build libcue"
"working-directory": "libcue-checkout"
// The name of the shared library is target-dependent.
// Build libcue with all possible names so we're covered
// in all cases.
run: """
go build -o libcue.so -buildmode=c-shared
cp libcue.so libcue.dylib
cp libcue.so cue.dll
"""
}

_#goTest: json.#step & {
name: "Test"
run: "go test ./..."
_mypy: json.#step & {
name: "mypy"
run: "mypy ."
}

_#goCheck: json.#step & {
// These checks can vary between platforms, as different code can be built
// based on GOOS and GOARCH build tags.
// However, CUE does not have any such build tags yet, and we don't use
// dependencies that vary wildly between platforms.
// For now, to save CI resources, just run the checks on one matrix job.
// TODO: consider adding more checks as per https://github.com/golang/go/issues/42119.
name: "Check"
run: "go vet ./..."
_pytest: json.#step & {
name: "pytest"
env: LD_LIBRARY_PATH: "${{ github.workspace }}/libcue-checkout"
env: DYLD_LIBRARY_PATH: "${{ github.workspace }}/libcue-checkout"
run: "pytest"
}
}
8 changes: 7 additions & 1 deletion internal/ci/repo/repo.cue
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ botGitHubUserEmail: "[email protected]"
defaultBranch: "main"

linuxMachine: "ubuntu-22.04"
linuxMachine: "ubuntu-22.04"
macosMachine: "macos-14"
windowsMachine: "windows-2022"

latestGo: "1.22.x"
// libcue requires Go 1.22+, so we can't test on any earlier version.
latestStableGo: "1.22.x"

latestStablePython: "3.12"

0 comments on commit d1f4519

Please sign in to comment.