Add test on git.#Commit

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-09-01 18:49:21 +02:00 committed by Guillaume de Rouville
parent c8e3755188
commit 4ad2c8e7e5
9 changed files with 171 additions and 24 deletions

View File

@ -10,6 +10,33 @@ Git operations
import "alpha.dagger.io/git" 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 ## git.#CurrentBranch
Get the name of the current checked out branch or tag Get the name of the current checked out branch or tag
@ -26,6 +53,16 @@ Get the name of the current checked out branch or tag
| ------------- |:-------------: |:-------------: | | ------------- |:-------------: |:-------------: |
|*name* | `string` |Git branch name | |*name* | `string` |Git branch name |
## git.#Image
### git.#Image Inputs
_No input._
### git.#Image Outputs
_No output._
## git.#Repository ## git.#Repository
A git repository A git repository
@ -34,7 +71,7 @@ A git repository
| Name | Type | Description | | Name | Type | Description |
| ------------- |:-------------: |:-------------: | | ------------- |:-------------: |:-------------: |
|*remote* | `string` |Git remote. Example: `"https://github.com/dagger/dagger"` | |*remote* | `string` |Git remote link |
|*ref* | `string` |Git ref: can be a commit, tag or branch. Example: "main" | |*ref* | `string` |Git ref: can be a commit, tag or branch. Example: "main" |
|*subdir* | `*null \| string` |(optional) Subdirectory | |*subdir* | `*null \| string` |(optional) Subdirectory |
|*authToken* | `dagger.#Secret` |(optional) Add Personal Access Token | |*authToken* | `dagger.#Secret` |(optional) Add Personal Access Token |

View File

@ -0,0 +1,2 @@
# dagger state
state/**

View File

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

View File

@ -12,7 +12,7 @@ import (
// Repository source code // Repository source code
source: dagger.#Artifact source: dagger.#Artifact
// Repository remote URL (e.g https://github.com/dagger/dagger.git) // Repository remote URL
remote: dagger.#Input & {string} remote: dagger.#Input & {string}
// Github PAT // Github PAT
@ -59,18 +59,18 @@ import (
"/input/content": from: content "/input/content": from: content
} }
env: { env: {
"USER_NAME": name USER_NAME: name
"USER_EMAIL": email USER_EMAIL: email
"COMMIT_MESSAGE": message COMMIT_MESSAGE: message
"GIT_BRANCH": repository.branch GIT_BRANCH: repository.branch
"GIT_REMOTE": repository.remote GIT_REMOTE: repository.remote
if force { if force {
"OPT_FORCE": "-f" OPT_FORCE: "-f"
} }
} }
if repository.PAT != null { if repository.PAT != null {
env: "GIT_ASKPASS": "/get_gitPAT" env: GIT_ASKPASS: "/get_gitPAT"
files: "/get_gitPAT": { files: "/get_gitPAT": {
content: "cat /secret/github_pat" content: "cat /secret/github_pat"
mode: 0o500 mode: 0o500

View File

@ -9,8 +9,7 @@ import (
// A git repository // A git repository
#Repository: { #Repository: {
// Git remote. // Git remote link
// Example: `"https://github.com/dagger/dagger"`
remote: dagger.#Input & {string} remote: dagger.#Input & {string}
// Git ref: can be a commit, tag or branch. // Git ref: can be a commit, tag or branch.

View File

@ -5,7 +5,5 @@ import (
) )
#Image: alpine.#Image & { #Image: alpine.#Image & {
package: { package: git: true
git: true
}
} }

View File

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

View File

@ -94,8 +94,8 @@ import (
}, },
for dest, file in files { for dest, file in files {
op.#WriteFile & { op.#WriteFile & {
"content": file.content content: file.content
"mode": file.mode mode: file.mode
"dest": dest "dest": dest
} }
}, },

View File

@ -40,7 +40,11 @@ setup() {
} }
@test "git" { @test "git" {
dagger -e git up # Fetch repo
dagger -e git-repo up
# Commit & push
dagger -e git-commit up
} }
@test "os.#Container" { @test "os.#Container" {