Merge pull request #1576 from shykes/yarn-cache-optional

yarn.#Build: simpler API, better tests
This commit is contained in:
Solomon Hykes 2022-02-08 15:27:06 -08:00 committed by GitHub
commit f7f2b2549f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 57 deletions

View File

@ -2,9 +2,9 @@ package yarn
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/yarn"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
)
dagger.#Plan & {
@ -13,60 +13,48 @@ dagger.#Plan & {
testdata2: path: "./testdata2"
}
actions: {
cache: dagger.#CacheDir & {
id: "yarn cache"
}
actions: tests: {
pkg: yarn.#Build & {
simple: {
build: yarn.#Build & {
source: inputs.directories.testdata.contents
"cache": cache
}
_image: alpine.#Build & {
packages: bash: {}
verify: #AssertFile & {
input: build.output
path: "test"
contents: "output\n"
}
}
test: bash.#Run & {
image: _image.output
mounts: build: {
dest: "/build"
contents: pkg.output
// Run yarn.#Build with a custom name
customName: {
build: yarn.#Build & {
name: "My Build"
source: inputs.directories.testdata.contents
}
verify: #AssertFile & {
input: build.output
path: "test"
contents: "output\n"
}
}
}
script: contents: #"""
test "$(cat /build/test)" = "output"
"""#
}
// FIXME: re-enable?
// TestSecretsAndFile: {
// pkg: #Package & {
// source: inputs.directories.testdata2
// writeEnvFile: "/.env"
// env: {
// one: "one"
// two: "two"
// }
// secrets: {
// secretone: dagger.#Secret @dagger(input)
// secretwo: dagger.#Secret @dagger(input)
// }
// }
// Make an assertion on the contents of a file
#AssertFile: {
input: dagger.#FS
path: string
contents: string
// test: os.#Container & {
// image: alpine.#Image & {
// package: bash: true
// }
// shell: path: "/bin/bash"
// mount: "/build": from: pkg.build
// command: """
// content="$(cat /build/env)"
// [[ "${content}" = *"SECRETONE="* ]] && \\
// [[ "${content}" = *"SECRETWO="* ]] && \\
// [[ "${content}" = *"ONE=one"* ]] && \\
// [[ "${content}" = *"TWO=two"* ]]
// """
// }
// }
_read: engine.#ReadFile & {
"input": input
"path": path
}
actual: _read.contents
// Assertion
contents: actual
}

View File

@ -13,6 +13,11 @@ import (
// Build a Yarn package
#Build: {
// Custom name for the build.
// When building different apps in the same plan, assign
// different names for optimal caching.
name: string | *""
// Application source code
source: dagger.#FS
@ -33,9 +38,6 @@ import (
// Fix for shadowing issues
let yarnScript = script
// Cache to use, passed by the caller
cache: engine.#CacheDir
// Optional arguments for the script
args: [...string] | *[]
@ -74,7 +76,10 @@ import (
mounts: {
"yarn cache": {
dest: "/cache/yarn"
contents: cache
contents: engine.#CacheDir & {
// FIXME: are there character limitations in cache ID?
id: "universe.dagger.io/yarn.#Build \(name)"
}
}
"package source": {
dest: "/src"