From 95040d83203272011a0482845ac59c26daf38b68 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 2 Sep 2021 14:23:57 +0200 Subject: [PATCH] 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 } } }