From 019b56891dab2e9693da1b7692dfd83301274f60 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Wed, 1 Sep 2021 18:40:02 +0200 Subject: [PATCH 1/5] Update old git test Signed-off-by: Tom Chauveau --- stdlib/.dagger/env/{git => git-repo}/.gitignore | 0 stdlib/.dagger/env/{git => git-repo}/values.yaml | 8 ++++---- stdlib/git/tests/{ => git}/git.cue | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) rename stdlib/.dagger/env/{git => git-repo}/.gitignore (100%) rename stdlib/.dagger/env/{git => git-repo}/values.yaml (70%) rename stdlib/git/tests/{ => git}/git.cue (90%) diff --git a/stdlib/.dagger/env/git/.gitignore b/stdlib/.dagger/env/git-repo/.gitignore similarity index 100% rename from stdlib/.dagger/env/git/.gitignore rename to stdlib/.dagger/env/git-repo/.gitignore diff --git a/stdlib/.dagger/env/git/values.yaml b/stdlib/.dagger/env/git-repo/values.yaml similarity index 70% rename from stdlib/.dagger/env/git/values.yaml rename to stdlib/.dagger/env/git-repo/values.yaml index 164b56f2..c07ef0da 100644 --- a/stdlib/.dagger/env/git/values.yaml +++ b/stdlib/.dagger/env/git-repo/values.yaml @@ -1,6 +1,6 @@ plan: - package: ./git/tests -name: git + package: ./git/tests/git +name: git-repo inputs: TestPAT: secret: ENC[AES256_GCM,data:7s1tSIpIDNBhAFupdjb7KtPbjKrCd5tXupr3RQF2N3Xu5XGuTZMgoQ==,iv:I+SVYLnjgMffvNg6BMB6m1lj+VVH5sDK0aIEAWPcyLY=,tag:TcfJ6LVps8dXVZGZy3T2ew==,type:str] @@ -19,8 +19,8 @@ sops: TmhJNisyamw3d244aGVJSEVFVUVLZGsKvd+nowA0CLXQbdvyI4J0lBjs9vdISWlo gGvR49uul3Z8raVWXFUzsyQ8xTvYNg0ovynFG2KdagSKr1DlhKMBEQ== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-08-26T13:44:11Z" - mac: ENC[AES256_GCM,data:ttmpbzhrVFEGh/oJF4TtMvf99rutPBbzp9cIaqakIl+5nxqOkuAakgvf7IIMBG235zdyMvIXZZh6NLYG51PZA1hKNMg5Pqqba9GOSvFCHasWzNJ3pi5SLBGD02ivDfkSMbEHeOCUhnG1X4LxkYL9j+fb4tQt1Btv1hiIAcIa+eY=,iv:WxuW+0yJYtNqAB0y1nji9c3lzn4Pftir8uZojcdphng=,tag:yvcIJxkuqOmCfXoyEnGWow==,type:str] + lastmodified: "2021-09-01T08:40:49Z" + mac: ENC[AES256_GCM,data:UgryTszQf7YgFfXL8YhzJekPIOymtd8adyijOp6AQW8JGXu989JtlXeUKvLpRkbyjZD8+oTTX1iK7Ssj/hJKgo0yklLc7O9sSQGhxjo/3WYTcKUcHd5Tj9yoZp+RFH1qZxpnkAexZoM2rwOT9FAhdV3/AJV2ekY2Qe3JbrGJr6s=,iv:DXiIE1oNDPGhXcL2aPXA2TcvY6Jee4mFypq3bELnAx4=,tag:qfHMnpGr6yFLSQHqIvyglA==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/git/tests/git.cue b/stdlib/git/tests/git/git.cue similarity index 90% rename from stdlib/git/tests/git.cue rename to stdlib/git/tests/git/git.cue index 3f00ca4b..ca7a675c 100644 --- a/stdlib/git/tests/git.cue +++ b/stdlib/git/tests/git/git.cue @@ -5,28 +5,27 @@ import ( "alpha.dagger.io/alpine" "alpha.dagger.io/dagger" - "alpha.dagger.io/git" "alpha.dagger.io/os" ) -repo: git.#Repository & { +repo: #Repository & { remote: "https://github.com/blocklayerhq/acme-clothing.git" ref: "master" keepGitDir: true } -repoSubDir: git.#Repository & { +repoSubDir: #Repository & { remote: "https://github.com/dagger/examples.git" ref: "main" subdir: "todoapp" keepGitDir: true } -branch: git.#CurrentBranch & { +branch: #CurrentBranch & { repository: repo } -tagsList: git.#Tags & { +tagsList: #Tags & { repository: repo } @@ -79,7 +78,7 @@ TestCurrentTags: os.#Container & { // Test fetching a private repo TestPAT: dagger.#Input & {dagger.#Secret} -privateRepo: git.#Repository & { +privateRepo: #Repository & { remote: "https://github.com/dagger/dagger.git" ref: "main" keepGitDir: true From c8e37551889962b63b9545e23261e678c1aae3bd Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Wed, 1 Sep 2021 18:48:54 +0200 Subject: [PATCH 2/5] Add git.#Commit definition and git.#Image This definition allow user to commit & push new content to repository. I've also add a quick feature to os.#Container to write files. Signed-off-by: Tom Chauveau --- stdlib/git/commit.cue | 89 +++++++++++++++++++++++++++++++++++++++++ stdlib/git/image.cue | 11 +++++ stdlib/os/container.cue | 13 ++++++ 3 files changed, 113 insertions(+) create mode 100644 stdlib/git/commit.cue create mode 100644 stdlib/git/image.cue diff --git a/stdlib/git/commit.cue b/stdlib/git/commit.cue new file mode 100644 index 00000000..37c82cb0 --- /dev/null +++ b/stdlib/git/commit.cue @@ -0,0 +1,89 @@ +package git + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/os" +) + +// Commit & push to github repository +#Commit: { + // Git repository + repository: { + // Repository source code + source: dagger.#Artifact + + // Repository remote URL (e.g https://github.com/dagger/dagger.git) + remote: dagger.#Input & {string} + + // Github PAT + PAT: 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.PAT != null { + env: "GIT_ASKPASS": "/get_gitPAT" + files: "/get_gitPAT": { + content: "cat /secret/github_pat" + mode: 0o500 + } + secret: "/secret/github_pat": repository.PAT + } + } + + // Commit hash + hash: { + os.#File & { + from: ctr + path: "/commit.txt" + } + }.contents & dagger.#Output +} diff --git a/stdlib/git/image.cue b/stdlib/git/image.cue new file mode 100644 index 00000000..a3a0a262 --- /dev/null +++ b/stdlib/git/image.cue @@ -0,0 +1,11 @@ +package git + +import ( + "alpha.dagger.io/alpine" +) + +#Image: alpine.#Image & { + package: { + git: true + } +} diff --git a/stdlib/os/container.cue b/stdlib/os/container.cue index 4e537205..92120e80 100644 --- a/stdlib/os/container.cue +++ b/stdlib/os/container.cue @@ -54,6 +54,12 @@ import ( // Safely mount secrets (in cleartext) as non-persistent files secret: [string]: dagger.#Secret + // Write file in the container + files: [string]: { + content: string + mode: int | *0o644 + } + // Mount persistent cache directories cache: [string]: true @@ -86,6 +92,13 @@ import ( "dir": dir } }, + for dest, file in files { + op.#WriteFile & { + "content": file.content + "mode": file.mode + "dest": dest + } + }, // Execute main command with volumes if command != "" { op.#Exec & { From 4ad2c8e7e58e09ad4b4cea02257533da23265739 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Wed, 1 Sep 2021 18:49:21 +0200 Subject: [PATCH 3/5] Add test on git.#Commit Signed-off-by: Tom Chauveau --- docs/reference/universe/git.md | 51 ++++++++++++-- stdlib/.dagger/env/git-commit/.gitignore | 2 + stdlib/.dagger/env/git-commit/values.yaml | 26 ++++++++ stdlib/git/commit.cue | 16 ++--- stdlib/git/git.cue | 3 +- stdlib/git/image.cue | 4 +- stdlib/git/tests/commit/commit.cue | 81 +++++++++++++++++++++++ stdlib/os/container.cue | 6 +- stdlib/universe.bats | 6 +- 9 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 stdlib/.dagger/env/git-commit/.gitignore create mode 100644 stdlib/.dagger/env/git-commit/values.yaml create mode 100644 stdlib/git/tests/commit/commit.cue 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" { From 95040d83203272011a0482845ac59c26daf38b68 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 2 Sep 2021 14:23:57 +0200 Subject: [PATCH 4/5] Improve git package according to Sam comments Signed-off-by: Tom Chauveau --- docs/reference/universe/git.md | 25 +++---- stdlib/.dagger/env/git-commit/values.yaml | 8 +-- stdlib/git/commit.cue | 20 +++--- stdlib/git/tests/commit/commit.cue | 82 +++++++++++++---------- 4 files changed, 72 insertions(+), 63 deletions(-) diff --git a/docs/reference/universe/git.md b/docs/reference/universe/git.md index 2d8a376c..59990600 100644 --- a/docs/reference/universe/git.md +++ b/docs/reference/universe/git.md @@ -12,24 +12,19 @@ import "alpha.dagger.io/git" ## git.#Commit -Commit & push to github repository +Commit & push to git 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` |- | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*repository.remote* | `string` |Repository remote URL | +|*repository.authToken* | `dagger.#Secret` |Authentication token (PAT or password) | +|*repository.branch* | `string` |Git branch | +|*name* | `string` |Username | +|*email* | `string` |Email | +|*message* | `string` |Commit message | +|*force* | `*false \| bool` |Force push options | ### git.#Commit Outputs diff --git a/stdlib/.dagger/env/git-commit/values.yaml b/stdlib/.dagger/env/git-commit/values.yaml index efd0985e..b68716d0 100644 --- a/stdlib/.dagger/env/git-commit/values.yaml +++ b/stdlib/.dagger/env/git-commit/values.yaml @@ -2,8 +2,8 @@ plan: package: ./git/tests/commit name: git-commit inputs: - TestPAT: - secret: ENC[AES256_GCM,data:9mUzH6KRPeZTnP/gH5656f4UOCeJYaignG6JQlMY0T1hKvr5ZX3etg==,iv:gCN7M478ipl5hoCjlmzCs5RNPTLjd7hu4G7tsMjO4iQ=,tag:EkZEJMSLuAffMhmR7Y+8MQ==,type:str] + TestAuthToken: + secret: ENC[AES256_GCM,data:OB4CfijwCnsvmvVhbV9BNlkhmuWtv1hu/nd7+E8+5tCBcXLbwOaMYQ==,iv:6+U+r/mmO07moQoitAr8Fm7bdTErJ5Ij3J21xIbEqIg=,tag:gmWLMFrVU+5l2O2pvb4Rug==,type:str] sops: kms: [] gcp_kms: [] @@ -19,8 +19,8 @@ sops: 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] + lastmodified: "2021-09-02T10:18:20Z" + mac: ENC[AES256_GCM,data:RoWci1iCDYMxmK5BIoB822G6U9bcffOGIxMkvY560N8qxjItEb/Syvboa9MOjzDUhNPwxpaUIklzra0sy3u57iRBVZPfJ8tH9WKSQYeQv0ObtBXLAOVv1o8VJQbAd0WFNzZ7K0SSP8hUKQieDRvvIOlCFlNzJs6atrY9q/GEj4o=,iv:MOWALgh400eQSateXVDKY1Xrq/HFaVN+B0yoJxD4X4o=,tag:L0Bz7tD6gUOr9LsPPA4Plw==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/git/commit.cue b/stdlib/git/commit.cue index b1418c46..2b424a27 100644 --- a/stdlib/git/commit.cue +++ b/stdlib/git/commit.cue @@ -5,7 +5,7 @@ import ( "alpha.dagger.io/os" ) -// Commit & push to github repository +// Commit & push to git repository #Commit: { // Git repository repository: { @@ -15,8 +15,8 @@ import ( // Repository remote URL remote: dagger.#Input & {string} - // Github PAT - PAT: dagger.#Input & {*null | dagger.#Secret} + // Authentication token (PAT or password) + authToken: dagger.#Input & {*null | dagger.#Secret} // Git branch branch: dagger.#Input & {string} @@ -37,7 +37,7 @@ import ( // Force push options force: dagger.#Input & {*false | bool} - ctr: os.#Container & { + _ctr: os.#Container & { image: #Image command: #""" # Move changes into repository @@ -69,20 +69,20 @@ import ( } } - if repository.PAT != null { - env: GIT_ASKPASS: "/get_gitPAT" - files: "/get_gitPAT": { - content: "cat /secret/github_pat" + if repository.authToken != null { + env: GIT_ASKPASS: "/get_authToken" + files: "/get_authToken": { + content: "cat /secrets/authToken" mode: 0o500 } - secret: "/secret/github_pat": repository.PAT + secret: "/secrets/authToken": repository.authToken } } // Commit hash hash: { os.#File & { - from: ctr + from: _ctr path: "/commit.txt" } }.contents & dagger.#Output diff --git a/stdlib/git/tests/commit/commit.cue b/stdlib/git/tests/commit/commit.cue index e21ec5bd..b460ab30 100644 --- a/stdlib/git/tests/commit/commit.cue +++ b/stdlib/git/tests/commit/commit.cue @@ -1,12 +1,14 @@ package git import ( + "alpha.dagger.io/alpine" "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" "alpha.dagger.io/os" "alpha.dagger.io/random" ) -TestPAT: dagger.#Input & {dagger.#Secret} +TestAuthToken: dagger.#Input & {dagger.#Secret} TestRemote: dagger.#Input & {*"https://github.com/dagger/test.git" | string} @@ -14,7 +16,7 @@ TestRepository: #Repository & { remote: TestRemote ref: "main" keepGitDir: true - authToken: TestPAT + authToken: TestAuthToken } TestData: { @@ -23,23 +25,39 @@ TestData: { } }.out -TestFile: os.#Dir & { - from: os.#Container & { - command: #""" - mkdir -p /output - echo "$MESSAGE" >> /output/test.md - """# - env: MESSAGE: TestData - } - path: "/output" -} +// FIXME Currently throw a structural cycle error +//TestFile: os.#Dir & { +// from: os.#Container & { +// image: alpine.#Image +// command: #""" +// mkdir -p /output +// echo "$MESSAGE" >> /output/test.md +// """# +// env: MESSAGE: TestData +// } +// path: "/output" +//} + +TestFile: #up: [ + op.#Load & {from: alpine.#Image}, + op.#Mkdir & { + path: "/output" + }, + op.#WriteFile & { + content: TestData + dest: "/output/test.md" + }, + op.#Subdir & { + dir: "/output" + }, +] TestCommit: #Commit & { repository: { - remote: TestRemote - PAT: TestPAT - source: TestRepository - branch: "ci/test-commit" + remote: TestRemote + authToken: TestAuthToken + source: TestRepository + branch: "ci/test-commit" } content: TestFile message: "This is a commit from the CI to test the repository" @@ -50,32 +68,28 @@ TestCommit: #Commit & { TestCheck: { _TestRepo: #Repository & { - remote: TestCommit.repository.remote - ref: TestCommit.repository.branch + remote: TestRemote + ref: "ci/test-commit" keepGitDir: true - authToken: TestCommit.repository.PAT + authToken: TestAuthToken } - _TestHash: TestCommit.hash - - os.#Container & { - image: #Image + _ctr: 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 commit + git rev-parse --verify HEAD | grep "$GIT_HASH" - # Check file - echo "$MESSAGE" >> expect.md - diff test.md expect.md - """# - dir: "/input/repo" + # Check file + echo -n "$EXPECTED_MESSAGE" >> expect.md + diff test.md expect.md + """# + dir: "/input/repo" mount: "/input/repo": from: _TestRepo env: { - MESSAGE: TestData + EXPECTED_MESSAGE: TestData // Force dependency - // GIT_HASH: TestCommit.hash + GIT_HASH: TestCommit.hash } } } From 9448fba997a244d242ebb0413b890d5db540ff03 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Fri, 3 Sep 2021 02:28:35 +0200 Subject: [PATCH 5/5] Fix structural cycle error Signed-off-by: Guillaume de Rouville --- stdlib/git/tests/commit/commit.cue | 42 +++++++++--------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/stdlib/git/tests/commit/commit.cue b/stdlib/git/tests/commit/commit.cue index b460ab30..90908c5b 100644 --- a/stdlib/git/tests/commit/commit.cue +++ b/stdlib/git/tests/commit/commit.cue @@ -3,7 +3,6 @@ package git import ( "alpha.dagger.io/alpine" "alpha.dagger.io/dagger" - "alpha.dagger.io/dagger/op" "alpha.dagger.io/os" "alpha.dagger.io/random" ) @@ -25,32 +24,17 @@ TestData: { } }.out -// FIXME Currently throw a structural cycle error -//TestFile: os.#Dir & { -// from: os.#Container & { -// image: alpine.#Image -// command: #""" -// mkdir -p /output -// echo "$MESSAGE" >> /output/test.md -// """# -// env: MESSAGE: TestData -// } -// path: "/output" -//} - -TestFile: #up: [ - op.#Load & {from: alpine.#Image}, - op.#Mkdir & { - path: "/output" - }, - op.#WriteFile & { - content: TestData - dest: "/output/test.md" - }, - op.#Subdir & { - dir: "/output" - }, -] +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: { @@ -88,8 +72,8 @@ TestCheck: { mount: "/input/repo": from: _TestRepo env: { EXPECTED_MESSAGE: TestData - // Force dependency - GIT_HASH: TestCommit.hash + // Force dependency with interpolation + GIT_HASH: "\(TestCommit.hash)" } } }