Improve git package according to Sam comments

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-09-02 14:23:57 +02:00 committed by Guillaume de Rouville
parent 4ad2c8e7e5
commit 95040d8320
4 changed files with 72 additions and 63 deletions

View File

@ -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.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 |
|*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

View File

@ -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

View File

@ -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

View File

@ -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,21 +25,37 @@ TestData: {
}
}.out
TestFile: os.#Dir & {
from: os.#Container & {
command: #"""
mkdir -p /output
echo "$MESSAGE" >> /output/test.md
"""#
env: MESSAGE: TestData
}
// 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
authToken: TestAuthToken
source: TestRepository
branch: "ci/test-commit"
}
@ -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 & {
_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)
git rev-parse --verify HEAD | grep "$GIT_HASH"
# Check file
echo "$MESSAGE" >> expect.md
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
}
}
}