cue modules: move stdlib to pkg/alpha.dagger.io
In preparation for Europa, we will vendor multiple CUE modules: - `pkg/alpha.dagger.io`: legacy non-europa packages - `pkg/dagger.io`: core Europa packages - `pkg/universe.dagger.io`: Europa universe Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
89
pkg/alpha.dagger.io/git/commit.cue
Normal file
89
pkg/alpha.dagger.io/git/commit.cue
Normal file
@@ -0,0 +1,89 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
// Commit & push to git repository
|
||||
#Commit: {
|
||||
// Git repository
|
||||
repository: {
|
||||
// Repository source code
|
||||
source: dagger.#Artifact
|
||||
|
||||
// Repository remote URL
|
||||
remote: dagger.#Input & {string}
|
||||
|
||||
// Authentication token (PAT or password)
|
||||
authToken: dagger.#Input & {*null | dagger.#Secret}
|
||||
|
||||
// Git branch
|
||||
branch: dagger.#Input & {string}
|
||||
}
|
||||
|
||||
// Username
|
||||
name: dagger.#Input & {string}
|
||||
|
||||
// Email
|
||||
email: dagger.#Input & {string}
|
||||
|
||||
// Commit message
|
||||
message: dagger.#Input & {string}
|
||||
|
||||
// Content to commit
|
||||
content: dagger.#Artifact
|
||||
|
||||
// Force push options
|
||||
force: dagger.#Input & {*false | bool}
|
||||
|
||||
_ctr: os.#Container & {
|
||||
image: #Image
|
||||
command: #"""
|
||||
# Move changes into repository
|
||||
mv /input/content/* .
|
||||
|
||||
# Commit changes
|
||||
git add .
|
||||
git -c user.name="$USER_NAME" -c user.email="$USER_EMAIL" commit -m "$COMMIT_MESSAGE"
|
||||
|
||||
# Push
|
||||
git push "$OPT_FORCE" -u "$GIT_REMOTE" HEAD:refs/heads/"$GIT_BRANCH"
|
||||
|
||||
# Retrieve commit hash
|
||||
git rev-parse --verify HEAD | tr -d '\n' > /commit.txt
|
||||
"""#
|
||||
dir: "/input/repo"
|
||||
mount: {
|
||||
"/input/repo": from: repository.source
|
||||
"/input/content": from: content
|
||||
}
|
||||
env: {
|
||||
USER_NAME: name
|
||||
USER_EMAIL: email
|
||||
COMMIT_MESSAGE: message
|
||||
GIT_BRANCH: repository.branch
|
||||
GIT_REMOTE: repository.remote
|
||||
if force {
|
||||
OPT_FORCE: "-f"
|
||||
}
|
||||
|
||||
}
|
||||
if repository.authToken != null {
|
||||
env: GIT_ASKPASS: "/get_authToken"
|
||||
files: "/get_authToken": {
|
||||
content: "cat /secrets/authToken"
|
||||
mode: 0o500
|
||||
}
|
||||
secret: "/secrets/authToken": repository.authToken
|
||||
}
|
||||
}
|
||||
|
||||
// Commit hash
|
||||
hash: {
|
||||
os.#File & {
|
||||
from: _ctr
|
||||
path: "/commit.txt"
|
||||
}
|
||||
}.contents & dagger.#Output
|
||||
}
|
163
pkg/alpha.dagger.io/git/git.cue
Normal file
163
pkg/alpha.dagger.io/git/git.cue
Normal file
@@ -0,0 +1,163 @@
|
||||
// Git operations
|
||||
package git
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/alpine"
|
||||
)
|
||||
|
||||
// A git repository
|
||||
#Repository: {
|
||||
// Git remote link
|
||||
remote: dagger.#Input & {string}
|
||||
|
||||
// Git ref: can be a commit, tag or branch.
|
||||
// Example: "main"
|
||||
ref: dagger.#Input & {string}
|
||||
|
||||
// (optional) Subdirectory
|
||||
subdir: dagger.#Input & {*null | string}
|
||||
|
||||
// (optional) Keep .git directory
|
||||
keepGitDir: *false | bool
|
||||
|
||||
// (optional) Add Personal Access Token
|
||||
authToken: dagger.#Input & {*null | dagger.#Secret}
|
||||
|
||||
// (optional) Add OAuth Token
|
||||
authHeader: dagger.#Input & {*null | dagger.#Secret}
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: git: true
|
||||
}
|
||||
},
|
||||
op.#Copy & {
|
||||
from: [
|
||||
op.#FetchGit & {
|
||||
"remote": remote
|
||||
"ref": ref
|
||||
if (keepGitDir) {
|
||||
keepGitDir: true
|
||||
}
|
||||
if (authToken != null) {
|
||||
"authToken": authToken
|
||||
}
|
||||
if (authHeader != null) {
|
||||
"authHeader": authHeader
|
||||
}
|
||||
},
|
||||
]
|
||||
dest: "/repository"
|
||||
},
|
||||
op.#Exec & {
|
||||
dir: "/repository"
|
||||
args: [
|
||||
"/bin/sh",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
code=$(git rev-parse --is-inside-work-tree 2>&1)
|
||||
([ "$code" = "true" ] && git remote set-url origin "$REMOTE") || true
|
||||
"""#,
|
||||
]
|
||||
env: REMOTE: remote
|
||||
},
|
||||
op.#Subdir & {
|
||||
dir: "/repository"
|
||||
},
|
||||
if subdir != null {
|
||||
op.#Subdir & {
|
||||
dir: subdir
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// Get the name of the current checked out branch or tag
|
||||
#CurrentBranch: {
|
||||
// Git repository
|
||||
repository: dagger.#Artifact @dagger(input)
|
||||
|
||||
// Git branch name
|
||||
name: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
mount: "/repository": from: repository
|
||||
dir: "/repository"
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
printf "$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" > /name.txt
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/name.txt"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
} @dagger(output)
|
||||
}
|
||||
|
||||
// List tags of a repository
|
||||
#Tags: {
|
||||
// Git repository
|
||||
repository: dagger.#Artifact @dagger(input)
|
||||
|
||||
// Repository tags
|
||||
tags: {
|
||||
[...string]
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: jq: true
|
||||
package: git: true
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
mount: "/repository": from: repository
|
||||
dir: "/repository"
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
git tag -l | jq --raw-input --slurp 'split("\n") | map(select(. != ""))' > /tags.json
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/tags.json"
|
||||
format: "json"
|
||||
},
|
||||
]
|
||||
} @dagger(output)
|
||||
}
|
9
pkg/alpha.dagger.io/git/image.cue
Normal file
9
pkg/alpha.dagger.io/git/image.cue
Normal file
@@ -0,0 +1,9 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/alpine"
|
||||
)
|
||||
|
||||
#Image: alpine.#Image & {
|
||||
package: git: true
|
||||
}
|
79
pkg/alpha.dagger.io/git/tests/commit/commit.cue
Normal file
79
pkg/alpha.dagger.io/git/tests/commit/commit.cue
Normal file
@@ -0,0 +1,79 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
"alpha.dagger.io/random"
|
||||
)
|
||||
|
||||
TestAuthToken: dagger.#Input & {dagger.#Secret}
|
||||
|
||||
TestRemote: dagger.#Input & {*"https://github.com/dagger/test.git" | string}
|
||||
|
||||
TestRepository: #Repository & {
|
||||
remote: TestRemote
|
||||
ref: "main"
|
||||
keepGitDir: true
|
||||
authToken: TestAuthToken
|
||||
}
|
||||
|
||||
TestData: {
|
||||
random.#String & {
|
||||
seed: "git-commit"
|
||||
}
|
||||
}.out
|
||||
|
||||
TestFile: os.#Dir & {
|
||||
from: os.#Container & {
|
||||
image: alpine.#Image
|
||||
command: #"""
|
||||
mkdir -p /output
|
||||
echo "$MESSAGE" >> /output/test.md
|
||||
"""#
|
||||
env: MESSAGE: TestData
|
||||
}
|
||||
path: "/output"
|
||||
}
|
||||
|
||||
TestCommit: #Commit & {
|
||||
repository: {
|
||||
remote: TestRemote
|
||||
authToken: TestAuthToken
|
||||
source: TestRepository
|
||||
branch: "ci/test-commit"
|
||||
}
|
||||
content: TestFile
|
||||
message: "This is a commit from the CI to test the repository"
|
||||
name: "Dagger CI"
|
||||
email: "daggerci@dagger.io"
|
||||
force: true
|
||||
}
|
||||
|
||||
TestCheck: {
|
||||
_TestRepo: #Repository & {
|
||||
remote: TestRemote
|
||||
ref: "ci/test-commit"
|
||||
keepGitDir: true
|
||||
authToken: TestAuthToken
|
||||
}
|
||||
|
||||
_ctr: os.#Container & {
|
||||
image: #Image
|
||||
command: #"""
|
||||
# Check commit
|
||||
git rev-parse --verify HEAD | grep "$GIT_HASH"
|
||||
|
||||
# Check file
|
||||
echo -n "$EXPECTED_MESSAGE" >> expect.md
|
||||
diff test.md expect.md
|
||||
"""#
|
||||
dir: "/input/repo"
|
||||
mount: "/input/repo": from: _TestRepo
|
||||
env: {
|
||||
EXPECTED_MESSAGE: TestData
|
||||
// Force dependency with interpolation
|
||||
GIT_HASH: "\(TestCommit.hash)"
|
||||
}
|
||||
}
|
||||
}
|
111
pkg/alpha.dagger.io/git/tests/git/git.cue
Normal file
111
pkg/alpha.dagger.io/git/tests/git/git.cue
Normal file
@@ -0,0 +1,111 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
repo: #Repository & {
|
||||
remote: "https://github.com/blocklayerhq/acme-clothing.git"
|
||||
ref: "master"
|
||||
keepGitDir: true
|
||||
}
|
||||
|
||||
repoSubDir: #Repository & {
|
||||
remote: "https://github.com/dagger/examples.git"
|
||||
ref: "main"
|
||||
subdir: "todoapp"
|
||||
keepGitDir: true
|
||||
}
|
||||
|
||||
branch: #CurrentBranch & {
|
||||
repository: repo
|
||||
}
|
||||
|
||||
tagsList: #Tags & {
|
||||
repository: repo
|
||||
}
|
||||
|
||||
TestRepository: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
mount: "/repo1": from: repo
|
||||
dir: "/repo1"
|
||||
command: """
|
||||
[ -d .git ]
|
||||
"""
|
||||
}
|
||||
|
||||
TestSubRepository: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
mount: "/repo1": from: repoSubDir
|
||||
dir: "/repo1"
|
||||
command: """
|
||||
[ -d src ]
|
||||
"""
|
||||
}
|
||||
|
||||
TestCurrentBranch: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
env: BRANCH_NAME: branch.name
|
||||
command: """
|
||||
[ $BRANCH_NAME = "master" ]
|
||||
"""
|
||||
}
|
||||
|
||||
TestCurrentTags: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
env: TAGS: strings.Join([ for k, v in tagsList.tags {"\(k)=\(v)"}], "\n")
|
||||
command: """
|
||||
[ $TAGS = "0=master" ]
|
||||
"""
|
||||
}
|
||||
|
||||
// Test fetching a private repo
|
||||
TestPAT: dagger.#Input & {dagger.#Secret}
|
||||
|
||||
privateRepo: #Repository & {
|
||||
remote: "https://github.com/dagger/dagger.git"
|
||||
ref: "main"
|
||||
keepGitDir: true
|
||||
authToken: TestPAT
|
||||
}
|
||||
|
||||
TestPrivateRepository: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
mount: "/repo1": from: privateRepo
|
||||
dir: "/repo1"
|
||||
command: """
|
||||
[ -d .git ]
|
||||
"""
|
||||
}
|
||||
|
||||
TestReferenceFormat: os.#Container & {
|
||||
image: alpine.#Image & {
|
||||
package: bash: true
|
||||
package: git: true
|
||||
}
|
||||
mount: "/repo1": from: privateRepo
|
||||
dir: "/repo1"
|
||||
command: """
|
||||
URL="$(git ls-remote --get-url origin)"
|
||||
[[ "$URL" = "https://github.com/dagger/dagger.git" ]]
|
||||
"""
|
||||
}
|
Reference in New Issue
Block a user