Improve git package according to Sam comments
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
4ad2c8e7e5
commit
95040d8320
@ -12,24 +12,19 @@ import "alpha.dagger.io/git"
|
|||||||
|
|
||||||
## git.#Commit
|
## git.#Commit
|
||||||
|
|
||||||
Commit & push to github repository
|
Commit & push to git repository
|
||||||
|
|
||||||
### git.#Commit Inputs
|
### git.#Commit Inputs
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ------------- |:-------------: |:-------------: |
|
| ------------- |:-------------: |:-------------: |
|
||||||
|*repository.remote* | `string` |Repository remote URL |
|
|*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 |
|
|*repository.branch* | `string` |Git branch |
|
||||||
|*name* | `string` |Username |
|
|*name* | `string` |Username |
|
||||||
|*email* | `string` |Email |
|
|*email* | `string` |Email |
|
||||||
|*message* | `string` |Commit message |
|
|*message* | `string` |Commit message |
|
||||||
|*force* | `*false \| bool` |Force push options |
|
|*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
|
### git.#Commit Outputs
|
||||||
|
|
||||||
|
8
stdlib/.dagger/env/git-commit/values.yaml
vendored
8
stdlib/.dagger/env/git-commit/values.yaml
vendored
@ -2,8 +2,8 @@ plan:
|
|||||||
package: ./git/tests/commit
|
package: ./git/tests/commit
|
||||||
name: git-commit
|
name: git-commit
|
||||||
inputs:
|
inputs:
|
||||||
TestPAT:
|
TestAuthToken:
|
||||||
secret: ENC[AES256_GCM,data:9mUzH6KRPeZTnP/gH5656f4UOCeJYaignG6JQlMY0T1hKvr5ZX3etg==,iv:gCN7M478ipl5hoCjlmzCs5RNPTLjd7hu4G7tsMjO4iQ=,tag:EkZEJMSLuAffMhmR7Y+8MQ==,type:str]
|
secret: ENC[AES256_GCM,data:OB4CfijwCnsvmvVhbV9BNlkhmuWtv1hu/nd7+E8+5tCBcXLbwOaMYQ==,iv:6+U+r/mmO07moQoitAr8Fm7bdTErJ5Ij3J21xIbEqIg=,tag:gmWLMFrVU+5l2O2pvb4Rug==,type:str]
|
||||||
sops:
|
sops:
|
||||||
kms: []
|
kms: []
|
||||||
gcp_kms: []
|
gcp_kms: []
|
||||||
@ -19,8 +19,8 @@ sops:
|
|||||||
M3RnUDF5QlhhZUV4NHF5ZWhkcHVrNmcKUJIummOk3FX1Bert7gaMtbMpbosIf/d3
|
M3RnUDF5QlhhZUV4NHF5ZWhkcHVrNmcKUJIummOk3FX1Bert7gaMtbMpbosIf/d3
|
||||||
HBATJRng4VNmcSimSh14pDRxyW0NdIPA+oL4tidwLVbQQv/74+IGKg==
|
HBATJRng4VNmcSimSh14pDRxyW0NdIPA+oL4tidwLVbQQv/74+IGKg==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2021-09-01T15:23:54Z"
|
lastmodified: "2021-09-02T10:18:20Z"
|
||||||
mac: ENC[AES256_GCM,data:GKoX70utgBD8Xd04pVAQJcIs2yfm0jcOcUDeBdGenVljNZxbtHw8/cmCpXie0gPe85Cr6F+J0PFpx4OZhfyXuOv+Kl0ar1nklWHVwJrYeFD6n6H4NkSCME1xo2IDI4NOlYdIMo6daH2w32P+iFV50vENfEDbRdPQNM4fvFm0/Uw=,iv:1wKI7syuF99V/GKts3t4x5VCbbJJfDq7at6PFrgb88o=,tag:0aDEtxXXghcopv556S+xmQ==,type:str]
|
mac: ENC[AES256_GCM,data:RoWci1iCDYMxmK5BIoB822G6U9bcffOGIxMkvY560N8qxjItEb/Syvboa9MOjzDUhNPwxpaUIklzra0sy3u57iRBVZPfJ8tH9WKSQYeQv0ObtBXLAOVv1o8VJQbAd0WFNzZ7K0SSP8hUKQieDRvvIOlCFlNzJs6atrY9q/GEj4o=,iv:MOWALgh400eQSateXVDKY1Xrq/HFaVN+B0yoJxD4X4o=,tag:L0Bz7tD6gUOr9LsPPA4Plw==,type:str]
|
||||||
pgp: []
|
pgp: []
|
||||||
encrypted_suffix: secret
|
encrypted_suffix: secret
|
||||||
version: 3.7.1
|
version: 3.7.1
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"alpha.dagger.io/os"
|
"alpha.dagger.io/os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Commit & push to github repository
|
// Commit & push to git repository
|
||||||
#Commit: {
|
#Commit: {
|
||||||
// Git repository
|
// Git repository
|
||||||
repository: {
|
repository: {
|
||||||
@ -15,8 +15,8 @@ import (
|
|||||||
// Repository remote URL
|
// Repository remote URL
|
||||||
remote: dagger.#Input & {string}
|
remote: dagger.#Input & {string}
|
||||||
|
|
||||||
// Github PAT
|
// Authentication token (PAT or password)
|
||||||
PAT: dagger.#Input & {*null | dagger.#Secret}
|
authToken: dagger.#Input & {*null | dagger.#Secret}
|
||||||
|
|
||||||
// Git branch
|
// Git branch
|
||||||
branch: dagger.#Input & {string}
|
branch: dagger.#Input & {string}
|
||||||
@ -37,7 +37,7 @@ import (
|
|||||||
// Force push options
|
// Force push options
|
||||||
force: dagger.#Input & {*false | bool}
|
force: dagger.#Input & {*false | bool}
|
||||||
|
|
||||||
ctr: os.#Container & {
|
_ctr: os.#Container & {
|
||||||
image: #Image
|
image: #Image
|
||||||
command: #"""
|
command: #"""
|
||||||
# Move changes into repository
|
# Move changes into repository
|
||||||
@ -69,20 +69,20 @@ import (
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if repository.PAT != null {
|
if repository.authToken != null {
|
||||||
env: GIT_ASKPASS: "/get_gitPAT"
|
env: GIT_ASKPASS: "/get_authToken"
|
||||||
files: "/get_gitPAT": {
|
files: "/get_authToken": {
|
||||||
content: "cat /secret/github_pat"
|
content: "cat /secrets/authToken"
|
||||||
mode: 0o500
|
mode: 0o500
|
||||||
}
|
}
|
||||||
secret: "/secret/github_pat": repository.PAT
|
secret: "/secrets/authToken": repository.authToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit hash
|
// Commit hash
|
||||||
hash: {
|
hash: {
|
||||||
os.#File & {
|
os.#File & {
|
||||||
from: ctr
|
from: _ctr
|
||||||
path: "/commit.txt"
|
path: "/commit.txt"
|
||||||
}
|
}
|
||||||
}.contents & dagger.#Output
|
}.contents & dagger.#Output
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"alpha.dagger.io/alpine"
|
||||||
"alpha.dagger.io/dagger"
|
"alpha.dagger.io/dagger"
|
||||||
|
"alpha.dagger.io/dagger/op"
|
||||||
"alpha.dagger.io/os"
|
"alpha.dagger.io/os"
|
||||||
"alpha.dagger.io/random"
|
"alpha.dagger.io/random"
|
||||||
)
|
)
|
||||||
|
|
||||||
TestPAT: dagger.#Input & {dagger.#Secret}
|
TestAuthToken: dagger.#Input & {dagger.#Secret}
|
||||||
|
|
||||||
TestRemote: dagger.#Input & {*"https://github.com/dagger/test.git" | string}
|
TestRemote: dagger.#Input & {*"https://github.com/dagger/test.git" | string}
|
||||||
|
|
||||||
@ -14,7 +16,7 @@ TestRepository: #Repository & {
|
|||||||
remote: TestRemote
|
remote: TestRemote
|
||||||
ref: "main"
|
ref: "main"
|
||||||
keepGitDir: true
|
keepGitDir: true
|
||||||
authToken: TestPAT
|
authToken: TestAuthToken
|
||||||
}
|
}
|
||||||
|
|
||||||
TestData: {
|
TestData: {
|
||||||
@ -23,23 +25,39 @@ TestData: {
|
|||||||
}
|
}
|
||||||
}.out
|
}.out
|
||||||
|
|
||||||
TestFile: os.#Dir & {
|
// FIXME Currently throw a structural cycle error
|
||||||
from: os.#Container & {
|
//TestFile: os.#Dir & {
|
||||||
command: #"""
|
// from: os.#Container & {
|
||||||
mkdir -p /output
|
// image: alpine.#Image
|
||||||
echo "$MESSAGE" >> /output/test.md
|
// command: #"""
|
||||||
"""#
|
// mkdir -p /output
|
||||||
env: MESSAGE: TestData
|
// echo "$MESSAGE" >> /output/test.md
|
||||||
}
|
// """#
|
||||||
path: "/output"
|
// 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 & {
|
TestCommit: #Commit & {
|
||||||
repository: {
|
repository: {
|
||||||
remote: TestRemote
|
remote: TestRemote
|
||||||
PAT: TestPAT
|
authToken: TestAuthToken
|
||||||
source: TestRepository
|
source: TestRepository
|
||||||
branch: "ci/test-commit"
|
branch: "ci/test-commit"
|
||||||
}
|
}
|
||||||
content: TestFile
|
content: TestFile
|
||||||
message: "This is a commit from the CI to test the repository"
|
message: "This is a commit from the CI to test the repository"
|
||||||
@ -50,32 +68,28 @@ TestCommit: #Commit & {
|
|||||||
|
|
||||||
TestCheck: {
|
TestCheck: {
|
||||||
_TestRepo: #Repository & {
|
_TestRepo: #Repository & {
|
||||||
remote: TestCommit.repository.remote
|
remote: TestRemote
|
||||||
ref: TestCommit.repository.branch
|
ref: "ci/test-commit"
|
||||||
keepGitDir: true
|
keepGitDir: true
|
||||||
authToken: TestCommit.repository.PAT
|
authToken: TestAuthToken
|
||||||
}
|
}
|
||||||
|
|
||||||
_TestHash: TestCommit.hash
|
_ctr: os.#Container & {
|
||||||
|
image: #Image
|
||||||
os.#Container & {
|
|
||||||
image: #Image
|
|
||||||
command: #"""
|
command: #"""
|
||||||
# Check commit
|
# Check commit
|
||||||
# FIXME Interpolate because there is an empty disjuction error
|
git rev-parse --verify HEAD | grep "$GIT_HASH"
|
||||||
# when given to env
|
|
||||||
git rev-parse --verify HEAD | grep \#(TestCommit.hash)
|
|
||||||
|
|
||||||
# Check file
|
# Check file
|
||||||
echo "$MESSAGE" >> expect.md
|
echo -n "$EXPECTED_MESSAGE" >> expect.md
|
||||||
diff test.md expect.md
|
diff test.md expect.md
|
||||||
"""#
|
"""#
|
||||||
dir: "/input/repo"
|
dir: "/input/repo"
|
||||||
mount: "/input/repo": from: _TestRepo
|
mount: "/input/repo": from: _TestRepo
|
||||||
env: {
|
env: {
|
||||||
MESSAGE: TestData
|
EXPECTED_MESSAGE: TestData
|
||||||
// Force dependency
|
// Force dependency
|
||||||
// GIT_HASH: TestCommit.hash
|
GIT_HASH: TestCommit.hash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user