update action to dagger 0.2

- Remove AGE key setup
- Update README to use `dagger do`
- Update tests to dagger 0.2

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-03-09 12:07:13 -08:00
parent 64f8bd95de
commit 24d6bfd692
96 changed files with 15028 additions and 70 deletions

View file

@ -0,0 +1,12 @@
{
"name": "test",
"main": "index.js",
"license": {
"type": "Apache-2.0",
"url": "https://opensource.org/licenses/apache2.0.php"
},
"scripts": {
"build": "mkdir -p ./build && cp /.env ./build/env"
}
}

View file

@ -0,0 +1,11 @@
{
"name": "test",
"main": "index.js",
"license": {
"type": "Apache-2.0",
"url": "https://opensource.org/licenses/apache2.0.php"
},
"scripts": {
"build": "mkdir -p ./build && echo output > ./build/test && touch .env && cp .env ./build/"
}
}

View file

@ -0,0 +1,9 @@
setup() {
load '../../bats_helpers'
common_setup
}
@test "yarn" {
dagger up
}

View file

@ -0,0 +1,90 @@
package yarn
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/yarn"
)
dagger.#Plan & {
client: filesystem: {
"./data/foo": read: contents: dagger.#FS
"./data/bar": read: contents: dagger.#FS
}
actions: tests: {
// Configuration for all tests
common: {
data: client.filesystem."./data/foo".read.contents
}
// Run yarn.#Build
simple: {
build: yarn.#Build & {
source: common.data
}
verify: #AssertFile & {
input: build.output
path: "test"
contents: "output\n"
}
}
// Run yarn.#Build with a custom name
customName: {
build: yarn.#Build & {
name: "My Build"
source: common.data
}
verify: #AssertFile & {
input: build.output
path: "test"
contents: "output\n"
}
}
// Run yarn.#Build with a custom docker image
customImage: {
buildImage: docker.#Build & {
steps: [
docker.#Pull & {
source: "alpine"
},
docker.#Run & {
command: {
name: "apk"
args: ["add", "yarn", "bash"]
}
},
]
}
image: build.output
build: yarn.#Build & {
source: common.data
container: #input: buildImage.output
}
}
}
}
// Make an assertion on the contents of a file
#AssertFile: {
input: dagger.#FS
path: string
contents: string
_read: dagger.#ReadFile & {
"input": input
"path": path
}
actual: _read.contents
// Assertion
contents: actual
}

View file

@ -0,0 +1,144 @@
// Yarn is a package manager for Javascript applications
package yarn
import (
"strings"
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
"universe.dagger.io/docker"
)
#Build: #Run & {
buildDir: *"build" | string
script: *"build" | string
}
// Run a Yarn command
#Run: {
// Custom name for this command.
// Assign an app-specific name if there are multiple apps in the same plan.
name: string | *""
// App source code
source: dagger.#FS
// Working directory to use
cwd: *"." | string
// Write the contents of `environment` to this file, in the "envfile" format
writeEnvFile: string | *""
// Optional: Read build output from this directory
// Must be relative to working directory, cwd
buildDir?: string
// Yarn script to run for this command.
script: string
// Fix for shadowing issues
let yarnScript = script
// Optional arguments for the script
args: [...string] | *[]
// Secret variables
// FIXME: not implemented. Are they needed?
secrets: [string]: dagger.#Secret
container: #input: docker.#Image | *{
// FIXME: Yarn's version depends on Alpine's version
// Yarn version
// yarnVersion: *"=~1.22" | string
// FIXME: custom base image not supported
alpine.#Build & {
packages: {
bash: {}
yarn: {}
}
}
}
_run: docker.#Build & {
steps: [
container.#input,
docker.#Copy & {
dest: "/src"
contents: source
},
bash.#Run & {
// FIXME: move shell script to its own file
script: contents: #"""
yarn --cwd "$YARN_CWD" install --production false
"""#
mounts: "yarn cache": {
dest: "/cache/yarn"
contents: dagger.#CacheDir & {
// FIXME: are there character limitations in cache ID?
id: "universe.dagger.io/yarn.#Run \(name)"
}
}
env: {
YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
}
workdir: "/src"
},
bash.#Run & {
// FIXME: move shell script to its own file
script: contents: #"""
# Create $ENVFILE_NAME file if set
[ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME"
opts=( $(echo $YARN_ARGS) )
yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]}
if [ ! -z "${YARN_BUILD_DIRECTORY:-}" ]; then
mv "$YARN_BUILD_DIRECTORY" /build
else
mkdir /build
fi
"""#
mounts: "yarn cache": {
dest: "/cache/yarn"
contents: dagger.#CacheDir & {
// FIXME: are there character limitations in cache ID?
id: "universe.dagger.io/yarn.#Run \(name)"
}
}
env: {
YARN_BUILD_SCRIPT: yarnScript
YARN_ARGS: strings.Join(args, "\n")
YARN_CACHE_FOLDER: "/cache/yarn"
YARN_CWD: cwd
if buildDir != _|_ {
YARN_BUILD_DIRECTORY: buildDir
}
if writeEnvFile != "" {
ENVFILE_NAME: writeEnvFile
ENVFILE: strings.Join([ for k, v in env {"\(k)=\(v)"}], "\n")
}
}
workdir: "/src"
},
]
}
// The final contents of the package after run
_output: dagger.#Subdir & {
input: _run.output.rootfs
path: "/build"
}
output: _output.output
}