diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0488dfe --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.drone.jsonnet +.drone.jsonnet.yml \ No newline at end of file diff --git a/windows/clone-commit.ps1 b/windows/clone-commit.ps1 new file mode 100644 index 0000000..d0426fd --- /dev/null +++ b/windows/clone-commit.ps1 @@ -0,0 +1,13 @@ + +Set-Variable -Name "FLAGS" -Value "" +if ($Env:PLUGIN_DEPTH) { + Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" +} + +if (!(Test-Path .git)) { + git init + git remote add origin $Env:DRONE_REMOTE_URL +} + +git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:" +git checkout $Env:DRONE_COMMIT_SHA -b $Env:DRONE_COMMIT_BRANCH diff --git a/windows/clone-pull-request.ps1 b/windows/clone-pull-request.ps1 new file mode 100644 index 0000000..6941ee1 --- /dev/null +++ b/windows/clone-pull-request.ps1 @@ -0,0 +1,16 @@ + +Set-Variable -Name "FLAGS" -Value "" +if ($Env:PLUGIN_DEPTH) { + Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" +} + +if (!(Test-Path .git)) { + git init + git remote add origin $Env:DRONE_REMOTE_URL +} + +git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:" +git checkout $Env:DRONE_COMMIT_BRANCH + +git fetch origin $Env:DRONE_COMMIT_REF: +git rebase $Env:DRONE_COMMIT_SHA diff --git a/windows/clone-tag.ps1 b/windows/clone-tag.ps1 new file mode 100644 index 0000000..a37a3f1 --- /dev/null +++ b/windows/clone-tag.ps1 @@ -0,0 +1,13 @@ + +Set-Variable -Name "FLAGS" -Value "" +if ($Env:PLUGIN_DEPTH) { + Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" +} + +if (!(Test-Path .git)) { + git init + git remote add origin $Env:DRONE_REMOTE_URL +} + +git fetch $FLAGS origin "+refs/tags/${Env:DRONE_TAG}:" +git checkout -qf FETCH_HEAD diff --git a/windows/clone.ps1 b/windows/clone.ps1 new file mode 100644 index 0000000..263b815 --- /dev/null +++ b/windows/clone.ps1 @@ -0,0 +1,60 @@ +$ErrorActionPreference = 'Stop'; + +# if the workspace is set we should make sure +# it is the current working directory. + +if ($Env:DRONE_WORKSPACE) { + cd $Env:DRONE_WORKSPACE +} + +# if the netrc enviornment variables exist, write +# the netrc file. + +if ($Env:DRONE_NETRC_MACHINE) { + +$netrc=[string]::Format("{0}\_netrc",$Env:HOME); +"machine $Env:CI_NETRC_MACHINE" >> $netrc; +"login $Env:CI_NETRC_USERNAME" >> $netrc; +"password $Env:CI_NETRC_PASSWORD" >> $netrc; +} + +# configure git global behavior and parameters via the +# following environment variables: + +if ($Env:PLUGIN_SKIP_VERIFY) { + $Env:GIT_SSL_NO_VERIFY = "true" +} + +if ($Env:DRONE_COMMIT_AUTHOR_NAME) { + $Env:GIT_AUTHOR_NAME = $Env:DRONE_COMMIT_AUTHOR_NAME +} else { + $Env:GIT_AUTHOR_NAME = "drone" +} + +if ($Env:DRONE_COMMIT_AUTHOR_NAME) { + $Env:GIT_AUTHOR_NAME = $Env:DRONE_COMMIT_AUTHOR_NAME +} else { + $Env:GIT_AUTHOR_NAME = 'drone@localhost' +} + +$Env:GIT_COMMITTER_NAME = $Env:GIT_AUTHOR_NAME +$Env:GIT_COMMITTER_EMAIL = $Env:GIT_AUTHOR_EMAIL + +# invoke the sub-script based on the drone event type. +# TODO we should ultimately look at the ref, since +# we need something compatible with deployment events. + +switch ($Env:DRONE_BUILD_EVENT) { + "pull_request" { + .\clone-pull-reqest.ps1 + break + } + "tag" { + .\clone-tag.ps1 + break + } + default { + .\clone-commit.ps1 + break + } +}