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: {
build: yarn.#Build & {
source: inputs.directories.testdata.contents source: inputs.directories.testdata.contents
"cache": cache
} }
_image: alpine.#Build & { verify: #AssertFile & {
packages: bash: {} input: build.output
path: "test"
contents: "output\n"
}
} }
test: bash.#Run & { // Run yarn.#Build with a custom name
image: _image.output customName: {
mounts: build: { build: yarn.#Build & {
dest: "/build" name: "My Build"
contents: pkg.output 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)
// }
// }
// 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"