mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-14 05:12:37 +08:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a9a5789cc | |||
| 38fe651776 | |||
| 2679e1a33b | |||
| 12827c56e5 | |||
| 9f8137bea7 | |||
| 2decbc4a77 | |||
| 7468610684 | |||
| 79beba5443 | |||
| 716cc7189b | |||
| 052d6e71bc | |||
| 13819778ab | |||
| e61e2409d3 | |||
| 0601816b74 | |||
| 13c4ec4609 | |||
| 87c72235a8 | |||
| fe4a745be0 | |||
| 45ef1287c2 | |||
| 9a56c98766 | |||
| c1ebb32673 | |||
| 4a7fa1bdff | |||
| 6bb71c761c | |||
| bb91fba471 | |||
| 86f19b9c1c | |||
| 691ddecf48 | |||
| a9c0fd3bbd | |||
| 7df424cbf1 | |||
| e5bd02fd8e | |||
| 7e0d4951b9 | |||
| ac6c465050 | |||
| 754c91fc38 | |||
| bb2dd5543b | |||
| 8b963288b3 | |||
| bd2ddc2b6c | |||
| d098811ced | |||
| de6f344960 | |||
| cf87fecefa | |||
| 665c665298 |
@@ -13,12 +13,12 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '41 23 * * 6'
|
- cron: "41 23 * * 6"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
@@ -32,23 +32,23 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
language: [ 'go' ]
|
language: ["go"]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
# By default, queries listed here will override any specified in a config file.
|
# By default, queries listed here will override any specified in a config file.
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v3
|
||||||
|
|||||||
@@ -5,56 +5,51 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- "v*"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- "master"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-docker:
|
build-docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '^1'
|
go-version: "^1"
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
run : |
|
run: |
|
||||||
make build_linux_amd64
|
make build_linux_amd64
|
||||||
make build_linux_arm
|
|
||||||
make build_linux_arm64
|
make build_linux_arm64
|
||||||
-
|
|
||||||
name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
|
|
||||||
-
|
- name: Set up QEMU
|
||||||
name: Set up Docker Buildx
|
uses: docker/setup-qemu-action@v3
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
-
|
- name: Set up Docker Buildx
|
||||||
name: Login to Docker Hub
|
uses: docker/setup-buildx-action@v3
|
||||||
uses: docker/login-action@v2
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
-
|
- name: Login to GitHub Container Registry
|
||||||
name: Login to GitHub Container Registry
|
uses: docker/login-action@v3
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
-
|
- name: Docker meta
|
||||||
name: Docker meta
|
|
||||||
id: docker-meta
|
id: docker-meta
|
||||||
uses: docker/metadata-action@v4
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
${{ github.repository }}
|
${{ github.repository }}
|
||||||
@@ -65,13 +60,14 @@ jobs:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
-
|
- name: Build and push
|
||||||
name: Build and push
|
uses: docker/build-push-action@v6
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
file: docker/Dockerfile
|
file: docker/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.docker-meta.outputs.tags }}
|
tags: ${{ steps.docker-meta.outputs.tags }}
|
||||||
labels: ${{ steps.docker-meta.outputs.labels }}
|
labels: ${{ steps.docker-meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
|
||||||
|
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ name: Goreleaser
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- "*"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -12,24 +12,21 @@ jobs:
|
|||||||
goreleaser:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
-
|
- name: Setup go
|
||||||
name: Setup go
|
uses: actions/setup-go@v5
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
with:
|
||||||
go-version: '^1'
|
go-version: "^1"
|
||||||
|
|
||||||
-
|
- name: Run GoReleaser
|
||||||
name: Run GoReleaser
|
uses: goreleaser/goreleaser-action@v6
|
||||||
uses: goreleaser/goreleaser-action@v4
|
|
||||||
with:
|
with:
|
||||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
args: release --rm-dist
|
args: release --clean
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: '^1'
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
- name: Setup golangci-lint
|
- name: Setup golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v6
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: --verbose
|
args: --verbose
|
||||||
@@ -27,10 +30,10 @@ jobs:
|
|||||||
|
|
||||||
testing:
|
testing:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: golang:1.20-alpine
|
container: golang:1.22-alpine
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: setup sshd server
|
- name: setup sshd server
|
||||||
run: |
|
run: |
|
||||||
@@ -42,4 +45,4 @@ jobs:
|
|||||||
make test
|
make test
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v4
|
||||||
|
|||||||
@@ -28,3 +28,5 @@ coverage.txt
|
|||||||
dist
|
dist
|
||||||
.cover
|
.cover
|
||||||
release
|
release
|
||||||
|
bin
|
||||||
|
.idea
|
||||||
|
|||||||
+108
-69
@@ -3,74 +3,78 @@ before:
|
|||||||
- go mod tidy
|
- go mod tidy
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
- env:
|
- env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
- linux
|
- linux
|
||||||
- windows
|
- windows
|
||||||
- freebsd
|
- freebsd
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- arm
|
- arm
|
||||||
- arm64
|
- arm64
|
||||||
goarm:
|
goarm:
|
||||||
- "5"
|
- "5"
|
||||||
- "6"
|
- "6"
|
||||||
- "7"
|
- "7"
|
||||||
ignore:
|
ignore:
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: arm
|
goarch: arm
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: ppc64le
|
goarch: ppc64le
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: s390x
|
goarch: s390x
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: ppc64le
|
goarch: ppc64le
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: s390x
|
goarch: s390x
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "5"
|
goarm: "5"
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "6"
|
goarm: "6"
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "7"
|
goarm: "7"
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: ppc64le
|
goarch: ppc64le
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: s390x
|
goarch: s390x
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "5"
|
goarm: "5"
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "6"
|
goarm: "6"
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: "7"
|
goarm: "7"
|
||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
flags:
|
flags:
|
||||||
- -trimpath
|
- -trimpath
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w
|
- -s -w
|
||||||
- -X main.Version={{.Version}}
|
- -X main.Version={{.Version}}
|
||||||
binary: >-
|
binary: >-
|
||||||
{{ .ProjectName }}-
|
{{ .ProjectName }}-
|
||||||
{{- if .IsSnapshot }}{{ .Branch }}-
|
{{- if .IsSnapshot }}{{ .Branch }}-
|
||||||
{{- else }}{{- .Version }}-{{ end }}
|
{{- else }}{{- .Version }}-{{ end }}
|
||||||
{{- .Os }}-
|
{{- .Os }}-
|
||||||
{{- if eq .Arch "amd64" }}amd64
|
{{- if eq .Arch "amd64" }}amd64
|
||||||
{{- else if eq .Arch "amd64_v1" }}amd64
|
{{- else if eq .Arch "amd64_v1" }}amd64
|
||||||
{{- else if eq .Arch "386" }}386
|
{{- else if eq .Arch "386" }}386
|
||||||
{{- else }}{{ .Arch }}{{ end }}
|
{{- else }}{{ .Arch }}{{ end }}
|
||||||
{{- if .Arm }}-{{ .Arm }}{{ end }}
|
{{- if .Arm }}-{{ .Arm }}{{ end }}
|
||||||
no_unique_dist_dir: true
|
no_unique_dist_dir: true
|
||||||
|
hooks:
|
||||||
|
post:
|
||||||
|
- cmd: xz -k -9 {{ .Path }}
|
||||||
|
dir: ./dist/
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: binary
|
- format: binary
|
||||||
@@ -78,7 +82,42 @@ archives:
|
|||||||
allow_different_binary_count: true
|
allow_different_binary_count: true
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: "checksums.txt"
|
||||||
|
extra_files:
|
||||||
|
- glob: ./**.xz
|
||||||
|
|
||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ incpatch .Version }}"
|
name_template: "{{ incpatch .Version }}"
|
||||||
|
|
||||||
|
release:
|
||||||
|
# You can add extra pre-existing files to the release.
|
||||||
|
# The filename on the release will be the last part of the path (base).
|
||||||
|
# If another file with the same name exists, the last one found will be used.
|
||||||
|
#
|
||||||
|
# Templates: allowed
|
||||||
|
extra_files:
|
||||||
|
- glob: ./**.xz
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
use: github
|
||||||
|
groups:
|
||||||
|
- title: Features
|
||||||
|
regexp: "^.*feat[(\\w)]*:+.*$"
|
||||||
|
order: 0
|
||||||
|
- title: "Bug fixes"
|
||||||
|
regexp: "^.*fix[(\\w)]*:+.*$"
|
||||||
|
order: 1
|
||||||
|
- title: "Enhancements"
|
||||||
|
regexp: "^.*chore[(\\w)]*:+.*$"
|
||||||
|
order: 2
|
||||||
|
- title: "Refactor"
|
||||||
|
regexp: "^.*refactor[(\\w)]*:+.*$"
|
||||||
|
order: 3
|
||||||
|
- title: "Build process updates"
|
||||||
|
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
|
||||||
|
order: 4
|
||||||
|
- title: "Documentation updates"
|
||||||
|
regexp: ^.*?docs?(\(.+\))??!?:.+$
|
||||||
|
order: 4
|
||||||
|
- title: Others
|
||||||
|
order: 999
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
ignored:
|
||||||
|
- DL3018
|
||||||
|
- DL3008
|
||||||
@@ -1,19 +1,8 @@
|
|||||||
DIST := dist
|
|
||||||
EXECUTABLE := drone-scp
|
EXECUTABLE := drone-scp
|
||||||
GOFMT ?= gofumpt -l
|
GOFMT ?= gofumpt -l -s -w
|
||||||
DIST := dist
|
|
||||||
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
|
||||||
GO ?= go
|
GO ?= go
|
||||||
SHASUM ?= shasum -a 256
|
|
||||||
GOFILES := $(shell find . -name "*.go" -type f)
|
GOFILES := $(shell find . -name "*.go" -type f)
|
||||||
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
|
||||||
XGO_VERSION := go-1.19.x
|
|
||||||
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
|
|
||||||
|
|
||||||
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
|
||||||
DARWIN_ARCHS ?= darwin-10.12/amd64,darwin-10.12/arm64
|
|
||||||
WINDOWS_ARCHS ?= windows/*
|
|
||||||
|
|
||||||
ifneq ($(shell uname), Darwin)
|
ifneq ($(shell uname), Darwin)
|
||||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||||
@@ -81,7 +70,7 @@ install: $(GOFILES)
|
|||||||
build: $(EXECUTABLE)
|
build: $(EXECUTABLE)
|
||||||
|
|
||||||
$(EXECUTABLE): $(GOFILES)
|
$(EXECUTABLE): $(GOFILES)
|
||||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
||||||
|
|
||||||
build_linux_amd64:
|
build_linux_amd64:
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
||||||
@@ -108,56 +97,13 @@ ssh-server:
|
|||||||
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
|
rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
|
||||||
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||||
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
|
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
|
||||||
|
sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/g' /etc/ssh/sshd_config
|
||||||
|
sed -i 's/^#ListenAddress ::/ListenAddress ::/g' /etc/ssh/sshd_config
|
||||||
./tests/entrypoint.sh /usr/sbin/sshd -D &
|
./tests/entrypoint.sh /usr/sbin/sshd -D &
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
sed -i '/main.go/d' coverage.txt
|
sed -i '/main.go/d' coverage.txt
|
||||||
|
|
||||||
.PHONY: deps-backend
|
|
||||||
deps-backend:
|
|
||||||
$(GO) mod download
|
|
||||||
$(GO) install $(GXZ_PAGAGE)
|
|
||||||
$(GO) install $(XGO_PACKAGE)
|
|
||||||
|
|
||||||
.PHONY: release
|
|
||||||
release: release-linux release-darwin release-windows release-copy release-compress release-check
|
|
||||||
|
|
||||||
$(DIST_DIRS):
|
|
||||||
mkdir -p $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: release-windows
|
|
||||||
release-windows: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-linux
|
|
||||||
release-linux: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-darwin
|
|
||||||
release-darwin: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-copy
|
|
||||||
release-copy: | $(DIST_DIRS)
|
|
||||||
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
|
|
||||||
|
|
||||||
.PHONY: release-check
|
|
||||||
release-check: | $(DIST_DIRS)
|
|
||||||
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
|
||||||
|
|
||||||
.PHONY: release-compress
|
|
||||||
release-compress: | $(DIST_DIRS)
|
|
||||||
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PAGAGE) -k -9 $${file}; done;
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(GO) clean -x -i ./...
|
$(GO) clean -x -i ./...
|
||||||
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
||||||
|
|||||||
+10
-3
@@ -1,22 +1,29 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
// This function returns the appropriate command for removing a file/directory based on the operating system.
|
||||||
func rmcmd(os, target string) string {
|
func rmcmd(os, target string) string {
|
||||||
switch os {
|
switch os {
|
||||||
case "windows":
|
case "windows":
|
||||||
|
// On Windows, use DEL command to delete files and folders recursively
|
||||||
return "DEL /F /S " + target
|
return "DEL /F /S " + target
|
||||||
case "unix":
|
case "unix":
|
||||||
return "rm -rf '" + target + "'"
|
// On Unix-based systems, use rm command to delete files and folders recursively
|
||||||
|
return "rm -rf " + target
|
||||||
}
|
}
|
||||||
|
// Return an empty string if the operating system is not recognized
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function returns the appropriate command for creating a directory based on the operating system.
|
||||||
func mkdircmd(os, target string) string {
|
func mkdircmd(os, target string) string {
|
||||||
switch os {
|
switch os {
|
||||||
case "windows":
|
case "windows":
|
||||||
|
// On Windows, use mkdir command to create directory and check if it exists
|
||||||
return "if not exist " + target + " mkdir " + target
|
return "if not exist " + target + " mkdir " + target
|
||||||
case "unix":
|
case "unix":
|
||||||
return "mkdir -p '" + target + "'"
|
// On Unix-based systems, use mkdir command with -p option to create directories recursively
|
||||||
|
return "mkdir -p " + target
|
||||||
}
|
}
|
||||||
|
// Return an empty string if the operating system is not recognized
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// Unit tests for rmcmd and mkdircmd
|
||||||
|
func TestCommands(t *testing.T) {
|
||||||
|
// Test rmcmd on Windows
|
||||||
|
os1 := "windows"
|
||||||
|
target1 := "C:\\path\\to\\file"
|
||||||
|
expected1 := "DEL /F /S " + target1
|
||||||
|
actual1 := rmcmd(os1, target1)
|
||||||
|
if actual1 != expected1 {
|
||||||
|
t.Errorf("rmcmd(%s, %s) = %s; expected %s", os1, target1, actual1, expected1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test rmcmd on Unix-based system
|
||||||
|
os2 := "unix"
|
||||||
|
target2 := "/path/to/folder"
|
||||||
|
expected2 := "rm -rf " + target2
|
||||||
|
actual2 := rmcmd(os2, target2)
|
||||||
|
if actual2 != expected2 {
|
||||||
|
t.Errorf("rmcmd(%s, %s) = %s; expected %s", os2, target2, actual2, expected2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test mkdircmd on Windows
|
||||||
|
os3 := "windows"
|
||||||
|
target3 := "C:\\path\\to\\folder"
|
||||||
|
expected3 := "if not exist " + target3 + " mkdir " + target3
|
||||||
|
actual3 := mkdircmd(os3, target3)
|
||||||
|
if actual3 != expected3 {
|
||||||
|
t.Errorf("mkdircmd(%s, %s) = %s; expected %s", os3, target3, actual3, expected3)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test mkdircmd on Unix-based system
|
||||||
|
os4 := "unix"
|
||||||
|
target4 := "/path/to/folder"
|
||||||
|
expected4 := "mkdir -p " + target4
|
||||||
|
actual4 := mkdircmd(os4, target4)
|
||||||
|
if actual4 != expected4 {
|
||||||
|
t.Errorf("mkdircmd(%s, %s) = %s; expected %s", os4, target4, actual4, expected4)
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-5
@@ -3,18 +3,32 @@ FROM alpine:3.17
|
|||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
|
||||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
||||||
org.label-schema.name="SCP Plugin" \
|
|
||||||
org.label-schema.vendor="Bo-Yi Wu" \
|
|
||||||
org.label-schema.schema-version="1.0"
|
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-scp
|
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-scp
|
||||||
LABEL org.opencontainers.image.description="Copy files and artifacts via SSH"
|
LABEL org.opencontainers.image.description="Copy files and artifacts via SSH"
|
||||||
LABEL org.opencontainers.image.licenses=MIT
|
LABEL org.opencontainers.image.licenses=MIT
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates=20220614-r4 && \
|
RUN apk add --no-cache ca-certificates && \
|
||||||
rm -rf /var/cache/apk/*
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
RUN addgroup \
|
||||||
|
-S -g 1000 \
|
||||||
|
deploy && \
|
||||||
|
adduser \
|
||||||
|
-S -H -D \
|
||||||
|
-h /home/deploy \
|
||||||
|
-s /bin/sh \
|
||||||
|
-u 1000 \
|
||||||
|
-G deploy \
|
||||||
|
deploy
|
||||||
|
|
||||||
|
RUN mkdir -p /home/deploy && \
|
||||||
|
chown deploy:deploy /home/deploy
|
||||||
|
|
||||||
|
# deploy:deploy
|
||||||
|
USER 1000:1000
|
||||||
|
|
||||||
COPY release/${TARGETOS}/${TARGETARCH}/drone-scp /bin/
|
COPY release/${TARGETOS}/${TARGETARCH}/drone-scp /bin/
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/drone-scp"]
|
ENTRYPOINT ["/bin/drone-scp"]
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
module github.com/appleboy/drone-scp
|
module github.com/appleboy/drone-scp
|
||||||
|
|
||||||
go 1.18
|
go 1.22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/appleboy/com v0.1.7
|
github.com/appleboy/com v0.2.0
|
||||||
github.com/appleboy/easyssh-proxy v1.3.10
|
github.com/appleboy/easyssh-proxy v1.5.0
|
||||||
github.com/fatih/color v1.15.0
|
github.com/fatih/color v1.18.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/urfave/cli/v2 v2.25.1
|
github.com/urfave/cli/v2 v2.27.5
|
||||||
golang.org/x/crypto v0.8.0
|
golang.org/x/crypto v0.28.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ScaleFT/sshkeys v1.2.0 // indirect
|
github.com/ScaleFT/sshkeys v1.2.0 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
golang.org/x/sys v0.7.0 // indirect
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,58 +1,54 @@
|
|||||||
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
|
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
|
||||||
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
|
||||||
github.com/appleboy/com v0.1.7 h1:4lYTFNoMAAXGGIC8lDxVg/NY+1aXbYqfAWN05cZhd0M=
|
github.com/appleboy/com v0.2.0 h1:0sggtDLRzh9eP8wATOTvbYzjulufRI+vuLbxJilgyHI=
|
||||||
github.com/appleboy/com v0.1.7/go.mod h1:JUK+oH0SXCLRH57pDMJx6VWVsm8CPdajalmRSWwamBE=
|
github.com/appleboy/com v0.2.0/go.mod h1:xlUTmT+fAy+HeLWdWX/saBEMbmkQzaVAqB1xC70Oys4=
|
||||||
github.com/appleboy/easyssh-proxy v1.3.10 h1:iriF68tlrYoxgWhS7t7Wyr0FA+hJlOem5tMfm+RDlx4=
|
github.com/appleboy/easyssh-proxy v1.5.0 h1:OYdSPvYQN3mhnsMH5I2OF1TgwSEcSq33kvjQfTwvZww=
|
||||||
github.com/appleboy/easyssh-proxy v1.3.10/go.mod h1:T81pu/Cxx/zf/7YXhFCFiucBa4xeQ81ci5b0PFnMRJc=
|
github.com/appleboy/easyssh-proxy v1.5.0/go.mod h1:zcEMrStH91/tcUn3gUGP0KpQwUYLm8tX/Ook1AH98uc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
|
||||||
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
|
||||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
|
||||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||||
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||||
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
|
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||||
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
|
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||||
|
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/appleboy/easyssh-proxy"
|
"github.com/appleboy/easyssh-proxy"
|
||||||
@@ -21,10 +22,14 @@ func main() {
|
|||||||
_ = godotenv.Load(filename)
|
_ = godotenv.Load(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||||
|
_ = godotenv.Overload("/run/drone/env")
|
||||||
|
}
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Drone SCP"
|
app.Name = "Drone SCP"
|
||||||
app.Usage = "Copy files and artifacts via SSH."
|
app.Usage = "Copy files and artifacts via SSH."
|
||||||
app.Copyright = "Copyright (c) 2020 Bo-Yi Wu"
|
app.Copyright = "Copyright (c) " + strconv.Itoa(time.Now().Year()) + " Bo-Yi Wu"
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Authors = []*cli.Author{
|
app.Authors = []*cli.Author{
|
||||||
{
|
{
|
||||||
@@ -49,6 +54,12 @@ func main() {
|
|||||||
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
|
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
|
||||||
Value: 22,
|
Value: 22,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "protocol",
|
||||||
|
Usage: "The IP protocol to use. Valid values are \"tcp\". \"tcp4\" or \"tcp6\". Default to tcp.",
|
||||||
|
EnvVars: []string{"PLUGIN_PROTOCOL", "SSH_PROTOCOL", "INPUT_PROTOCOL"},
|
||||||
|
Value: "tcp",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "username",
|
Name: "username",
|
||||||
Aliases: []string{"user", "u"},
|
Aliases: []string{"user", "u"},
|
||||||
@@ -134,6 +145,12 @@ func main() {
|
|||||||
EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "INPUT_PROXY_PORT"},
|
EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "INPUT_PROXY_PORT"},
|
||||||
Value: "22",
|
Value: "22",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "proxy.protocol",
|
||||||
|
Usage: "The IP protocol to use for the proxy. Valid values are \"tcp\". \"tcp4\" or \"tcp6\". Default to tcp.",
|
||||||
|
EnvVars: []string{"PLUGIN_PROXY_PROTOCOL", "SSH_PROXY_PROTOCOL", "INPUT_PROXY_PROTOCOL"},
|
||||||
|
Value: "tcp",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "proxy.username",
|
Name: "proxy.username",
|
||||||
Usage: "connect as user of proxy",
|
Usage: "connect as user of proxy",
|
||||||
@@ -260,7 +277,8 @@ func run(c *cli.Context) error {
|
|||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Host: c.StringSlice("host"),
|
Host: c.StringSlice("host"),
|
||||||
Port: c.String("port"),
|
Port: c.Int("port"),
|
||||||
|
Protocol: easyssh.Protocol(c.String("protocol")),
|
||||||
Username: c.String("username"),
|
Username: c.String("username"),
|
||||||
Password: c.String("password"),
|
Password: c.String("password"),
|
||||||
Passphrase: c.String("ssh-passphrase"),
|
Passphrase: c.String("ssh-passphrase"),
|
||||||
@@ -290,6 +308,7 @@ func run(c *cli.Context) error {
|
|||||||
Password: c.String("proxy.password"),
|
Password: c.String("proxy.password"),
|
||||||
Server: c.String("proxy.host"),
|
Server: c.String("proxy.host"),
|
||||||
Port: c.String("proxy.port"),
|
Port: c.String("proxy.port"),
|
||||||
|
Protocol: easyssh.Protocol(c.String("proxy.protocol")),
|
||||||
Timeout: c.Duration("proxy.timeout"),
|
Timeout: c.Duration("proxy.timeout"),
|
||||||
Ciphers: c.StringSlice("proxy.ciphers"),
|
Ciphers: c.StringSlice("proxy.ciphers"),
|
||||||
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
|
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ type (
|
|||||||
// Config for the plugin.
|
// Config for the plugin.
|
||||||
Config struct {
|
Config struct {
|
||||||
Host []string
|
Host []string
|
||||||
Port string
|
Port int
|
||||||
|
Protocol easyssh.Protocol
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Key string
|
Key string
|
||||||
@@ -115,12 +116,14 @@ func (p *Plugin) removeDestFile(os string, ssh *easyssh.MakeConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) removeAllDestFile() error {
|
func (p *Plugin) removeAllDestFile() error {
|
||||||
for _, host := range trimValues(p.Config.Host) {
|
for _, h := range trimValues(p.Config.Host) {
|
||||||
|
host, port := p.hostPort(h)
|
||||||
ssh := &easyssh.MakeConfig{
|
ssh := &easyssh.MakeConfig{
|
||||||
Server: host,
|
Server: host,
|
||||||
User: p.Config.Username,
|
User: p.Config.Username,
|
||||||
Password: p.Config.Password,
|
Password: p.Config.Password,
|
||||||
Port: p.Config.Port,
|
Port: port,
|
||||||
|
Protocol: p.Config.Protocol,
|
||||||
Key: p.Config.Key,
|
Key: p.Config.Key,
|
||||||
KeyPath: p.Config.KeyPath,
|
KeyPath: p.Config.KeyPath,
|
||||||
Passphrase: p.Config.Passphrase,
|
Passphrase: p.Config.Passphrase,
|
||||||
@@ -133,6 +136,7 @@ func (p *Plugin) removeAllDestFile() error {
|
|||||||
User: p.Config.Proxy.User,
|
User: p.Config.Proxy.User,
|
||||||
Password: p.Config.Proxy.Password,
|
Password: p.Config.Proxy.Password,
|
||||||
Port: p.Config.Proxy.Port,
|
Port: p.Config.Proxy.Port,
|
||||||
|
Protocol: p.Config.Proxy.Protocol,
|
||||||
Key: p.Config.Proxy.Key,
|
Key: p.Config.Proxy.Key,
|
||||||
KeyPath: p.Config.Proxy.KeyPath,
|
KeyPath: p.Config.Proxy.KeyPath,
|
||||||
Passphrase: p.Config.Proxy.Passphrase,
|
Passphrase: p.Config.Proxy.Passphrase,
|
||||||
@@ -209,7 +213,7 @@ func (p *Plugin) buildUnTarArgs(target string) []string {
|
|||||||
|
|
||||||
args = append(args,
|
args = append(args,
|
||||||
"-C",
|
"-C",
|
||||||
"'"+target+"'",
|
target,
|
||||||
)
|
)
|
||||||
|
|
||||||
return args
|
return args
|
||||||
@@ -236,6 +240,8 @@ func (p *Plugin) Exec() error {
|
|||||||
dir := os.TempDir()
|
dir := os.TempDir()
|
||||||
src := filepath.Join(dir, p.DestFile)
|
src := filepath.Join(dir, p.DestFile)
|
||||||
|
|
||||||
|
// show current version
|
||||||
|
fmt.Println("drone-scp version: " + Version)
|
||||||
// run archive command
|
// run archive command
|
||||||
fmt.Println("tar all files into " + src)
|
fmt.Println("tar all files into " + src)
|
||||||
args := p.buildTarArgs(src)
|
args := p.buildTarArgs(src)
|
||||||
@@ -304,6 +310,7 @@ func (p *Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, target := range p.Config.Target {
|
for _, target := range p.Config.Target {
|
||||||
|
target = strings.Replace(target, " ", "\\ ", -1)
|
||||||
// remove target folder before upload data
|
// remove target folder before upload data
|
||||||
if p.Config.Remove {
|
if p.Config.Remove {
|
||||||
p.log(host, "Remove target folder:", target)
|
p.log(host, "Remove target folder:", target)
|
||||||
@@ -323,7 +330,7 @@ func (p *Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(errStr) != 0 {
|
if len(errStr) != 0 {
|
||||||
errChannel <- fmt.Errorf(errStr)
|
errChannel <- fmt.Errorf("%s", errStr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,19 +393,16 @@ func (p *Plugin) Exec() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function takes a Plugin struct and a host string and returns the host and port as separate strings.
|
|
||||||
func (p Plugin) hostPort(host string) (string, string) {
|
func (p Plugin) hostPort(host string) (string, string) {
|
||||||
// Split the host string by colon (":") to get the host and port
|
|
||||||
hosts := strings.Split(host, ":")
|
hosts := strings.Split(host, ":")
|
||||||
// Get the default port from the Plugin's Config field
|
port := strconv.Itoa(p.Config.Port)
|
||||||
port := p.Config.Port
|
if len(hosts) > 1 &&
|
||||||
// If the host string contains a port (i.e. it has more than one element after splitting), set the port to that value
|
(p.Config.Protocol == easyssh.PROTOCOL_TCP ||
|
||||||
if len(hosts) > 1 {
|
p.Config.Protocol == easyssh.PROTOCOL_TCP4) {
|
||||||
host = hosts[0]
|
host = hosts[0]
|
||||||
port = hosts[1]
|
port = hosts[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the host and port as separate strings
|
|
||||||
return host, port
|
return host, port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+136
-22
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -41,7 +42,7 @@ func TestMissingSourceConfig(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"example.com"},
|
Host: []string{"example.com"},
|
||||||
Username: "ubuntu",
|
Username: "ubuntu",
|
||||||
Port: "443",
|
Port: 443,
|
||||||
Password: "1234",
|
Password: "1234",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -81,7 +82,7 @@ func TestSCPFileFromPublicKey(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
Target: []string{filepath.Join(u.HomeDir, "/test")},
|
Target: []string{filepath.Join(u.HomeDir, "/test")},
|
||||||
@@ -131,7 +132,7 @@ func TestSCPFileFromPublicKeyWithPassphrase(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/test",
|
KeyPath: "tests/.ssh/test",
|
||||||
Passphrase: "1234",
|
Passphrase: "1234",
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
@@ -164,7 +165,7 @@ func TestWrongFingerprint(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
Target: []string{filepath.Join(u.HomeDir, "/test2")},
|
Target: []string{filepath.Join(u.HomeDir, "/test2")},
|
||||||
@@ -188,7 +189,6 @@ func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf)
|
pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ func TestSCPFileFromPublicKeyWithFingerprint(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
Fingerprint: ssh.FingerprintSHA256(hostKey),
|
Fingerprint: ssh.FingerprintSHA256(hostKey),
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
@@ -254,7 +254,7 @@ func TestSCPWildcardFileList(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
Target: []string{filepath.Join(u.HomeDir, "abc")},
|
Target: []string{filepath.Join(u.HomeDir, "abc")},
|
||||||
@@ -286,7 +286,7 @@ func TestSCPFromProxySetting(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
Target: []string{filepath.Join(u.HomeDir, "def")},
|
Target: []string{filepath.Join(u.HomeDir, "def")},
|
||||||
@@ -330,7 +330,7 @@ func TestStripComponentsFlag(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
StripComponents: 2,
|
StripComponents: 2,
|
||||||
@@ -363,7 +363,7 @@ func TestUseInsecureCipherFlag(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
StripComponents: 2,
|
StripComponents: 2,
|
||||||
@@ -403,7 +403,7 @@ func TestIgnoreList(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
|
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
|
||||||
StripComponents: 2,
|
StripComponents: 2,
|
||||||
@@ -483,7 +483,7 @@ func TestIncorrectPassword(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
Password: "123456",
|
Password: "123456",
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
Target: []string{"/home"},
|
Target: []string{"/home"},
|
||||||
@@ -506,7 +506,7 @@ func TestNoPermissionCreateFolder(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/a.txt", "tests/b.txt"},
|
Source: []string{"tests/a.txt", "tests/b.txt"},
|
||||||
Target: []string{"/etc/test"},
|
Target: []string{"/etc/test"},
|
||||||
@@ -615,7 +615,7 @@ func TestPlugin_buildUnTarArgs(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
target: "foo",
|
target: "foo",
|
||||||
},
|
},
|
||||||
want: []string{"tar", "-zxf", "foo.tar.gz", "-C", "'foo'"},
|
want: []string{"tar", "-zxf", "foo.tar.gz", "-C", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "strip components",
|
name: "strip components",
|
||||||
@@ -631,7 +631,7 @@ func TestPlugin_buildUnTarArgs(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
target: "foo",
|
target: "foo",
|
||||||
},
|
},
|
||||||
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "-C", "'foo'"},
|
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "-C", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "overwrite",
|
name: "overwrite",
|
||||||
@@ -647,7 +647,7 @@ func TestPlugin_buildUnTarArgs(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
target: "foo",
|
target: "foo",
|
||||||
},
|
},
|
||||||
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "-C", "'foo'"},
|
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "-C", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "unlink first",
|
name: "unlink first",
|
||||||
@@ -663,7 +663,7 @@ func TestPlugin_buildUnTarArgs(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
target: "foo",
|
target: "foo",
|
||||||
},
|
},
|
||||||
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "--unlink-first", "-C", "'foo'"},
|
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "--unlink-first", "-C", "foo"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "output folder path with space",
|
name: "output folder path with space",
|
||||||
@@ -677,9 +677,9 @@ func TestPlugin_buildUnTarArgs(t *testing.T) {
|
|||||||
DestFile: "foo.tar.gz",
|
DestFile: "foo.tar.gz",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
target: "foo bar",
|
target: "foo\\ bar",
|
||||||
},
|
},
|
||||||
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "--unlink-first", "-C", "'foo bar'"},
|
want: []string{"tar", "-zxf", "foo.tar.gz", "--strip-components", "2", "--overwrite", "--unlink-first", "-C", "foo\\ bar"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@@ -782,7 +782,7 @@ func TestTargetFolderWithSpaces(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "22",
|
Port: 22,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
StripComponents: 2,
|
StripComponents: 2,
|
||||||
@@ -821,7 +821,8 @@ func TestHostPortString(t *testing.T) {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost:22", "localhost:22"},
|
Host: []string{"localhost:22", "localhost:22"},
|
||||||
Username: "drone-scp",
|
Username: "drone-scp",
|
||||||
Port: "8080",
|
Protocol: easyssh.PROTOCOL_TCP4,
|
||||||
|
Port: 8080,
|
||||||
KeyPath: "tests/.ssh/id_rsa",
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
Source: []string{"tests/global/*"},
|
Source: []string{"tests/global/*"},
|
||||||
StripComponents: 2,
|
StripComponents: 2,
|
||||||
@@ -848,7 +849,8 @@ func TestHostPortString(t *testing.T) {
|
|||||||
func TestHostPort(t *testing.T) {
|
func TestHostPort(t *testing.T) {
|
||||||
p := Plugin{
|
p := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Port: "8080",
|
Port: 8080,
|
||||||
|
Protocol: easyssh.PROTOCOL_TCP4,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,3 +872,115 @@ func TestHostPort(t *testing.T) {
|
|||||||
t.Errorf("hostPort(%s) = (%s, %s); expected (%s, %s)", host2, actualHost2, actualPort2, expectedHost2, expectedPort2)
|
t.Errorf("hostPort(%s) = (%s, %s); expected (%s, %s)", host2, actualHost2, actualPort2, expectedHost2, expectedPort2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlugin_hostPort(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Config Config
|
||||||
|
Writer io.Writer
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
h string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantHost string
|
||||||
|
wantPort string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "default host and port",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Port: 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
h: "localhost",
|
||||||
|
},
|
||||||
|
wantHost: "localhost",
|
||||||
|
wantPort: "22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "different port",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Port: 22,
|
||||||
|
Protocol: easyssh.PROTOCOL_TCP4,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
h: "localhost:443",
|
||||||
|
},
|
||||||
|
wantHost: "localhost",
|
||||||
|
wantPort: "443",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ipv6",
|
||||||
|
fields: fields{
|
||||||
|
Config: Config{
|
||||||
|
Port: 22,
|
||||||
|
Protocol: easyssh.PROTOCOL_TCP6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
h: "::1",
|
||||||
|
},
|
||||||
|
wantHost: "::1",
|
||||||
|
wantPort: "22",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := Plugin{
|
||||||
|
Config: tt.fields.Config,
|
||||||
|
}
|
||||||
|
gotHost, gotPort := p.hostPort(tt.args.h)
|
||||||
|
if gotHost != tt.wantHost {
|
||||||
|
t.Errorf("Plugin.hostPort() gotHost = %v, want %v", gotHost, tt.wantHost)
|
||||||
|
}
|
||||||
|
if gotPort != tt.wantPort {
|
||||||
|
t.Errorf("Plugin.hostPort() gotPort = %v, want %v", gotPort, tt.wantPort)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIgnoreFolder(t *testing.T) {
|
||||||
|
if os.Getenv("SSH_AUTH_SOCK") != "" {
|
||||||
|
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
|
||||||
|
t.Fatalf("exec: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := user.Lookup("drone-scp")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Lookup: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin := Plugin{
|
||||||
|
Config: Config{
|
||||||
|
Host: []string{"localhost"},
|
||||||
|
Username: "drone-scp",
|
||||||
|
Protocol: easyssh.PROTOCOL_TCP4,
|
||||||
|
Port: 22,
|
||||||
|
KeyPath: "tests/.ssh/id_rsa",
|
||||||
|
Source: []string{"tests/*", "!tests/global"},
|
||||||
|
Target: []string{filepath.Join(u.HomeDir, "test_ignore")},
|
||||||
|
CommandTimeout: 60 * time.Second,
|
||||||
|
TarExec: "tar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = plugin.Exec()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// check file exist
|
||||||
|
if _, err := os.Stat(filepath.Join(u.HomeDir, "test_ignore", "global", "c.txt")); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("SCP-error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(u.HomeDir, "test_ignore", "global", "d.txt")); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("SCP-error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user