mirror of
https://github.com/dagger/dagger-for-github.git
synced 2026-01-04 05:49:58 +11:00
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:
parent
64f8bd95de
commit
24d6bfd692
96 changed files with 15028 additions and 70 deletions
61
test/cue.mod/pkg/universe.dagger.io/netlify/deploy.sh
vendored
Executable file
61
test/cue.mod/pkg/universe.dagger.io/netlify/deploy.sh
vendored
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
NETLIFY_AUTH_TOKEN="$(cat /run/secrets/token)"
|
||||
export NETLIFY_AUTH_TOKEN
|
||||
|
||||
create_site() {
|
||||
url="https://api.netlify.com/api/v1/${NETLIFY_ACCOUNT:-}/sites"
|
||||
|
||||
curl -s -S --fail-with-body -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
||||
-X POST -H "Content-Type: application/json" \
|
||||
"$url" \
|
||||
-d "{\"name\": \"${NETLIFY_SITE_NAME}\", \"custom_domain\": \"${NETLIFY_DOMAIN}\"}" -o body
|
||||
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ]; then
|
||||
cat body >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
jq -r '.site_id' body
|
||||
}
|
||||
|
||||
site_id=$(curl -s -S -f -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
|
||||
"https://api.netlify.com/api/v1/sites?filter=all" | \
|
||||
jq -r ".[] | select(.name==\"$NETLIFY_SITE_NAME\") | .id" \
|
||||
)
|
||||
if [ -z "$site_id" ] ; then
|
||||
if [ "${NETLIFY_SITE_CREATE:-}" != 1 ]; then
|
||||
echo "Site $NETLIFY_SITE_NAME does not exist"
|
||||
exit 1
|
||||
fi
|
||||
site_id=$(create_site)
|
||||
if [ -z "$site_id" ]; then
|
||||
echo "create site failed"
|
||||
exit 1
|
||||
else
|
||||
echo "clean create site API response..."
|
||||
rm -f body
|
||||
fi
|
||||
fi
|
||||
|
||||
netlify link --id "$site_id"
|
||||
netlify build
|
||||
|
||||
netlify deploy \
|
||||
--dir="$(pwd)" \
|
||||
--site="$site_id" \
|
||||
--prod \
|
||||
| tee /tmp/stdout
|
||||
|
||||
url="$(</tmp/stdout grep Website | grep -Eo 'https://[^ >]+' | head -1)"
|
||||
deployUrl="$(</tmp/stdout grep Unique | grep -Eo 'https://[^ >]+' | head -1)"
|
||||
logsUrl="$(</tmp/stdout grep Logs | grep -Eo 'https://[^ >]+' | head -1)"
|
||||
|
||||
# Write output files
|
||||
mkdir -p /netlify
|
||||
echo -n "$url" > /netlify/url
|
||||
echo -n "$deployUrl" > /netlify/deployUrl
|
||||
echo -n "$logsUrl" > /netlify/logsUrl
|
||||
109
test/cue.mod/pkg/universe.dagger.io/netlify/netlify.cue
vendored
Executable file
109
test/cue.mod/pkg/universe.dagger.io/netlify/netlify.cue
vendored
Executable file
|
|
@ -0,0 +1,109 @@
|
|||
// Deploy to Netlify
|
||||
// https://netlify.com
|
||||
package netlify
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
|
||||
"universe.dagger.io/alpine"
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/bash"
|
||||
)
|
||||
|
||||
// Deploy a site to Netlify
|
||||
#Deploy: {
|
||||
// Contents of the site
|
||||
contents: dagger.#FS
|
||||
|
||||
// Name of the Netlify site
|
||||
// Example: "my-super-site"
|
||||
site: string
|
||||
|
||||
// Netlify API token
|
||||
token: dagger.#Secret
|
||||
|
||||
// Name of the Netlify team (optional)
|
||||
// Example: "acme-inc"
|
||||
// Default: use the Netlify account's default team
|
||||
team: string | *""
|
||||
|
||||
// Domain at which the site should be available (optional)
|
||||
// If not set, Netlify will allocate one under netlify.app.
|
||||
// Example: "www.mysupersite.tld"
|
||||
domain: string | *null
|
||||
|
||||
// Create the site if it doesn't exist
|
||||
create: *true | false
|
||||
|
||||
// Build a docker image to run the netlify client
|
||||
_build: docker.#Build & {
|
||||
steps: [
|
||||
alpine.#Build & {
|
||||
packages: {
|
||||
bash: {}
|
||||
curl: {}
|
||||
jq: {}
|
||||
yarn: {}
|
||||
}
|
||||
},
|
||||
// FIXME: make this an alpine custom package, that would be so cool.
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "yarn"
|
||||
args: ["global", "add", "netlify-cli@8.6.21"]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// Run the netlify client in a container
|
||||
container: bash.#Run & {
|
||||
input: *_build.output | docker.#Image
|
||||
script: {
|
||||
_load: dagger.#Source & {
|
||||
path: "."
|
||||
include: ["*.sh"]
|
||||
}
|
||||
directory: _load.output
|
||||
filename: "deploy.sh"
|
||||
}
|
||||
|
||||
always: true
|
||||
env: {
|
||||
NETLIFY_SITE_NAME: site
|
||||
if (create) {
|
||||
NETLIFY_SITE_CREATE: "1"
|
||||
}
|
||||
if domain != null {
|
||||
NETLIFY_DOMAIN: domain
|
||||
}
|
||||
NETLIFY_ACCOUNT: team
|
||||
}
|
||||
workdir: "/src"
|
||||
mounts: {
|
||||
"Site contents": {
|
||||
dest: "/src"
|
||||
"contents": contents
|
||||
}
|
||||
"Netlify token": {
|
||||
dest: "/run/secrets/token"
|
||||
contents: token
|
||||
}
|
||||
}
|
||||
|
||||
export: files: {
|
||||
"/netlify/url": _
|
||||
"/netlify/deployUrl": _
|
||||
"/netlify/logsUrl": _
|
||||
}
|
||||
}
|
||||
|
||||
// URL of the deployed site
|
||||
url: container.export.files."/netlify/url"
|
||||
|
||||
// URL of the latest deployment
|
||||
deployUrl: container.export.files."/netlify/deployUrl"
|
||||
|
||||
// URL for logs of the latest deployment
|
||||
logsUrl: container.export.files."/netlify/logsUrl"
|
||||
}
|
||||
9
test/cue.mod/pkg/universe.dagger.io/netlify/test/test.bats
vendored
Executable file
9
test/cue.mod/pkg/universe.dagger.io/netlify/test/test.bats
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
setup() {
|
||||
load '../../bats_helpers'
|
||||
|
||||
common_setup
|
||||
}
|
||||
|
||||
@test "netlify" {
|
||||
dagger up
|
||||
}
|
||||
100
test/cue.mod/pkg/universe.dagger.io/netlify/test/test.cue
vendored
Executable file
100
test/cue.mod/pkg/universe.dagger.io/netlify/test/test.cue
vendored
Executable file
|
|
@ -0,0 +1,100 @@
|
|||
package netlify
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/netlify"
|
||||
|
||||
"universe.dagger.io/netlify/test/testutils"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: commands: sops: {
|
||||
name: "sops"
|
||||
args: ["-d", "../../test_secrets.yaml"]
|
||||
stdout: dagger.#Secret
|
||||
}
|
||||
|
||||
actions: tests: {
|
||||
|
||||
// Configuration common to all tests
|
||||
common: {
|
||||
testSecrets: dagger.#DecodeSecret & {
|
||||
input: client.commands.sops.stdout
|
||||
format: "yaml"
|
||||
}
|
||||
|
||||
token: testSecrets.output.netlifyToken.contents
|
||||
|
||||
marker: "hello world"
|
||||
|
||||
data: dagger.#WriteFile & {
|
||||
input: dagger.#Scratch
|
||||
path: "index.html"
|
||||
contents: marker
|
||||
}
|
||||
}
|
||||
|
||||
// Test: deploy a simple site to Netlify
|
||||
simple: {
|
||||
// Deploy to netlify
|
||||
deploy: netlify.#Deploy & {
|
||||
team: "blocklayer"
|
||||
token: common.token
|
||||
site: "dagger-test"
|
||||
contents: common.data.output
|
||||
}
|
||||
|
||||
verify: testutils.#AssertURL & {
|
||||
url: deploy.deployUrl
|
||||
contents: common.marker
|
||||
}
|
||||
}
|
||||
|
||||
// Test: deploy to Netlify with a custom image
|
||||
swapImage: {
|
||||
// Deploy to netlify
|
||||
deploy: netlify.#Deploy & {
|
||||
team: "blocklayer"
|
||||
token: common.token
|
||||
site: "dagger-test"
|
||||
contents: common.data.output
|
||||
container: input: customImage.output
|
||||
}
|
||||
|
||||
customImage: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: "alpine"
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "apk"
|
||||
args: [
|
||||
"add",
|
||||
"--no-cache",
|
||||
"yarn",
|
||||
"bash",
|
||||
"rsync",
|
||||
"curl",
|
||||
"jq",
|
||||
]
|
||||
}
|
||||
},
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "yarn"
|
||||
args: ["global", "add", "netlify-cli"]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: testutils.#AssertURL & {
|
||||
url: deploy.deployUrl
|
||||
contents: common.marker
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
test/cue.mod/pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
vendored
Executable file
26
test/cue.mod/pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
vendored
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
package testutils
|
||||
|
||||
import (
|
||||
"universe.dagger.io/bash"
|
||||
"universe.dagger.io/alpine"
|
||||
)
|
||||
|
||||
// Assert the text contents available at a URL
|
||||
#AssertURL: {
|
||||
url: string
|
||||
contents: string
|
||||
|
||||
run: bash.#Run & {
|
||||
input: image.output
|
||||
script: "contents": """
|
||||
test "$(curl \(url))" = "\(contents)"
|
||||
"""
|
||||
}
|
||||
|
||||
image: alpine.#Build & {
|
||||
packages: {
|
||||
bash: {}
|
||||
curl: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue