├── .dockerignore ├── .drone.yml ├── .github ├── issue_template.md └── pull_request_template.md ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── posix ├── clone ├── clone-commit ├── clone-pull-request ├── clone-tag ├── fixtures.sh ├── fixtures.tar ├── posix.go ├── posix_gen.go └── posix_test.go ├── scripts └── includetext.go └── windows ├── clone-commit.ps1 ├── clone-pull-request.ps1 ├── clone-tag.ps1 ├── clone.ps1 ├── windows.go └── windows_gen.go /.dockerignore: -------------------------------------------------------------------------------- 1 | .github 2 | .gitignore 3 | .drone.yml 4 | LICENSE 5 | README.md 6 | */fixtures* 7 | *.go 8 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: pipeline 3 | type: vm 4 | name: linux-amd64 5 | 6 | platform: 7 | os: linux 8 | arch: amd64 9 | 10 | pool: 11 | use: ubuntu 12 | 13 | steps: 14 | - name: build 15 | image: golang:1.10 16 | commands: 17 | - cd posix 18 | - tar -xf fixtures.tar -C / 19 | - go test -v 20 | 21 | - name: publish 22 | image: plugins/docker:18 23 | settings: 24 | dockerfile: docker/Dockerfile.linux.amd64 25 | repo: drone/git 26 | auto_tag: "true" 27 | auto_tag_suffix: linux-amd64 28 | username: 29 | from_secret: docker_username 30 | password: 31 | from_secret: docker_password 32 | when: 33 | event: 34 | - push 35 | - tag 36 | 37 | --- 38 | kind: pipeline 39 | type: vm 40 | name: linux-arm64 41 | 42 | platform: 43 | os: linux 44 | arch: arm64 45 | 46 | pool: 47 | use: ubuntu_arm64 48 | 49 | steps: 50 | - name: build 51 | image: golang:1.10 52 | commands: 53 | - cd posix 54 | - tar -xf fixtures.tar -C / 55 | - go test -v 56 | 57 | - name: publish 58 | image: plugins/docker:18 59 | settings: 60 | dockerfile: docker/Dockerfile.linux.arm64 61 | repo: drone/git 62 | auto_tag: "true" 63 | auto_tag_suffix: linux-arm64 64 | username: 65 | from_secret: docker_username 66 | password: 67 | from_secret: docker_password 68 | when: 69 | event: 70 | - push 71 | - tag 72 | 73 | --- 74 | kind: pipeline 75 | type: vm 76 | name: windows-1809 77 | 78 | platform: 79 | os: windows 80 | arch: amd64 81 | 82 | pool: 83 | use: windows 84 | 85 | steps: 86 | - name: docker 87 | image: plugins/docker 88 | settings: 89 | dockerfile: docker/Dockerfile.windows.1809 90 | repo: drone/git 91 | username: 92 | from_secret: docker_username 93 | password: 94 | from_secret: docker_password 95 | auto_tag: true 96 | auto_tag_suffix: windows-1809-amd64 97 | daemon_off: true 98 | purge: false 99 | 100 | trigger: 101 | event: 102 | - push 103 | 104 | --- 105 | kind: pipeline 106 | type: vm 107 | name: windows-ltsc2022 108 | 109 | platform: 110 | os: windows 111 | arch: amd64 112 | 113 | pool: 114 | use: windows-2022 115 | 116 | steps: 117 | - name: docker 118 | image: plugins/docker 119 | settings: 120 | dockerfile: docker/Dockerfile.windows.ltsc2022 121 | repo: drone/git 122 | username: 123 | from_secret: docker_username 124 | password: 125 | from_secret: docker_password 126 | auto_tag: true 127 | auto_tag_suffix: windows-ltsc2022-amd64 128 | daemon_off: true 129 | purge: false 130 | 131 | trigger: 132 | event: 133 | - push 134 | 135 | --- 136 | kind: pipeline 137 | type: vm 138 | name: manifest 139 | 140 | platform: 141 | os: linux 142 | arch: amd64 143 | 144 | pool: 145 | use: ubuntu 146 | 147 | steps: 148 | - name: manifest 149 | image: plugins/manifest 150 | settings: 151 | auto_tag: "true" 152 | ignore_missing: "true" 153 | spec: docker/manifest.tmpl 154 | username: 155 | from_secret: docker_username 156 | password: 157 | from_secret: docker_password 158 | 159 | trigger: 160 | event: 161 | - push 162 | - tag 163 | 164 | depends_on: 165 | - linux-amd64 166 | - linux-arm64 167 | - windows-1809 168 | - windows-ltsc2022 169 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone/drone-git/39d233b3d9eccc68e66508a06a725a2567f33143/.github/pull_request_template.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone/drone-git/39d233b3d9eccc68e66508a06a725a2567f33143/.gitignore -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | ### Added 9 | 10 | ## [1.1.0] 11 | ### Added 12 | 13 | - Ability to clone tags for promotion events from [@josmo](https://github.com/josme) 14 | - Support for git lfs in base images from [@carlwgeorge](https://github.com/carlwgeorge) 15 | - Support for windows 1803 from [@donny-dont](https://github.com/donny-dont) 16 | - Support for windows 1809 from [@donny-dont](https://github.com/donny-dont) 17 | 18 | ### Fixed 19 | 20 | - Fixed error merging when missing email from [@bradrydzewski](https://github.com/bradrydzewski) 21 | - Fixed empty ref on windows from [@drpebcak](https://github.com/drpebcak) 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2017 Drone.IO, Inc. 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | https://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-git 2 | 3 | Drone plugin to clone `git` repositories. 4 | 5 | ## Build 6 | 7 | Build the Docker image with the following commands: 8 | 9 | ``` 10 | docker build --rm -f docker/Dockerfile.linux.amd64 -t drone/git . 11 | ``` 12 | 13 | ## Usage 14 | 15 | Clone a commit: 16 | 17 | ``` 18 | docker run --rm \ 19 | -e DRONE_WORKSPACE=/drone \ 20 | -e DRONE_REMOTE_URL=https://github.com/drone/envsubst.git \ 21 | -e DRONE_BUILD_EVENT=push \ 22 | -e DRONE_COMMIT_SHA=15e3f9b7e16332eee3bbdff9ef31f95d23c5da2c \ 23 | -e DRONE_COMMIT_BRANCH=master \ 24 | drone/git 25 | ``` 26 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM alpine:3.12 2 | RUN apk add --no-cache ca-certificates git git-lfs openssh curl perl aws-cli sudo 3 | 4 | ADD posix/* /usr/local/bin/ 5 | 6 | # RUN adduser -g Drone -s /bin/sh -D -u 1000 drone 7 | # RUN echo 'drone ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/drone 8 | # USER drone:drone 9 | # RUN chmod -R 777 /home/drone 10 | 11 | ENTRYPOINT ["/usr/local/bin/clone"] -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM arm64v8/alpine:3.12 2 | RUN apk add --no-cache ca-certificates git git-lfs openssh curl perl aws-cli sudo 3 | 4 | ADD posix/* /usr/local/bin/ 5 | 6 | # RUN adduser -g Drone -s /bin/sh -D -u 1000 drone 7 | # RUN echo 'drone ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/drone 8 | # USER drone:drone 9 | # RUN chmod -R 777 /home/drone 10 | 11 | ENTRYPOINT ["/usr/local/bin/clone"] 12 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | 3 | FROM mcr.microsoft.com/windows/servercore:1809 AS git 4 | SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] 5 | 6 | RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` 7 | Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` 8 | Expand-Archive git.zip -DestinationPath C:\git; 9 | 10 | FROM mcr.microsoft.com/powershell:nanoserver-1809 11 | COPY --from=git /git /git 12 | 13 | ADD windows/* /bin/ 14 | 15 | # https://github.com/PowerShell/PowerShell/issues/6211#issuecomment-367477137 16 | USER ContainerAdministrator 17 | RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell" 18 | 19 | SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] 20 | CMD [ "pwsh", "C:\\bin\\clone.ps1" ] 21 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | 3 | FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS git 4 | SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] 5 | 6 | RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` 7 | Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` 8 | Expand-Archive git.zip -DestinationPath C:\git; 9 | 10 | FROM mcr.microsoft.com/powershell:nanoserver-ltsc2022 11 | COPY --from=git /git /git 12 | 13 | ADD windows/* /bin/ 14 | 15 | # https://github.com/PowerShell/PowerShell/issues/6211#issuecomment-367477137 16 | USER ContainerAdministrator 17 | RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell" 18 | 19 | SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] 20 | CMD [ "pwsh", "C:\\bin\\clone.ps1" ] 21 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: drone/git:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} 2 | {{#if build.tags}} 3 | tags: 4 | {{#each build.tags}} 5 | - {{this}} 6 | {{/each}} 7 | {{/if}} 8 | manifests: 9 | - 10 | image: drone/git:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 11 | platform: 12 | architecture: amd64 13 | os: linux 14 | - 15 | image: drone/git:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 16 | platform: 17 | variant: v8 18 | architecture: arm64 19 | os: linux 20 | - 21 | image: drone/git:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 22 | platform: 23 | architecture: amd64 24 | os: windows 25 | version: 1809 26 | - 27 | image: drone/git:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 28 | platform: 29 | architecture: amd64 30 | os: windows 31 | version: ltsc2022 -------------------------------------------------------------------------------- /posix/clone: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ -n "${DRONE_WORKSPACE}" ]]; then 4 | # ensure the unprivileged drone user can write 5 | # to the workspace. This is required because 6 | # the workspace is a docker volume and is owned 7 | # by root. 8 | # sudo mkdir -p ${DRONE_WORKSPACE} 9 | # sudo chown drone:drone ${DRONE_WORKSPACE} 10 | 11 | # ensure the workspace is the current working 12 | # directory. This should already be the case, 13 | # but we cd just to be safe. 14 | cd ${DRONE_WORKSPACE} 15 | fi 16 | 17 | # force the home directory path. 18 | 19 | # if [ "$HOME" != "/home/drone" ]; then 20 | # echo "[DEBUG] setting default home directory" 21 | # export HOME=/home/drone 22 | # fi 23 | 24 | # if the netrc enviornment variables exist, write 25 | # the netrc file. 26 | 27 | if [[ ! -z "${DRONE_NETRC_MACHINE}" ]]; then 28 | cat < ${HOME}/.netrc 29 | machine ${DRONE_NETRC_MACHINE} 30 | login ${DRONE_NETRC_USERNAME} 31 | password ${DRONE_NETRC_PASSWORD} 32 | EOF 33 | fi 34 | 35 | # if the ssh_key environment variable exists, write 36 | # the ssh key and add the netrc machine to the 37 | # known hosts file. 38 | 39 | if [[ ! -z "${DRONE_SSH_KEY}" ]]; then 40 | mkdir ${HOME}/.ssh 41 | echo -n "$DRONE_SSH_KEY" > ${HOME}/.ssh/id_rsa 42 | chmod 600 ${HOME}/.ssh/id_rsa 43 | 44 | touch ${HOME}/.ssh/known_hosts 45 | chmod 600 ${HOME}/.ssh/known_hosts 46 | ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null 47 | fi 48 | 49 | # AWS codecommit support using AWS access key & secret key 50 | # Refer: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-unixes.html 51 | 52 | if [[ ! -z "$DRONE_AWS_ACCESS_KEY" ]]; then 53 | aws configure set aws_access_key_id $DRONE_AWS_ACCESS_KEY 54 | aws configure set aws_secret_access_key $DRONE_AWS_SECRET_KEY 55 | aws configure set default.region $DRONE_AWS_REGION 56 | 57 | git config --global credential.helper '!aws codecommit credential-helper $@' 58 | git config --global credential.UseHttpPath true 59 | fi 60 | 61 | # configure git global behavior and parameters via the 62 | # following environment variables: 63 | 64 | 65 | if [[ -z "${DRONE_COMMIT_AUTHOR_NAME}" ]]; then 66 | export DRONE_COMMIT_AUTHOR_NAME=drone 67 | fi 68 | 69 | if [[ -z "${DRONE_COMMIT_AUTHOR_EMAIL}" ]]; then 70 | export DRONE_COMMIT_AUTHOR_EMAIL=drone@localhost 71 | fi 72 | 73 | export GIT_AUTHOR_NAME=${DRONE_COMMIT_AUTHOR_NAME} 74 | export GIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} 75 | export GIT_COMMITTER_NAME=${DRONE_COMMIT_AUTHOR_NAME} 76 | export GIT_COMMITTER_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} 77 | 78 | # invoke the sub-script based on the drone event type. 79 | # TODO we should ultimately look at the ref, since 80 | # we need something compatible with deployment events. 81 | 82 | CLONE_TYPE=$DRONE_BUILD_EVENT 83 | case $DRONE_COMMIT_REF in 84 | refs/tags/* ) CLONE_TYPE=tag ;; 85 | refs/pull/* ) CLONE_TYPE=pull_request ;; 86 | refs/pull-request/* ) CLONE_TYPE=pull_request ;; 87 | refs/merge-requests/* ) CLONE_TYPE=pull_request ;; 88 | esac 89 | 90 | git_clone_retry(){ 91 | retries="${PLUGIN_RETRIES:-0}" 92 | if [ -n "${retries##*[0-9]*}" ] || [ "${retries}" -lt 0 ]; then 93 | echo "PLUGIN_RETRIES defined but is not a number: ${retries}" >&2 94 | exit 1 95 | fi 96 | 97 | echo "Cloning with ${retries} retries" 98 | n=0 99 | until [ "$n" -gt "${retries}" ]; do 100 | $1 && return 101 | n=$((n+1)) 102 | done 103 | 104 | exit 1 105 | } 106 | 107 | case $CLONE_TYPE in 108 | pull_request) 109 | git_clone_retry clone-pull-request 110 | ;; 111 | tag) 112 | git_clone_retry clone-tag 113 | ;; 114 | *) 115 | git_clone_retry clone-commit 116 | ;; 117 | esac -------------------------------------------------------------------------------- /posix/clone-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FLAGS="" 4 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 5 | FLAGS="--depth=${PLUGIN_DEPTH}" 6 | fi 7 | 8 | if [ ! -d .git ]; then 9 | git init 10 | git remote add origin ${DRONE_REMOTE_URL} 11 | fi 12 | 13 | # the branch may be empty for certain event types, 14 | # such as github deployment events. If the branch 15 | # is empty we checkout the sha directly. Note that 16 | # we intentially omit depth flags to avoid failed 17 | # clones due to lack of history. 18 | if [[ -z "${DRONE_COMMIT_BRANCH}" ]]; then 19 | set -e 20 | set -x 21 | git fetch origin 22 | git checkout -qf ${DRONE_COMMIT_SHA} 23 | exit 0 24 | fi 25 | 26 | # the commit sha may be empty for builds that are 27 | # manually triggered in Harness CI Enterprise. If 28 | # the commit is empty we clone the branch. 29 | if [[ -z "${DRONE_COMMIT_SHA}" ]]; then 30 | set -e 31 | set -x 32 | git fetch ${FLAGS} origin +refs/heads/${DRONE_COMMIT_BRANCH}: 33 | git checkout -b ${DRONE_COMMIT_BRANCH} origin/${DRONE_COMMIT_BRANCH} 34 | exit 0 35 | fi 36 | 37 | set -e 38 | set -x 39 | 40 | git fetch ${FLAGS} origin +refs/heads/${DRONE_COMMIT_BRANCH}: 41 | git checkout ${DRONE_COMMIT_SHA} -b ${DRONE_COMMIT_BRANCH} 42 | -------------------------------------------------------------------------------- /posix/clone-pull-request: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FLAGS="" 4 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 5 | FLAGS="--depth=${PLUGIN_DEPTH}" 6 | fi 7 | 8 | if [ ! -d .git ]; then 9 | git init 10 | git remote add origin ${DRONE_REMOTE_URL} 11 | fi 12 | 13 | set -e 14 | set -x 15 | 16 | git fetch ${FLAGS} origin +refs/heads/${DRONE_COMMIT_BRANCH}: 17 | git checkout ${DRONE_COMMIT_BRANCH} 18 | 19 | git fetch origin ${DRONE_COMMIT_REF}: 20 | git merge ${DRONE_COMMIT_SHA} 21 | -------------------------------------------------------------------------------- /posix/clone-tag: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FLAGS="" 4 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 5 | FLAGS="--depth=${PLUGIN_DEPTH}" 6 | fi 7 | 8 | if [ ! -d .git ]; then 9 | git init 10 | git remote add origin ${DRONE_REMOTE_URL} 11 | fi 12 | 13 | set -e 14 | set -x 15 | 16 | git fetch ${FLAGS} origin +refs/tags/${DRONE_TAG}: 17 | git checkout -qf FETCH_HEAD 18 | -------------------------------------------------------------------------------- /posix/fixtures.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script creates a git repository and seeds with 4 | # commit history. Used by unit tests. 5 | 6 | set -e 7 | set -x 8 | 9 | rm -rf /tmp/remote/greeting 10 | mkdir -p /tmp/remote/greeting 11 | pushd /tmp/remote/greeting 12 | 13 | git init 14 | 15 | echo "hi world" > hello.txt 16 | git add hello.txt 17 | git commit -m "say hi" 18 | git tag v1.0.0 19 | 20 | echo "hello world" > hello.txt 21 | git add hello.txt 22 | git commit -m "say hello" 23 | git tag v1.1.0 24 | 25 | git checkout -b fr 26 | 27 | echo "salut monde" > hello.txt 28 | git add hello.txt 29 | git commit -m "say hello in french" 30 | git tag v2.0.0 31 | 32 | echo "bonjour monde" > hello.txt 33 | git add hello.txt 34 | git commit -m "say hello en francais" 35 | git tag v2.1.0 36 | 37 | git checkout master 38 | 39 | popd 40 | tar -cvf fixtures.tar /tmp/remote/greeting 41 | -------------------------------------------------------------------------------- /posix/fixtures.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone/drone-git/39d233b3d9eccc68e66508a06a725a2567f33143/posix/fixtures.tar -------------------------------------------------------------------------------- /posix/posix.go: -------------------------------------------------------------------------------- 1 | package posix 2 | 3 | //go:generate go run ../scripts/includetext.go --input=clone --input=clone-commit --input=clone-pull-request --input=clone-tag --package=posix --output=posix_gen.go 4 | -------------------------------------------------------------------------------- /posix/posix_gen.go: -------------------------------------------------------------------------------- 1 | package posix 2 | 3 | // DO NOT EDIT. This file is automatically generated. 4 | 5 | // Contents of clone 6 | const Clone = `#!/bin/sh 7 | 8 | if [[ ! -z "${DRONE_WORKSPACE}" ]]; then 9 | cd ${DRONE_WORKSPACE} 10 | fi 11 | 12 | # if the netrc enviornment variables exist, write 13 | # the netrc file. 14 | 15 | if [[ ! -z "${DRONE_NETRC_MACHINE}" ]]; then 16 | cat < /root/.netrc 17 | machine ${DRONE_NETRC_MACHINE} 18 | login ${DRONE_NETRC_USERNAME} 19 | password ${DRONE_NETRC_PASSWORD} 20 | EOF 21 | fi 22 | 23 | # if the ssh_key environment variable exists, write 24 | # the ssh key and add the netrc machine to the 25 | # known hosts file. 26 | 27 | if [[ ! -z "${SSH_KEY}" ]]; then 28 | mkdir /root/.ssh 29 | echo -n "$SSH_KEY" > /root/.ssh/id_rsa 30 | chmod 600 /root/.ssh/id_rsa 31 | 32 | touch /root/.ssh/known_hosts 33 | chmod 600 /root/.ssh/known_hosts 34 | ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null 35 | fi 36 | 37 | # configure git global behavior and parameters via the 38 | # following environment variables: 39 | 40 | 41 | if [[ -z "${DRONE_COMMIT_AUTHOR_NAME}" ]]; then 42 | export DRONE_COMMIT_AUTHOR_NAME=drone 43 | fi 44 | 45 | if [[ -z "${DRONE_COMMIT_AUTHOR_EMAIL}" ]]; then 46 | export DRONE_COMMIT_AUTHOR_EMAIL=drone@localhost 47 | fi 48 | 49 | export GIT_AUTHOR_NAME=${DRONE_COMMIT_AUTHOR_NAME} 50 | export GIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} 51 | export GIT_COMMITTER_NAME=${DRONE_COMMIT_AUTHOR_NAME} 52 | export GIT_COMMITTER_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} 53 | 54 | # invoke the sub-script based on the drone event type. 55 | # TODO we should ultimately look at the ref, since 56 | # we need something compatible with deployment events. 57 | 58 | CLONE_TYPE=$DRONE_BUILD_EVENT 59 | case $DRONE_COMMIT_REF in 60 | refs/tags/* ) CLONE_TYPE=tag ;; 61 | esac 62 | 63 | case $CLONE_TYPE in 64 | pull_request) 65 | clone-pull-request 66 | ;; 67 | tag) 68 | clone-tag 69 | ;; 70 | *) 71 | clone-commit 72 | ;; 73 | esac 74 | ` 75 | 76 | // Contents of clone-commit 77 | const CloneCommit = `#!/bin/sh 78 | 79 | FLAGS="" 80 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 81 | FLAGS="--depth=${PLUGIN_DEPTH}" 82 | fi 83 | 84 | if [ ! -d .git ]; then 85 | git init 86 | git remote add origin ${DRONE_REMOTE_URL} 87 | fi 88 | 89 | set -e 90 | set -x 91 | 92 | git fetch ${FLAGS} origin +refs/heads/${DRONE_COMMIT_BRANCH}: 93 | git checkout ${DRONE_COMMIT_SHA} -b ${DRONE_COMMIT_BRANCH} 94 | ` 95 | 96 | // Contents of clone-pull-request 97 | const ClonePullRequest = `#!/bin/sh 98 | 99 | FLAGS="" 100 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 101 | FLAGS="--depth=${PLUGIN_DEPTH}" 102 | fi 103 | 104 | if [ ! -d .git ]; then 105 | git init 106 | git remote add origin ${DRONE_REMOTE_URL} 107 | fi 108 | 109 | set -e 110 | set -x 111 | 112 | git fetch ${FLAGS} origin +refs/heads/${DRONE_COMMIT_BRANCH}: 113 | git checkout ${DRONE_COMMIT_BRANCH} 114 | 115 | git fetch origin ${DRONE_COMMIT_REF}: 116 | git merge ${DRONE_COMMIT_SHA} 117 | ` 118 | 119 | // Contents of clone-tag 120 | const CloneTag = `#!/bin/sh 121 | 122 | FLAGS="" 123 | if [[ ! -z "${PLUGIN_DEPTH}" ]]; then 124 | FLAGS="--depth=${PLUGIN_DEPTH}" 125 | fi 126 | 127 | if [ ! -d .git ]; then 128 | git init 129 | git remote add origin ${DRONE_REMOTE_URL} 130 | fi 131 | 132 | set -e 133 | set -x 134 | 135 | git fetch ${FLAGS} origin +refs/tags/${DRONE_TAG}: 136 | git checkout -qf FETCH_HEAD 137 | ` 138 | 139 | -------------------------------------------------------------------------------- /posix/posix_test.go: -------------------------------------------------------------------------------- 1 | package posix 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | "strings" 10 | "testing" 11 | ) 12 | 13 | func TestCommits(t *testing.T) { 14 | remote := "/tmp/remote/greeting" 15 | 16 | base, err := ioutil.TempDir("", "test") 17 | if err != nil { 18 | t.Error(err) 19 | return 20 | } 21 | defer os.Remove(base) 22 | 23 | for i, test := range tests { 24 | local := filepath.Join(base, fmt.Sprint(i)) 25 | err = os.MkdirAll(local, 0777) 26 | if err != nil { 27 | t.Error(err) 28 | return 29 | } 30 | 31 | bin, err := filepath.Abs("clone-commit") 32 | if err != nil { 33 | t.Error(err) 34 | return 35 | } 36 | 37 | cmd := exec.Command(bin) 38 | cmd.Dir = local 39 | cmd.Env = []string{ 40 | fmt.Sprintf("DRONE_COMMIT_BRANCH=%s", test.branch), 41 | fmt.Sprintf("DRONE_COMMIT_SHA=%s", test.commit), 42 | fmt.Sprintf("DRONE_WORKSPACE=%s", local), 43 | fmt.Sprintf("DRONE_REMOTE_URL=%s", remote), 44 | } 45 | 46 | out, err := cmd.CombinedOutput() 47 | if err != nil { 48 | t.Error(err) 49 | t.Log(string(out)) 50 | return 51 | } 52 | 53 | commit, err := getCommit(local) 54 | if err != nil { 55 | t.Error(err) 56 | return 57 | } 58 | 59 | branch, err := getBranch(local) 60 | if err != nil { 61 | t.Error(err) 62 | return 63 | } 64 | 65 | if want, got := test.commit, commit; got != want { 66 | t.Errorf("Want commit %s, got %s", want, got) 67 | } 68 | 69 | if want, got := test.branch, branch; got != want { 70 | t.Errorf("Want branch %s, got %s", want, got) 71 | } 72 | 73 | file := filepath.Join(local, test.file) 74 | out, err = ioutil.ReadFile(file) 75 | if err != nil { 76 | t.Error(err) 77 | return 78 | } 79 | 80 | if want, got := test.text, string(out); want != got { 81 | t.Errorf("Want file content %q, got %q", want, got) 82 | } 83 | } 84 | } 85 | 86 | func TestTags(t *testing.T) { 87 | remote := "/tmp/remote/greeting" 88 | 89 | base, err := ioutil.TempDir("", "test") 90 | if err != nil { 91 | t.Error(err) 92 | return 93 | } 94 | defer os.Remove(base) 95 | 96 | for i, test := range tests { 97 | local := filepath.Join(base, fmt.Sprint(i)) 98 | err = os.MkdirAll(local, 0777) 99 | if err != nil { 100 | t.Error(err) 101 | return 102 | } 103 | 104 | bin, err := filepath.Abs("clone-tag") 105 | if err != nil { 106 | t.Error(err) 107 | return 108 | } 109 | 110 | cmd := exec.Command(bin) 111 | cmd.Dir = local 112 | cmd.Env = []string{ 113 | fmt.Sprintf("DRONE_TAG=%s", test.tag), 114 | fmt.Sprintf("DRONE_COMMIT_SHA=%s", test.commit), 115 | fmt.Sprintf("DRONE_WORKSPACE=%s", local), 116 | fmt.Sprintf("DRONE_REMOTE_URL=%s", remote), 117 | } 118 | 119 | out, err := cmd.CombinedOutput() 120 | if err != nil { 121 | t.Error(err) 122 | t.Log(string(out)) 123 | return 124 | } 125 | 126 | commit, err := getCommit(local) 127 | if err != nil { 128 | t.Error(err) 129 | return 130 | } 131 | 132 | if want, got := test.commit, commit; got != want { 133 | t.Errorf("Want commit %s, got %s", want, got) 134 | } 135 | 136 | file := filepath.Join(local, test.file) 137 | out, err = ioutil.ReadFile(file) 138 | if err != nil { 139 | t.Error(err) 140 | return 141 | } 142 | 143 | if want, got := test.text, string(out); want != got { 144 | t.Errorf("Want file content %q, got %q", want, got) 145 | } 146 | } 147 | } 148 | 149 | func TestPullRequest(t *testing.T) { 150 | remote := "https://github.com/octocat/Spoon-Knife.git" 151 | 152 | local, err := ioutil.TempDir("", "test") 153 | if err != nil { 154 | t.Error(err) 155 | return 156 | } 157 | defer os.Remove(local) 158 | 159 | bin, err := filepath.Abs("clone-pull-request") 160 | if err != nil { 161 | t.Error(err) 162 | return 163 | } 164 | 165 | cmd := exec.Command(bin) 166 | cmd.Dir = local 167 | cmd.Env = []string{ 168 | fmt.Sprintf("DRONE_COMMIT_REF=%s", "refs/pull/14596/head"), 169 | fmt.Sprintf("DRONE_COMMIT_BRANCH=%s", "main"), 170 | fmt.Sprintf("DRONE_COMMIT_SHA=%s", "26923a8f37933ccc23943de0d4ebd53908268582"), 171 | fmt.Sprintf("DRONE_WORKSPACE=%s", local), 172 | fmt.Sprintf("DRONE_REMOTE_URL=%s", remote), 173 | } 174 | 175 | out, err := cmd.CombinedOutput() 176 | if err != nil { 177 | t.Error(err) 178 | t.Log(string(out)) 179 | return 180 | } 181 | 182 | commit, err := getCommit(local) 183 | if err != nil { 184 | t.Error(err) 185 | return 186 | } 187 | 188 | branch, err := getBranch(local) 189 | if err != nil { 190 | t.Error(err) 191 | return 192 | } 193 | 194 | if want, got := "26923a8f37933ccc23943de0d4ebd53908268582", commit; got != want { 195 | t.Errorf("Want commit %s, got %s", want, got) 196 | } 197 | 198 | if want, got := "main", branch; got != want { 199 | t.Errorf("Want branch %s, got %s", want, got) 200 | } 201 | 202 | file := filepath.Join(local, "directory/file.txt") 203 | out, err = ioutil.ReadFile(file) 204 | if err != nil { 205 | t.Error(err) 206 | return 207 | } 208 | } 209 | 210 | func getBranch(path string) (string, error) { 211 | cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") 212 | cmd.Dir = path 213 | out, err := cmd.CombinedOutput() 214 | return strings.TrimSpace(string(out)), err 215 | } 216 | 217 | func getCommit(path string) (string, error) { 218 | cmd := exec.Command("git", "rev-parse", "HEAD") 219 | cmd.Dir = path 220 | out, err := cmd.CombinedOutput() 221 | return strings.TrimSpace(string(out)), err 222 | } 223 | 224 | var tests = []struct { 225 | branch string 226 | commit string 227 | tag string 228 | file string 229 | text string 230 | }{ 231 | { 232 | commit: "9cd29dca0a98f76df94d66493ee54788a18190a0", 233 | branch: "master", 234 | tag: "v1.0.0", 235 | file: "hello.txt", 236 | text: "hi world\n", 237 | }, 238 | { 239 | commit: "bbdf5d4028a6066431f59fcd8d83afff610a55ae", 240 | branch: "master", 241 | tag: "v1.1.0", 242 | file: "hello.txt", 243 | text: "hello world\n", 244 | }, 245 | { 246 | commit: "553af1ca53c9ad54b096d7ff1416f6c4d1e5049f", 247 | branch: "fr", 248 | tag: "v2.0.0", 249 | file: "hello.txt", 250 | text: "salut monde\n", 251 | }, 252 | { 253 | commit: "94b4a1710d1581b8b00c5f7b077026eae3c07646", 254 | branch: "fr", 255 | tag: "v2.1.0", 256 | file: "hello.txt", 257 | text: "bonjour monde\n", 258 | }, 259 | } 260 | -------------------------------------------------------------------------------- /scripts/includetext.go: -------------------------------------------------------------------------------- 1 | // +build ignore 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "flag" 8 | "io/ioutil" 9 | "log" 10 | "path/filepath" 11 | "strings" 12 | "text/template" 13 | ) 14 | 15 | var ( 16 | input stringSlice 17 | output string 18 | name string 19 | ) 20 | 21 | func main() { 22 | flag.Var(&input, "input", "input files") 23 | flag.StringVar(&output, "output", "", "output file") 24 | flag.StringVar(&name, "package", "", "package name") 25 | flag.Parse() 26 | 27 | var files []File 28 | for _, file := range input { 29 | out, err := ioutil.ReadFile(file) 30 | if err != nil { 31 | log.Fatalln(err) 32 | } 33 | files = append(files, File{ 34 | Name: file, 35 | Slug: slugify(file), 36 | Data: string(out), 37 | }) 38 | } 39 | 40 | data := map[string]interface{}{ 41 | "Files": files, 42 | "Package": name, 43 | } 44 | buf := new(bytes.Buffer) 45 | err := tmpl.Execute(buf, data) 46 | if err != nil { 47 | log.Fatalln(err) 48 | } 49 | 50 | ioutil.WriteFile(output, buf.Bytes(), 0644) 51 | } 52 | 53 | func slugify(s string) string { 54 | ext := filepath.Ext(s) 55 | s = strings.TrimSuffix(s, ext) 56 | s = strings.Title(s) 57 | s = strings.ReplaceAll(s, "-", "") 58 | s = strings.ReplaceAll(s, "_", "") 59 | return s 60 | } 61 | 62 | type stringSlice []string 63 | 64 | func (s *stringSlice) String() string { 65 | return strings.Join(*s, ",") 66 | } 67 | 68 | func (s *stringSlice) Set(value string) error { 69 | *s = append(*s, value) 70 | return nil 71 | } 72 | 73 | type File struct { 74 | Name string 75 | Data string 76 | Slug string 77 | } 78 | 79 | var tmpl = template.Must(template.New("_").Parse(`package {{ .Package }} 80 | 81 | // DO NOT EDIT. This file is automatically generated. 82 | 83 | {{ range .Files -}} 84 | // Contents of {{ .Name }} 85 | const {{ .Slug }} = ` + "`{{ .Data }}`" + ` 86 | 87 | {{ end -}}`)) 88 | -------------------------------------------------------------------------------- /windows/clone-commit.ps1: -------------------------------------------------------------------------------- 1 | 2 | Set-Variable -Name "FLAGS" -Value "" 3 | if ($Env:PLUGIN_DEPTH) { 4 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 5 | } 6 | 7 | if (!(Test-Path .git)) { 8 | Write-Host 'git init'; 9 | git init 10 | Write-Host "git remote add origin $Env:DRONE_REMOTE_URL" 11 | git remote add origin $Env:DRONE_REMOTE_URL 12 | } 13 | 14 | Write-Host "git fetch $FLAGS origin +refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; 15 | git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; 16 | Write-Host "git checkout $Env:DRONE_COMMIT_SHA -f $Env:DRONE_COMMIT_BRANCH"; 17 | git checkout $Env:DRONE_COMMIT_SHA -b $Env:DRONE_COMMIT_BRANCH; 18 | -------------------------------------------------------------------------------- /windows/clone-pull-request.ps1: -------------------------------------------------------------------------------- 1 | 2 | Set-Variable -Name "FLAGS" -Value "" 3 | if ($Env:PLUGIN_DEPTH) { 4 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 5 | } 6 | 7 | if (!(Test-Path .git)) { 8 | git init 9 | git remote add origin $Env:DRONE_REMOTE_URL 10 | } 11 | 12 | git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:" 13 | git checkout $Env:DRONE_COMMIT_BRANCH 14 | 15 | git fetch origin "${Env:DRONE_COMMIT_REF}:" 16 | git merge $Env:DRONE_COMMIT_SHA 17 | -------------------------------------------------------------------------------- /windows/clone-tag.ps1: -------------------------------------------------------------------------------- 1 | 2 | Set-Variable -Name "FLAGS" -Value "" 3 | if ($Env:PLUGIN_DEPTH) { 4 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 5 | } 6 | 7 | if (!(Test-Path .git)) { 8 | git init 9 | git remote add origin $Env:DRONE_REMOTE_URL 10 | } 11 | 12 | git fetch $FLAGS origin "+refs/tags/${Env:DRONE_TAG}:" 13 | git checkout -qf FETCH_HEAD 14 | -------------------------------------------------------------------------------- /windows/clone.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop'; 2 | 3 | # HACK: no clue how to set the PATH inside the Dockerfile, 4 | # so am setting it here instead. This is not idea. 5 | $Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin' 6 | 7 | # if the workspace is set we should make sure 8 | # it is the current working directory. 9 | 10 | if ($Env:DRONE_WORKSPACE) { 11 | cd $Env:DRONE_WORKSPACE 12 | } 13 | 14 | # if the netrc enviornment variables exist, write 15 | # the netrc file. 16 | 17 | if ($Env:DRONE_NETRC_MACHINE) { 18 | @" 19 | machine $Env:DRONE_NETRC_MACHINE 20 | login $Env:DRONE_NETRC_USERNAME 21 | password $Env:DRONE_NETRC_PASSWORD 22 | "@ > (Join-Path $Env:USERPROFILE '_netrc'); 23 | } 24 | 25 | # configure git global behavior and parameters via the 26 | # following environment variables: 27 | 28 | if ($Env:PLUGIN_SKIP_VERIFY) { 29 | $Env:GIT_SSL_NO_VERIFY = "true" 30 | } 31 | 32 | if ($Env:DRONE_COMMIT_AUTHOR_NAME -eq '' -or $Env:DRONE_COMMIT_AUTHOR_NAME -eq $null) { 33 | $Env:GIT_AUTHOR_NAME = "drone" 34 | } else { 35 | $Env:GIT_AUTHOR_NAME = $Env:DRONE_COMMIT_AUTHOR_NAME 36 | } 37 | 38 | if ($Env:DRONE_COMMIT_AUTHOR_EMAIL -eq '' -or $Env:DRONE_COMMIT_AUTHOR_EMAIL -eq $null) { 39 | $Env:GIT_AUTHOR_EMAIL = 'drone@localhost' 40 | } else { 41 | $Env:GIT_AUTHOR_EMAIL = $Env:DRONE_COMMIT_AUTHOR_EMAIL 42 | } 43 | 44 | $Env:GIT_COMMITTER_NAME = $Env:GIT_AUTHOR_NAME 45 | $Env:GIT_COMMITTER_EMAIL = $Env:GIT_AUTHOR_EMAIL 46 | 47 | # invoke the sub-script based on the drone event type. 48 | # TODO we should ultimately look at the ref, since 49 | # we need something compatible with deployment events. 50 | 51 | switch ($Env:DRONE_BUILD_EVENT) { 52 | "pull_request" { 53 | Invoke-Expression "${PSScriptRoot}\clone-pull-request.ps1" 54 | break 55 | } 56 | "tag" { 57 | Invoke-Expression "${PSScriptRoot}\clone-tag.ps1" 58 | break 59 | } 60 | default { 61 | Invoke-Expression "${PSScriptRoot}\clone-commit.ps1" 62 | break 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /windows/windows.go: -------------------------------------------------------------------------------- 1 | package windows 2 | 3 | //go:generate go run ../scripts/includetext.go --input=clone.ps1 --input=clone-commit.ps1 --input=clone-pull-request.ps1 --input=clone-tag.ps1 --package=windows --output=windows_gen.go 4 | -------------------------------------------------------------------------------- /windows/windows_gen.go: -------------------------------------------------------------------------------- 1 | package windows 2 | 3 | // DO NOT EDIT. This file is automatically generated. 4 | 5 | // Contents of clone.ps1 6 | const Clone = `$ErrorActionPreference = 'Stop'; 7 | 8 | # HACK: no clue how to set the PATH inside the Dockerfile, 9 | # so am setting it here instead. This is not idea. 10 | $Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin' 11 | 12 | # if the workspace is set we should make sure 13 | # it is the current working directory. 14 | 15 | if ($Env:DRONE_WORKSPACE) { 16 | cd $Env:DRONE_WORKSPACE 17 | } 18 | 19 | # if the netrc enviornment variables exist, write 20 | # the netrc file. 21 | 22 | if ($Env:DRONE_NETRC_MACHINE) { 23 | @" 24 | machine $Env:DRONE_NETRC_MACHINE 25 | login $Env:DRONE_NETRC_USERNAME 26 | password $Env:DRONE_NETRC_PASSWORD 27 | "@ > (Join-Path $Env:USERPROFILE '_netrc'); 28 | } 29 | 30 | # configure git global behavior and parameters via the 31 | # following environment variables: 32 | 33 | if ($Env:PLUGIN_SKIP_VERIFY) { 34 | $Env:GIT_SSL_NO_VERIFY = "true" 35 | } 36 | 37 | if ($Env:DRONE_COMMIT_AUTHOR_NAME -eq '' -or $Env:DRONE_COMMIT_AUTHOR_NAME -eq $null) { 38 | $Env:GIT_AUTHOR_NAME = "drone" 39 | } else { 40 | $Env:GIT_AUTHOR_NAME = $Env:DRONE_COMMIT_AUTHOR_NAME 41 | } 42 | 43 | if ($Env:DRONE_COMMIT_AUTHOR_EMAIL -eq '' -or $Env:DRONE_COMMIT_AUTHOR_EMAIL -eq $null) { 44 | $Env:GIT_AUTHOR_EMAIL = 'drone@localhost' 45 | } else { 46 | $Env:GIT_AUTHOR_EMAIL = $Env:DRONE_COMMIT_AUTHOR_EMAIL 47 | } 48 | 49 | $Env:GIT_COMMITTER_NAME = $Env:GIT_AUTHOR_NAME 50 | $Env:GIT_COMMITTER_EMAIL = $Env:GIT_AUTHOR_EMAIL 51 | 52 | # invoke the sub-script based on the drone event type. 53 | # TODO we should ultimately look at the ref, since 54 | # we need something compatible with deployment events. 55 | 56 | switch ($Env:DRONE_BUILD_EVENT) { 57 | "pull_request" { 58 | Invoke-Expression "${PSScriptRoot}\clone-pull-request.ps1" 59 | break 60 | } 61 | "tag" { 62 | Invoke-Expression "${PSScriptRoot}\clone-tag.ps1" 63 | break 64 | } 65 | default { 66 | Invoke-Expression "${PSScriptRoot}\clone-commit.ps1" 67 | break 68 | } 69 | } 70 | ` 71 | 72 | // Contents of clone-commit.ps1 73 | const CloneCommit = ` 74 | Set-Variable -Name "FLAGS" -Value "" 75 | if ($Env:PLUGIN_DEPTH) { 76 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 77 | } 78 | 79 | if (!(Test-Path .git)) { 80 | Write-Host 'git init'; 81 | git init 82 | Write-Host "git remote add origin $Env:DRONE_REMOTE_URL" 83 | git remote add origin $Env:DRONE_REMOTE_URL 84 | } 85 | 86 | Write-Host "git fetch $FLAGS origin +refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; 87 | git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; 88 | Write-Host "git checkout $Env:DRONE_COMMIT_SHA -f $Env:DRONE_COMMIT_BRANCH"; 89 | git checkout $Env:DRONE_COMMIT_SHA -b $Env:DRONE_COMMIT_BRANCH; 90 | ` 91 | 92 | // Contents of clone-pull-request.ps1 93 | const ClonePullRequest = ` 94 | Set-Variable -Name "FLAGS" -Value "" 95 | if ($Env:PLUGIN_DEPTH) { 96 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 97 | } 98 | 99 | if (!(Test-Path .git)) { 100 | git init 101 | git remote add origin $Env:DRONE_REMOTE_URL 102 | } 103 | 104 | git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:" 105 | git checkout $Env:DRONE_COMMIT_BRANCH 106 | 107 | git fetch origin "${Env:DRONE_COMMIT_REF}:" 108 | git merge $Env:DRONE_COMMIT_SHA 109 | ` 110 | 111 | // Contents of clone-tag.ps1 112 | const CloneTag = ` 113 | Set-Variable -Name "FLAGS" -Value "" 114 | if ($Env:PLUGIN_DEPTH) { 115 | Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" 116 | } 117 | 118 | if (!(Test-Path .git)) { 119 | git init 120 | git remote add origin $Env:DRONE_REMOTE_URL 121 | } 122 | 123 | git fetch $FLAGS origin "+refs/tags/${Env:DRONE_TAG}:" 124 | git checkout -qf FETCH_HEAD 125 | ` 126 | 127 | --------------------------------------------------------------------------------