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 ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/yarn" "universe.dagger.io/yarn"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
) )
dagger.#Plan & { dagger.#Plan & {
@ -13,60 +13,48 @@ dagger.#Plan & {
testdata2: path: "./testdata2" testdata2: path: "./testdata2"
} }
actions: { actions: tests: {
cache: dagger.#CacheDir & {
id: "yarn cache"
}
pkg: yarn.#Build & { simple: {
source: inputs.directories.testdata.contents build: yarn.#Build & {
"cache": cache source: inputs.directories.testdata.contents
} }
_image: alpine.#Build & { verify: #AssertFile & {
packages: bash: {} input: build.output
} path: "test"
contents: "output\n"
test: bash.#Run & {
image: _image.output
mounts: build: {
dest: "/build"
contents: pkg.output
} }
script: contents: #"""
test "$(cat /build/test)" = "output"
"""#
} }
// FIXME: re-enable? // Run yarn.#Build with a custom name
// TestSecretsAndFile: { customName: {
// pkg: #Package & { build: yarn.#Build & {
// source: inputs.directories.testdata2 name: "My Build"
// writeEnvFile: "/.env" source: inputs.directories.testdata.contents
// env: { }
// one: "one" verify: #AssertFile & {
// two: "two" input: build.output
// } path: "test"
// secrets: { contents: "output\n"
// secretone: dagger.#Secret @dagger(input) }
// secretwo: dagger.#Secret @dagger(input) }
// }
// }
// 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"* ]]
// """
// }
// }
} }
} }
// Make an assertion on the contents of a file
#AssertFile: {
input: dagger.#FS
path: string
contents: string
_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 a Yarn package
#Build: { #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 // Application source code
source: dagger.#FS source: dagger.#FS
@ -33,9 +38,6 @@ import (
// Fix for shadowing issues // Fix for shadowing issues
let yarnScript = script let yarnScript = script
// Cache to use, passed by the caller
cache: engine.#CacheDir
// Optional arguments for the script // Optional arguments for the script
args: [...string] | *[] args: [...string] | *[]
@ -74,7 +76,10 @@ import (
mounts: { mounts: {
"yarn cache": { "yarn cache": {
dest: "/cache/yarn" 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": { "package source": {
dest: "/src" dest: "/src"