diff --git a/docs/reference/universe/git.md b/docs/reference/universe/git.md index f9107ac7..2d8a376c 100644 --- a/docs/reference/universe/git.md +++ b/docs/reference/universe/git.md @@ -10,6 +10,33 @@ Git operations import "alpha.dagger.io/git" ``` +## git.#Commit + +Commit & push to github repository + +### git.#Commit Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*repository.remote* | `string` |Repository remote URL | +|*repository.PAT* | `dagger.#Secret` |Github PAT | +|*repository.branch* | `string` |Git branch | +|*name* | `string` |Username | +|*email* | `string` |Email | +|*message* | `string` |Commit message | +|*force* | `*false \| bool` |Force push options | +|*ctr.env.USER_NAME* | `string` |- | +|*ctr.env.USER_EMAIL* | `string` |- | +|*ctr.env.COMMIT_MESSAGE* | `string` |- | +|*ctr.env.GIT_BRANCH* | `string` |- | +|*ctr.env.GIT_REMOTE* | `string` |- | + +### git.#Commit Outputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*hash* | `string` |Commit hash | + ## git.#CurrentBranch Get the name of the current checked out branch or tag @@ -26,19 +53,29 @@ Get the name of the current checked out branch or tag | ------------- |:-------------: |:-------------: | |*name* | `string` |Git branch name | +## git.#Image + +### git.#Image Inputs + +_No input._ + +### git.#Image Outputs + +_No output._ + ## git.#Repository A git repository ### git.#Repository Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*remote* | `string` |Git remote. Example: `"https://github.com/dagger/dagger"` | -|*ref* | `string` |Git ref: can be a commit, tag or branch. Example: "main" | -|*subdir* | `*null \| string` |(optional) Subdirectory | -|*authToken* | `dagger.#Secret` |(optional) Add Personal Access Token | -|*authHeader* | `dagger.#Secret` |(optional) Add OAuth Token | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*remote* | `string` |Git remote link | +|*ref* | `string` |Git ref: can be a commit, tag or branch. Example: "main" | +|*subdir* | `*null \| string` |(optional) Subdirectory | +|*authToken* | `dagger.#Secret` |(optional) Add Personal Access Token | +|*authHeader* | `dagger.#Secret` |(optional) Add OAuth Token | ### git.#Repository Outputs diff --git a/stdlib/.dagger/env/git-commit/.gitignore b/stdlib/.dagger/env/git-commit/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/git-commit/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/git-commit/values.yaml b/stdlib/.dagger/env/git-commit/values.yaml new file mode 100644 index 00000000..efd0985e --- /dev/null +++ b/stdlib/.dagger/env/git-commit/values.yaml @@ -0,0 +1,26 @@ +plan: + package: ./git/tests/commit +name: git-commit +inputs: + TestPAT: + secret: ENC[AES256_GCM,data:9mUzH6KRPeZTnP/gH5656f4UOCeJYaignG6JQlMY0T1hKvr5ZX3etg==,iv:gCN7M478ipl5hoCjlmzCs5RNPTLjd7hu4G7tsMjO4iQ=,tag:EkZEJMSLuAffMhmR7Y+8MQ==,type:str] +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBnWkIxUExFTnQ2VS9pSHVv + Ykd6eUl4dlRQeU9YRGtLQWhPNExZakZORG5VCkVLN3NnNlNxZ0hmQW9TRGU5WXpN + UmYzZE1BUWZ1WDlPWjA2dURIbDA1bGcKLS0tIHBkR3c2U3IxY2w5Z0YxOWxLRkVv + M3RnUDF5QlhhZUV4NHF5ZWhkcHVrNmcKUJIummOk3FX1Bert7gaMtbMpbosIf/d3 + HBATJRng4VNmcSimSh14pDRxyW0NdIPA+oL4tidwLVbQQv/74+IGKg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-09-01T15:23:54Z" + mac: ENC[AES256_GCM,data:GKoX70utgBD8Xd04pVAQJcIs2yfm0jcOcUDeBdGenVljNZxbtHw8/cmCpXie0gPe85Cr6F+J0PFpx4OZhfyXuOv+Kl0ar1nklWHVwJrYeFD6n6H4NkSCME1xo2IDI4NOlYdIMo6daH2w32P+iFV50vENfEDbRdPQNM4fvFm0/Uw=,iv:1wKI7syuF99V/GKts3t4x5VCbbJJfDq7at6PFrgb88o=,tag:0aDEtxXXghcopv556S+xmQ==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/git/commit.cue b/stdlib/git/commit.cue index 37c82cb0..b1418c46 100644 --- a/stdlib/git/commit.cue +++ b/stdlib/git/commit.cue @@ -12,7 +12,7 @@ import ( // Repository source code source: dagger.#Artifact - // Repository remote URL (e.g https://github.com/dagger/dagger.git) + // Repository remote URL remote: dagger.#Input & {string} // Github PAT @@ -59,18 +59,18 @@ import ( "/input/content": from: content } env: { - "USER_NAME": name - "USER_EMAIL": email - "COMMIT_MESSAGE": message - "GIT_BRANCH": repository.branch - "GIT_REMOTE": repository.remote + USER_NAME: name + USER_EMAIL: email + COMMIT_MESSAGE: message + GIT_BRANCH: repository.branch + GIT_REMOTE: repository.remote if force { - "OPT_FORCE": "-f" + OPT_FORCE: "-f" } } if repository.PAT != null { - env: "GIT_ASKPASS": "/get_gitPAT" + env: GIT_ASKPASS: "/get_gitPAT" files: "/get_gitPAT": { content: "cat /secret/github_pat" mode: 0o500 diff --git a/stdlib/git/git.cue b/stdlib/git/git.cue index 8a12177d..5a7e338e 100644 --- a/stdlib/git/git.cue +++ b/stdlib/git/git.cue @@ -9,8 +9,7 @@ import ( // A git repository #Repository: { - // Git remote. - // Example: `"https://github.com/dagger/dagger"` + // Git remote link remote: dagger.#Input & {string} // Git ref: can be a commit, tag or branch. diff --git a/stdlib/git/image.cue b/stdlib/git/image.cue index a3a0a262..38da5a78 100644 --- a/stdlib/git/image.cue +++ b/stdlib/git/image.cue @@ -5,7 +5,5 @@ import ( ) #Image: alpine.#Image & { - package: { - git: true - } + package: git: true } diff --git a/stdlib/git/tests/commit/commit.cue b/stdlib/git/tests/commit/commit.cue new file mode 100644 index 00000000..e21ec5bd --- /dev/null +++ b/stdlib/git/tests/commit/commit.cue @@ -0,0 +1,81 @@ +package git + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/os" + "alpha.dagger.io/random" +) + +TestPAT: dagger.#Input & {dagger.#Secret} + +TestRemote: dagger.#Input & {*"https://github.com/dagger/test.git" | string} + +TestRepository: #Repository & { + remote: TestRemote + ref: "main" + keepGitDir: true + authToken: TestPAT +} + +TestData: { + random.#String & { + seed: "git-commit" + } +}.out + +TestFile: os.#Dir & { + from: os.#Container & { + command: #""" + mkdir -p /output + echo "$MESSAGE" >> /output/test.md + """# + env: MESSAGE: TestData + } + path: "/output" +} + +TestCommit: #Commit & { + repository: { + remote: TestRemote + PAT: TestPAT + 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: TestCommit.repository.remote + ref: TestCommit.repository.branch + keepGitDir: true + authToken: TestCommit.repository.PAT + } + + _TestHash: TestCommit.hash + + os.#Container & { + image: #Image + command: #""" + # Check commit + # FIXME Interpolate because there is an empty disjuction error + # when given to env + git rev-parse --verify HEAD | grep \#(TestCommit.hash) + + # Check file + echo "$MESSAGE" >> expect.md + diff test.md expect.md + """# + dir: "/input/repo" + mount: "/input/repo": from: _TestRepo + env: { + MESSAGE: TestData + // Force dependency + // GIT_HASH: TestCommit.hash + } + } +} diff --git a/stdlib/os/container.cue b/stdlib/os/container.cue index 92120e80..20f57fe6 100644 --- a/stdlib/os/container.cue +++ b/stdlib/os/container.cue @@ -94,9 +94,9 @@ import ( }, for dest, file in files { op.#WriteFile & { - "content": file.content - "mode": file.mode - "dest": dest + content: file.content + mode: file.mode + "dest": dest } }, // Execute main command with volumes diff --git a/stdlib/universe.bats b/stdlib/universe.bats index add1cc19..b0470e94 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -40,7 +40,11 @@ setup() { } @test "git" { - dagger -e git up + # Fetch repo + dagger -e git-repo up + + # Commit & push + dagger -e git-commit up } @test "os.#Container" {