Compare commits

...

54 Commits

Author SHA1 Message Date
Bo-Yi Wu 256ad7447c ci(docker): fail push when trivy finds CRITICAL/HIGH issues 2026-04-16 23:01:09 +08:00
Bo-Yi Wu f06dda2b3e ci(trivy): use existing build_docker make target 2026-04-16 22:49:10 +08:00
Bo-Yi Wu 262e7e16b7 ci: enable check-latest in docker and goreleaser workflows 2026-04-16 22:42:52 +08:00
Bo-Yi Wu f93104aeb7 fix: skip integration tests without telegram secrets; apply modernize fix 2026-04-16 22:39:45 +08:00
Bo-Yi Wu cd05adc191 ci: pin golangci-lint to v2.11 2026-04-16 21:11:20 +08:00
Bo-Yi Wu af4fd887b2 ci: bump GitHub Actions and add Go 1.25/1.26 to test matrix 2026-04-16 21:03:29 +08:00
Bo-Yi Wu cf36b35b36 chore: bump go directive to 1.25.9 2026-04-16 20:57:59 +08:00
Bo-Yi Wu 90d58d2f98 ci: add Trivy security scanning for source code and Docker image
- Add independent trivy.yml workflow with repo scan and image scan jobs
- Add Trivy image scan step in docker.yml before pushing Docker image
- Add security-events permission for SARIF upload
- Add Trivy Security Scan badge to README
2026-04-16 18:10:11 +08:00
Bo-Yi Wu a4fc564fc9 fix(deps): upgrade golang.org/x/crypto to fix CVE vulnerabilities
- bump golang.org/x/crypto to v0.45.0 (fixes CVE-2024-45337 CRITICAL,
  CVE-2025-22869 HIGH, CVE-2025-47914 MEDIUM, CVE-2025-58181 MEDIUM)
- bump golang.org/x/sys to v0.38.0
2026-04-16 12:13:16 +08:00
Bo-Yi Wu 7d363fb2b0 ci(actions): upgrade GitHub Actions to latest versions
- bump actions/checkout to v6
- bump actions/setup-go to v6
- bump actions/cache to v5
- bump goreleaser/goreleaser-action to v7
- bump golangci/golangci-lint-action to v9
- bump github/codeql-action/* to v4
- bump codecov/codecov-action to v5
- bump docker/build-push-action to v7
- bump docker/login-action to v4
- bump docker/metadata-action to v6
- bump docker/setup-buildx-action to v4
- bump docker/setup-qemu-action to v4
- bump hadolint/hadolint-action to v3.3.0
- bump aquasecurity/trivy-action to v0.35.0
2026-04-16 12:06:53 +08:00
appleboy 2b178e9a27 chore: bump dependencies to latest stable versions
- Update dependencies: bump github.com/appleboy/com to v1.1.0, github.com/urfave/cli/v2 to v2.27.7, golang.org/x/crypto to v0.41.0, github.com/xrash/smetrics and golang.org/x/sys to newer versions

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-09-02 00:01:06 +08:00
appleboy aad3a6ad27 docs: improve consistency and accuracy of Chinese language selection
- Correct the display of Chinese script names for Simplified and Traditional Chinese
- Reorder language selection links for consistency across documentation files

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-08-31 11:06:02 +08:00
Florian Maurer dd5217c90a add woodpecker compatible metadata (#197)
See https://github.com/woodpecker-ci/woodpecker/pull/4871 for more information
2025-05-03 07:22:11 +08:00
appleboy 110008c84a docs: update README files with correct workflow links and formatting
- Update workflow badge links in all README files to reference testing.yml instead of lint.yml
- Fix bullet formatting in Chinese README files for better markdown display

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-27 11:43:48 +08:00
appleboy cc35c73edd feat: expand proxy configuration with new flags and env support
- Add multiple new proxy-related flags, including protocol, username, password, SSH key, key path, SSH passphrase, connection timeout, ciphers, use of insecure ciphers, and fingerprint
- Enable proxy configuration using environment variables for each new flag
- Set default values for several proxy options (e.g., protocol defaults to tcp, username defaults to root)

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-27 11:41:44 +08:00
appleboy e8f6afdd34 chore: update go-md2man dependency to v2.0.7
- Bump github.com/cpuguy83/go-md2man/v2 from version 2.0.6 to 2.0.7 in dependencies

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-26 23:09:46 +08:00
Bo-Yi Wu 05df7845ab feat: integrate godump for enhanced debugging functionality
- Add `github.com/yassinebenaid/godump` dependency in `go.mod`
- Import `github.com/yassinebenaid/godump` in `main.go`
- Add debug dump functionality using `godump` in `run` function

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-04-15 11:29:31 +08:00
Bo-Yi Wu 928be3e7e7 chore: upgrade Go dependencies to latest versions
- Update Go version from `1.23.0` to `1.23.8`
- Upgrade `github.com/appleboy/com` from `v0.2.0` to `v0.3.0`
- Upgrade `github.com/urfave/cli/v2` from `v2.27.5` to `v2.27.6`
- Upgrade `golang.org/x/crypto` from `v0.36.0` to `v0.37.0`
- Upgrade `github.com/ScaleFT/sshkeys` from `v1.2.0` to `v1.4.0`
- Upgrade `github.com/cpuguy83/go-md2man/v2` from `v2.0.5` to `v2.0.6`
- Upgrade `github.com/mattn/go-colorable` from `v0.1.13` to `v0.1.14`
- Upgrade `golang.org/x/sys` from `v0.31.0` to `v0.32.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-04-15 10:42:01 +08:00
Bo-Yi Wu e4f03f3543 build: enhance build process and testing across environments
- Add a new `all` target to the Makefile

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-04-15 10:35:36 +08:00
appleboy 419eff8b22 build: revamp make targets and update build instructions
- Replace `make build_linux_amd64` and `make build_linux_arm64` with `make build_docker`
- Add a help target with usage instructions and target descriptions
- Update `fmt` to install the latest version of `gofumpt`
- Add descriptions for `vet`, `fmt-check`, `test`, `install`, `build`, `ssh-server`, and `clean` targets
- Remove several build targets (`amd64`, `i386`, `arm64`, `arm`)
- Remove the `coverage` and `version` targets

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-14 14:12:46 +08:00
appleboy 0c387532cf refactor: improve code clarity and testing reliability across modules
- Use `strings.ReplaceAll` instead of `strings.Replace` for clarity and conciseness

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-12 19:42:12 +08:00
appleboy e2a386e6ec ci: enhance linting and string manipulations in plugin code
- Update golangci-lint action to v7 and specify version v2.0 in the GitHub testing workflow
- Add `.golangci.yaml` configuration file with various linters and settings
- Refactor string concatenation method for destination file name in `plugin.go`
- Use `strings.ReplaceAll` for replacing spaces in target paths in `plugin.go`
- Change error handling to use `errors.As` for type assertion in `plugin.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-12 19:41:17 +08:00
appleboy 7a4b5f1fad build: update dependencies and optimize Docker configuration
- Update base image in Dockerfile from `alpine:3.17` to `alpine:3.21`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-10 22:17:06 +08:00
appleboy eb083b1019 docs: enhance documentation and streamline configuration options
- Update usage descriptions for better clarity and detail
- Remove various proxy-related flags, streamlining the configuration options
- Add comments to indicate unchanged proxy settings
- Improve descriptions of tar-related flags for better understanding

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-10 22:16:39 +08:00
appleboy 5c956e2bfa ci: refactor CI workflows and enhance test configurations
- Rename `.github/workflows/lint.yml` to `.github/workflows/testing.yml`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-10 22:06:50 +08:00
appleboy 1536096428 chore: update Go version and dependencies to 1.23-alpine
- Update golang container version in GitHub Actions file to `1.23-alpine`
- Change go module version to `1.23.0`
- Upgrade `golang.org/x/crypto` to `v0.36.0`
- Upgrade `golang.org/x/sys` to `v0.31.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-10 22:06:25 +08:00
appleboy aab544b837 docs: improve documentation clarity and consistency throughout files
- Enhance description of SSH file transfer method
- Update heading from "Feature" to "Features"
- Reformulate feature list for clarity and readability
- Ensure list formatting consistency in documentation

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-10 22:05:21 +08:00
appleboy 4a529bdfd2 feat(bearer): configure scanning and reporting settings
- Add a new configuration file for bearer settings
- Set logging level to info
- Define reporting options including severity levels and output format
- Specify rules for scanning, including disabling default rules and skipping a specific rule
- Configure scanning parameters such as domain resolution and exit code settings

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-12-01 17:47:06 +08:00
appleboy 4f744b8f8b ci(bearer): enhance security with Bearer GitHub Action integration
- Add Bearer GitHub Action to scan for sensitive data in the codebase, configured to only scan changes in the current pull request or commit

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-12-01 10:32:50 +08:00
Bo-Yi Wu 19f2d8e319 docs: update 2024-11-19 13:57:12 +08:00
Bo-Yi Wu c250624789 docs: translate zh-tw and zh-ch 2024-11-19 13:52:15 +08:00
appleboy 2a9a5789cc ci(docker): improve CI workflow and API integration
- Downgrade docker/login-action from v4 to v3 in GitHub workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-28 21:48:53 +08:00
appleboy 38fe651776 style(lint): improve error handling and testing robustness
- Fix formatting issue in error message by using a formatted string with `fmt.Errorf`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-28 21:47:09 +08:00
appleboy 2679e1a33b build(goreleaser): refactor codebase for improved performance and maintainability
- Change goreleaser argument from `--rm-dist` to `--clean`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-28 21:02:41 +08:00
appleboy 12827c56e5 refactor(makefile): simplify and clean up Makefile for streamlined builds
- Remove redundant `DIST` variable declaration
- Update `GOFMT` command to include `-s` and `-w` flags
- Remove `SHASUM` variable declaration
- Remove `XGO_PACKAGE` and `XGO_VERSION` variable declarations
- Remove `GXZ_PAGAGE` variable declaration
- Remove architecture-specific variables (`LINUX_ARCHS`, `DARWIN_ARCHS`, `WINDOWS_ARCHS`)
- Remove `.PHONY` targets and associated rules for `deps-backend`, `release`, `release-windows`, `release-linux`, `release-darwin`, `release-copy`, `release-check`, and `release-compress`
- Simplify the `Makefile` by removing complex release-related commands and dependencies

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-28 21:01:40 +08:00
appleboy 9f8137bea7 chore(deps): update dependencies to latest versions
- Update `github.com/appleboy/com` to v0.2.0
- Update `github.com/fatih/color` to v1.18.0
- Update `github.com/urfave/cli/v2` to v2.27.5
- Update `golang.org/x/crypto` to v0.28.0
- Update `github.com/cpuguy83/go-md2man/v2` to v2.0.5
- Update `golang.org/x/sys` to v0.26.0

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-28 20:48:54 +08:00
Bo-Yi Wu 2decbc4a77 feat: refactor protocol configuration handling in main and plugin
- Add protocol configuration to the `run` function in `main.go`
- Remove redundant protocol configuration from the `run` function in `main.go`
- Add proxy protocol configuration to the `run` function in `main.go`
- Add protocol configuration to the `removeAllDestFile` function in `plugin.go`
- Add proxy protocol configuration to the `removeAllDestFile` function in `plugin.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-19 07:50:09 +08:00
Bo-Yi Wu 7468610684 chore: standardize code style and enhance changelog configuration
- Change single quotes to double quotes for `name_template`
- Add changelog configuration with GitHub integration
- Define changelog groups for Features, Bug fixes, Enhancements, Refactor, Build process updates, Documentation updates, and Others

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-19 07:46:51 +08:00
Xiaotong Liu 79beba5443 fix(parameter): missing protocol argument (#193)
* fix host split

* rm .idea
2024-07-19 07:43:10 +08:00
Bo-Yi Wu 716cc7189b ci: downgrade GitHub workflow dependencies
- Downgrade docker/login-action from v4 to v3 in GitHub workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 22:16:01 +08:00
Bo-Yi Wu 052d6e71bc feat: load environment variables from /run/drone/env file
- Add check for `/run/drone/env` file and load environment variables if it exists

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 22:10:19 +08:00
Bo-Yi Wu 13819778ab ci: update Go version and improve lint workflow
- Add repository checkout step to lint workflow
- Update Go version in lint workflow to use `go.mod` file and check latest version
- Change container image in lint workflow from `golang:1.21-alpine` to `golang:1.22-alpine`
- Update Go version in `go.mod` from `1.18` to `1.22`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 22:09:41 +08:00
Bo-Yi Wu e61e2409d3 ci: update Docker actions and remove ARM build step
- Remove `make build_linux_arm` step
- Update `docker/setup-qemu-action` to v3
- Update `docker/setup-buildx-action` to v3
- Update `docker/login-action` to v4
- Update `docker/metadata-action` to v5
- Update `docker/build-push-action` to v6
- Remove `linux/arm` platform from build platforms

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 22:08:26 +08:00
Bo-Yi Wu 0601816b74 chore: update Golang dependencies to latest versions
- Update `golang.org/x/crypto` from v0.23.0 to v0.25.0
- Update `golang.org/x/sys` from v0.20.0 to v0.22.0

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-11 22:28:41 +08:00
Bo-Yi Wu 13c4ec4609 ci: update GitHub Actions to latest versions
- Update `actions/checkout` to version `v4` in `codeql.yml`
- Update `github/codeql-action/init` to version `v3` in `codeql.yml`
- Update `github/codeql-action/analyze` to version `v3` in `codeql.yml`
- Update `actions/checkout` to version `v4` in `goreleaser.yml`
- Update `goreleaser/goreleaser-action` to version `v6` in `goreleaser.yml`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-11 22:27:50 +08:00
Bo-Yi Wu 87c72235a8 test: enhance SCP plugin with folder ignore and error handling (#192)
- Add `TestIgnoreFolder` function to test ignoring specific folders during SCP
- Initialize and terminate `ssh-agent` if `SSH_AUTH_SOCK` is set
- Lookup user `drone-scp` and handle potential errors
- Configure `Plugin` with specific settings for SCP operation
- Execute `plugin.Exec()` and assert no errors
- Verify that certain files do not exist in the target directory after SCP operation

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 12:33:11 +08:00
Bo-Yi Wu fe4a745be0 feat: enhance plugin networking capabilities support IPV6 (#191)
* feat: enhance plugin networking capabilities

- Enable SSH server to listen on all interfaces by uncommenting relevant lines in `sshd_config`
- Add new `protocol` and `proxy.protocol` flags to `main.go` with usage information and default values
- Change the `Port` field type from `string` to `int` in `plugin.go` and `plugin_test.go`
- Refactor variable name from `host` to `h` and add `port` variable in `plugin.go` loop
- Remove commented-out code and refactor `hostPort` function in `plugin.go`
- Add import for `io` package in `plugin_test.go`
- Add new test function `TestPlugin_hostPort` with multiple test cases in `plugin_test.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update

Signed-off-by: appleboy <appleboy.tw@gmail.com>

* update

Signed-off-by: appleboy <appleboy.tw@gmail.com>

* update

Signed-off-by: appleboy <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 11:40:23 +08:00
appleboy 45ef1287c2 ci: standardize YAML formatting and upgrade GitHub Actions
- Change cron schedule quotes from single to double in codeql.yml
- Update language matrix quotes from single to double in codeql.yml
- Upgrade actions/checkout from v3 to v4 in docker.yml
- Add a blank line after make build_linux_arm64 step in docker.yml
- Change tag pattern quotes from single to double in goreleaser.yml
- Consolidate steps in goreleaser.yml by removing unnecessary line breaks
- Upgrade actions/setup-go from v4 to v5 in goreleaser.yml
- Upgrade golangci-lint-action from v3 to v6 in lint.yml
- Upgrade codecov-action from v3 to v4 in lint.yml

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 10:51:10 +08:00
appleboy 9a56c98766 style: standardize code style and optimize CI pipeline
- Change single quotes to double quotes for consistency
- Consolidate job steps by removing unnecessary hyphens
- Add caching options for Docker build and push actions

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 10:50:11 +08:00
appleboy c1ebb32673 chore: update dependencies to latest versions
- Update `github.com/fatih/color` from v1.16.0 to v1.17.0
- Update `github.com/urfave/cli/v2` from v2.27.1 to v2.27.2
- Update `golang.org/x/crypto` from v0.22.0 to v0.23.0
- Update `github.com/xrash/smetrics` from v0.0.0-20240312152122-5f08fbb34913 to v0.0.0-20240521201337-686a1a2994c1
- Update `golang.org/x/sys` from v0.19.0 to v0.20.0

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 10:12:04 +08:00
Bo-Yi Wu 4a7fa1bdff chore: update dependencies to latest versions
- Update `golang.org/x/crypto` from `v0.18.0` to `v0.22.0`
- Update `github.com/cpuguy83/go-md2man/v2` from `v2.0.3` to `v2.0.4`
- Update `github.com/xrash/smetrics` to a newer commit
- Update `golang.org/x/sys` from `v0.16.0` to `v0.19.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-04-17 12:11:47 +08:00
appleboy 6bb71c761c chore: update dependencies in go.mod file
- Update the version of `golang.org/x/crypto` from `v0.17.0` to `v0.18.0` in the `go.mod` file
- Update the version of `golang.org/x/sys` from `v0.15.0` to `v0.16.0` in the `go.mod` file

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-01-11 20:52:49 +08:00
Bo-Yi Wu bb91fba471 chore: update external dependencies versions
- Update the version of `github.com/appleboy/easyssh-proxy` from `v1.4.0` to `v1.5.0`
- Update the version of `github.com/urfave/cli/v2` from `v2.26.0` to `v2.27.1`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-01 10:38:36 +08:00
Bo-Yi Wu 86f19b9c1c chore: update dependencies to latest versions
- Update `easyssh-proxy` dependency from `v1.3.10` to `v1.4.0`
- Update `color` library from `v1.15.0` to `v1.16.0`
- Upgrade `urfave/cli` module from `v2.25.5` to `v2.26.0`
- Bump `x/crypto` version from `v0.9.0` to `v0.17.0`
- Increment `go-md2man` indirect dependency from `v2.0.2` to `v2.0.3`
- Update `go-isatty` indirect dependency from `v0.0.19` to `v0.0.20`
- Update `smetrics` indirect dependency to a newer commit
- Upgrade `x/sys` indirect dependency from `v0.8.0` to `v0.15.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-12-26 13:46:27 +08:00
22 changed files with 1221 additions and 379 deletions
+17 -17
View File
@@ -13,12 +13,12 @@ name: "CodeQL"
on:
push:
branches: [ master ]
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches: [master]
schedule:
- cron: '41 23 * * 6'
- cron: "41 23 * * 6"
jobs:
analyze:
@@ -32,23 +32,23 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v6
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# 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.
# 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
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# 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.
# 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
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
+54 -28
View File
@@ -5,56 +5,56 @@ on:
branches:
- master
tags:
- 'v*'
- "v*"
pull_request:
branches:
- 'master'
- "master"
permissions:
contents: read
packages: write
security-events: write
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: '^1'
go-version: "^1"
check-latest: true
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Build binary
run : |
make build_linux_amd64
make build_linux_arm
make build_linux_arm64
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
run: |
make build_docker
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
-
name: Login to Docker Hub
uses: docker/login-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Docker meta
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v6
with:
images: |
${{ github.repository }}
@@ -65,13 +65,39 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
-
name: Build and push
uses: docker/build-push-action@v4
- name: Build image for scanning
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm,linux/arm64
file: docker/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: drone-scp:scan
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: "drone-scp:scan"
format: "sarif"
output: "trivy-image-results.sarif"
severity: "CRITICAL,HIGH"
exit-code: '1'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-image-results.sarif"
category: "trivy-docker-image"
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
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
+10 -12
View File
@@ -3,7 +3,7 @@ name: Goreleaser
on:
push:
tags:
- '*'
- "*"
permissions:
contents: write
@@ -12,24 +12,22 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
-
name: Setup go
uses: actions/setup-go@v5
- name: Setup go
uses: actions/setup-go@v6
with:
go-version: '^1'
go-version: "^1"
check-latest: true
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-45
View File
@@ -1,45 +0,0 @@
name: Lint and Testing
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: "^1"
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --verbose
- uses: hadolint/hadolint-action@v3.1.0
name: hadolint for Dockerfile
with:
dockerfile: docker/Dockerfile
testing:
runs-on: ubuntu-latest
container: golang:1.21-alpine
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: setup sshd server
run: |
apk add git make curl perl bash build-base zlib-dev ucl-dev
make ssh-server
- name: testing
run: |
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
+61
View File
@@ -0,0 +1,61 @@
name: Lint and Testing
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11
args: --verbose
- uses: hadolint/hadolint-action@v3.3.0
name: hadolint for Dockerfile
with:
dockerfile: docker/Dockerfile
# This step uses the Bearer GitHub Action to scan for sensitive data in the codebase.
# The 'uses' keyword specifies the action to be used, in this case, 'bearer/bearer-action' at version 'v2'.
# The 'with' keyword provides input parameters for the action:
# - 'diff: true' indicates that the action should only scan the changes in the current pull request or commit.
- name: Bearer
uses: bearer/bearer-action@v2
with:
diff: true
testing:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.25", "1.26"]
container:
image: golang:${{ matrix.go-version }}-alpine
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: setup sshd server
run: |
apk add git make curl perl bash build-base zlib-dev ucl-dev gpg
make ssh-server
- name: testing
run: |
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
+85
View File
@@ -0,0 +1,85 @@
name: Trivy Security Scan
on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
# Run daily at 00:00 UTC
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
trivy-repo-scan:
name: Trivy Repository Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Run Trivy vulnerability scanner (repo)
uses: aquasecurity/trivy-action@v0.35.0
with:
scan-type: "fs"
scan-ref: "."
format: "sarif"
output: "trivy-repo-results.sarif"
severity: "CRITICAL,HIGH"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-repo-results.sarif"
trivy-image-scan:
name: Trivy Image Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
- name: Build binary
run: |
make build_docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image for scanning
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: drone-scp:scan
- name: Run Trivy vulnerability scanner (image)
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: "drone-scp:scan"
format: "sarif"
output: "trivy-image-results.sarif"
severity: "CRITICAL,HIGH"
- name: Upload Trivy image scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-image-results.sarif"
category: "trivy-image"
+1
View File
@@ -29,3 +29,4 @@ dist
.cover
release
bin
.idea
+54
View File
@@ -0,0 +1,54 @@
version: "2"
linters:
enable:
- asciicheck
- durationcheck
- errorlint
- gosec
- misspell
- nakedret
- nilerr
- nolintlint
- perfsprint
- revive
- usestdlibvars
- wastedassign
settings:
gosec:
includes:
- G102
- G106
- G108
- G109
- G111
- G112
- G201
- G203
perfsprint:
int-conversion: true
err-error: true
errorf: true
sprintf1: true
strconcat: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
+98 -74
View File
@@ -3,78 +3,78 @@ before:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
- freebsd
goarch:
- amd64
- arm
- arm64
goarm:
- "5"
- "6"
- "7"
ignore:
- goos: darwin
goarch: arm
- goos: darwin
goarch: ppc64le
- goos: darwin
goarch: s390x
- goos: windows
goarch: ppc64le
- goos: windows
goarch: s390x
- goos: windows
goarch: arm
goarm: "5"
- goos: windows
goarch: arm
goarm: "6"
- goos: windows
goarch: arm
goarm: "7"
- goos: windows
goarch: arm64
- goos: freebsd
goarch: ppc64le
- goos: freebsd
goarch: s390x
- goos: freebsd
goarch: arm
goarm: "5"
- goos: freebsd
goarch: arm
goarm: "6"
- goos: freebsd
goarch: arm
goarm: "7"
- goos: freebsd
goarch: arm64
flags:
- -trimpath
ldflags:
- -s -w
- -X main.Version={{.Version}}
binary: >-
{{ .ProjectName }}-
{{- if .IsSnapshot }}{{ .Branch }}-
{{- else }}{{- .Version }}-{{ end }}
{{- .Os }}-
{{- if eq .Arch "amd64" }}amd64
{{- else if eq .Arch "amd64_v1" }}amd64
{{- else if eq .Arch "386" }}386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}-{{ .Arm }}{{ end }}
no_unique_dist_dir: true
hooks:
post:
- cmd: xz -k -9 {{ .Path }}
dir: ./dist/
- env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
- freebsd
goarch:
- amd64
- arm
- arm64
goarm:
- "5"
- "6"
- "7"
ignore:
- goos: darwin
goarch: arm
- goos: darwin
goarch: ppc64le
- goos: darwin
goarch: s390x
- goos: windows
goarch: ppc64le
- goos: windows
goarch: s390x
- goos: windows
goarch: arm
goarm: "5"
- goos: windows
goarch: arm
goarm: "6"
- goos: windows
goarch: arm
goarm: "7"
- goos: windows
goarch: arm64
- goos: freebsd
goarch: ppc64le
- goos: freebsd
goarch: s390x
- goos: freebsd
goarch: arm
goarm: "5"
- goos: freebsd
goarch: arm
goarm: "6"
- goos: freebsd
goarch: arm
goarm: "7"
- goos: freebsd
goarch: arm64
flags:
- -trimpath
ldflags:
- -s -w
- -X main.Version={{.Version}}
binary: >-
{{ .ProjectName }}-
{{- if .IsSnapshot }}{{ .Branch }}-
{{- else }}{{- .Version }}-{{ end }}
{{- .Os }}-
{{- if eq .Arch "amd64" }}amd64
{{- else if eq .Arch "amd64_v1" }}amd64
{{- else if eq .Arch "386" }}386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}-{{ .Arm }}{{ end }}
no_unique_dist_dir: true
hooks:
post:
- cmd: xz -k -9 {{ .Path }}
dir: ./dist/
archives:
- format: binary
@@ -82,9 +82,9 @@ archives:
allow_different_binary_count: true
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
extra_files:
- glob: ./**.xz
- glob: ./**.xz
snapshot:
name_template: "{{ incpatch .Version }}"
@@ -97,3 +97,27 @@ release:
# 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
+5
View File
@@ -1,11 +1,16 @@
---
date: 2017-01-06T00:00:00+00:00
title: SCP
name: SCP
description: Deploy artifacts using SSH/SCP
author: appleboy
tags: [ publish, ssh, scp ]
logo: term.svg
repo: appleboy/drone-scp
image: appleboy/drone-scp
containerImage: appleboy/drone-scp
containerImageUrl: https://hub.docker.com/r/appleboy/drone-scp
url: https://github.com/appleboy/drone-scp
---
The SCP plugin copy files and artifacts to target host machine via SSH. The below pipeline configuration demonstrates simple usage:
+23 -83
View File
@@ -1,19 +1,8 @@
DIST := dist
EXECUTABLE := drone-scp
GOFMT ?= gofumpt -l
DIST := dist
DIST_DIRS := $(DIST)/binaries $(DIST)/release
GOFMT ?= gofumpt -l -s -w
GO ?= go
SHASUM ?= shasum -a 256
GOFILES := $(shell find . -name "*.go" -type f)
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)
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -51,17 +40,25 @@ LDFLAGS ?= -X 'main.Version=$(VERSION)'
all: build
fmt:
.PHONY: help
help: ## Print this help message.
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
fmt: ## Format the code
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
$(GO) install mvdan.cc/gofumpt@latest; \
fi
$(GOFMT) -w $(GOFILES)
vet:
vet: ## Run go vet
$(GO) vet ./...
.PHONY: fmt-check
fmt-check:
fmt-check: ## Check if the code is formatted
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
@@ -72,30 +69,22 @@ fmt-check:
exit 1; \
fi;
test:
test: ## Run tests
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
install: $(GOFILES)
install: $(GOFILES) ## Install the package
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
build: $(EXECUTABLE) ## Build the package
$(EXECUTABLE): $(GOFILES)
$(EXECUTABLE): $(GOFILES) ## Build the package
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
build_linux_amd64:
build_docker:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
build_linux_i386:
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
build_linux_arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
build_linux_arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
ssh-server:
ssh-server: ## Run ssh server
adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
echo drone-scp:1234 | chpasswd
mkdir -p /home/drone-scp/.ssh
@@ -108,59 +97,10 @@ ssh-server:
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/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 &
coverage:
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: ## Clean the build
$(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
version:
@echo $(VERSION)
rm -rf coverage.txt $(EXECUTABLE)
+18 -15
View File
@@ -1,21 +1,24 @@
# drone-scp
[繁體中文](README.zh-tw.md) | [簡體中文](README.zh-cn.md)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![Lint and Testing](https://github.com/appleboy/drone-scp/actions/workflows/lint.yml/badge.svg)](https://github.com/appleboy/drone-scp/actions/workflows/lint.yml)
[![Lint and Testing](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml/badge.svg)](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml)
[![Trivy Security Scan](https://github.com/appleboy/drone-scp/actions/workflows/trivy.yml/badge.svg?branch=master)](https://github.com/appleboy/drone-scp/actions/workflows/trivy.yml)
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://docs.drone.io/).
Securely transfer files and artifacts via SSH using a standalone binary, Docker container, or [Drone CI](http://docs.drone.io/) integration.
## Feature
## Features
* [x] Support routines.
* [x] Support wildcard pattern on source list.
* [x] Support send files to multiple host.
* [x] Support send files to multiple target folder on host.
* [x] Support load ssh key from absolute path or raw body.
* [x] Support SSH ProxyCommand.
- [x] Parallel file transfer with multiple routines
- [x] Support for wildcard patterns in source file selection
- [x] Ability to transfer files to multiple destination hosts
- [x] Support for multiple target directories on each host
- [x] Flexible SSH key authentication via file path or raw content
- [x] Advanced networking with SSH ProxyCommand support
```sh
+--------+ +----------+ +-----------+
@@ -56,9 +59,9 @@ Copy files and artifacts via SSH using a binary, docker or [Drone CI](http://doc
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-scp/releases). Support the following OS type.
* Windows amd64/386
* Linux arm/amd64/386
* Darwin amd64/386
- Windows amd64/386
- Linux arm/amd64/386
- Darwin amd64/386
With `Go` installed
@@ -92,9 +95,9 @@ make docker
There are three ways to send notification.
* [usage from binary](#usage-from-binary)
* [usage from docker](#usage-from-docker)
* [usage from drone ci](#usage-from-drone-ci)
- [usage from binary](#usage-from-binary)
- [usage from docker](#usage-from-docker)
- [usage from drone ci](#usage-from-drone-ci)
### Usage from binary
+265
View File
@@ -0,0 +1,265 @@
# drone-scp
[English](README.md) | [繁體中文](README.zh-tw.md)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![Lint and Testing](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml/badge.svg)](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml)
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
复制文件和工件通过 SSH 使用二进制文件、docker 或 [Drone CI](http://docs.drone.io/)。
[English](README.md) | [繁體中文](README.zh-tw.md)
## 功能
- [x] 支持例程。
- [x] 支持来源列表中的通配符模式。
- [x] 支持将文件发送到多个主机。
- [x] 支持将文件发送到主机上的多个目标文件夹。
- [x] 支持从绝对路径或原始主体加载 ssh 密钥。
- [x] 支持 SSH ProxyCommand。
```sh
+--------+ +----------+ +-----------+
| Laptop | <--> | Jumphost | <--> | FooServer |
+--------+ +----------+ +-----------+
OR
+--------+ +----------+ +-----------+
| Laptop | <--> | Firewall | <--> | FooServer |
+--------+ +----------+ +-----------+
192.168.1.5 121.1.2.3 10.10.29.68
```
## Breaking changes
`v1.5.0`: change command timeout flag to `Duration`. See the following setting:
```diff
- name: scp files
image: appleboy/drone-scp
settings:
host:
- example1.com
- example2.com
username: ubuntu
password:
from_secret: ssh_password
port: 22
- command_timeout: 120
+ command_timeout: 2m
target: /home/deploy/web
source:
- release/*.tar.gz
```
## Build or Download a binary
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-scp/releases). Support the following OS type.
- Windows amd64/386
- Linux arm/amd64/386
- Darwin amd64/386
With `Go` installed
```sh
export GO111MODULE=on
go get -u -v github.com/appleboy/drone-scp
```
or build the binary with the following command:
```sh
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go test -cover ./...
go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
```
## Docker
Build the docker image with the following commands:
```sh
make docker
```
## Usage
There are three ways to send notification.
- [usage from binary](#usage-from-binary)
- [usage from docker](#usage-from-docker)
- [usage from drone ci](#usage-from-drone-ci)
### Usage from binary
#### Using public key
```bash
drone-scp --host example.com \
--port 22 \
--username appleboy \
--key-path "${HOME}/.ssh/id_rsa" \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Using password
```diff
drone-scp --host example.com \
--port 22 \
--username appleboy \
+ --password xxxxxxx \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Using ssh-agent
Start your local ssh agent:
```bash
eval `ssh-agent -s`
```
Import your local public key `~/.ssh/id_rsa`
```sh
ssh-add
```
You don't need to add `--password` or `--key-path` arguments.
```bash
drone-scp --host example.com \
--port 22 \
--username appleboy \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Send multiple source or target folder and hosts
```diff
drone-scp --host example1.com \
+ --host example2.com \
--port 22 \
--username appleboy \
--password xxxxxxx
--target /home/appleboy/test1 \
+ --target /home/appleboy/test2 \
--source your_local_folder_path_1
+ --source your_local_folder_path_2
```
### Usage from docker
Using public key
```bash
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_KEY_PATH="${HOME}/.ssh/id_rsa"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Using password
```diff
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
+ -e SCP_PASSWORD="xxxxxxx"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Using ssh-agent, start your local ssh agent:
```bash
eval `ssh-agent -s`
```
Import your local public key `~/.ssh/id_rsa`
```sh
ssh-add
```
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH` arguments.
```bash
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Send multiple source or target folder and hosts
```bash
docker run --rm \
-e SCP_HOST=example1.com,example2.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PASSWORD=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST_1,SOURCE_FILE_LIST_2 \
-e SCP_TARGET=TARGET_FOLDER_PATH_1,TARGET_FOLDER_PATH_2 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
### Usage from drone ci
Execute from the working directory:
```bash
docker run --rm \
-e PLUGIN_HOST=example.com \
-e PLUGIN_USERNAME=xxxxxxx \
-e PLUGIN_PASSWORD=xxxxxxx \
-e PLUGIN_PORT=xxxxxxx \
-e PLUGIN_SOURCE=SOURCE_FILE_LIST \
-e PLUGIN_TARGET=TARGET_FOLDER_PATH \
-e PLUGIN_RM=false \
-e PLUGIN_DEBUG=true \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
You can get more [information](http://plugins.drone.io/appleboy/drone-scp/) about how to use scp in drone.
## Testing
Test the package with the following command:
```sh
make test
```
+265
View File
@@ -0,0 +1,265 @@
# drone-scp
[English](README.md) | [簡體中文](README.zh-cn.md)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-scp?status.svg)](https://godoc.org/github.com/appleboy/drone-scp)
[![Lint and Testing](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml/badge.svg)](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml)
[![codecov](https://codecov.io/gh/appleboy/drone-scp/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-scp)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-scp)](https://goreportcard.com/report/github.com/appleboy/drone-scp)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-scp.svg)](https://hub.docker.com/r/appleboy/drone-scp/)
複製檔案和工件通過 SSH 使用二進制檔案、docker 或 [Drone CI](http://docs.drone.io/)。
[English](README.md) | [簡體中文](README.zh-cn.md)
## 功能
- [x] 支援例程。
- [x] 支援來源列表中的萬用字元模式。
- [x] 支援將檔案發送到多個主機。
- [x] 支援將檔案發送到主機上的多個目標資料夾。
- [x] 支援從絕對路徑或原始主體載入 ssh 金鑰。
- [x] 支援 SSH ProxyCommand。
```sh
+--------+ +----------+ +-----------+
| Laptop | <--> | Jumphost | <--> | FooServer |
+--------+ +----------+ +-----------+
OR
+--------+ +----------+ +-----------+
| Laptop | <--> | Firewall | <--> | FooServer |
+--------+ +----------+ +-----------+
192.168.1.5 121.1.2.3 10.10.29.68
```
## Breaking changes
`v1.5.0`: change command timeout flag to `Duration`. See the following setting:
```diff
- name: scp files
image: appleboy/drone-scp
settings:
host:
- example1.com
- example2.com
username: ubuntu
password:
from_secret: ssh_password
port: 22
- command_timeout: 120
+ command_timeout: 2m
target: /home/deploy/web
source:
- release/*.tar.gz
```
## Build or Download a binary
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-scp/releases). Support the following OS type.
- Windows amd64/386
- Linux arm/amd64/386
- Darwin amd64/386
With `Go` installed
```sh
export GO111MODULE=on
go get -u -v github.com/appleboy/drone-scp
```
or build the binary with the following command:
```sh
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go test -cover ./...
go build -v -a -tags netgo -o release/linux/amd64/drone-scp .
```
## Docker
Build the docker image with the following commands:
```sh
make docker
```
## Usage
There are three ways to send notification.
- [usage from binary](#usage-from-binary)
- [usage from docker](#usage-from-docker)
- [usage from drone ci](#usage-from-drone-ci)
### Usage from binary
#### Using public key
```bash
drone-scp --host example.com \
--port 22 \
--username appleboy \
--key-path "${HOME}/.ssh/id_rsa" \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Using password
```diff
drone-scp --host example.com \
--port 22 \
--username appleboy \
+ --password xxxxxxx \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Using ssh-agent
Start your local ssh agent:
```bash
eval `ssh-agent -s`
```
Import your local public key `~/.ssh/id_rsa`
```sh
ssh-add
```
You don't need to add `--password` or `--key-path` arguments.
```bash
drone-scp --host example.com \
--port 22 \
--username appleboy \
--target /home/appleboy/test \
--source your_local_folder_path
```
#### Send multiple source or target folder and hosts
```diff
drone-scp --host example1.com \
+ --host example2.com \
--port 22 \
--username appleboy \
--password xxxxxxx
--target /home/appleboy/test1 \
+ --target /home/appleboy/test2 \
--source your_local_folder_path_1
+ --source your_local_folder_path_2
```
### Usage from docker
Using public key
```bash
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_KEY_PATH="${HOME}/.ssh/id_rsa"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Using password
```diff
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
+ -e SCP_PASSWORD="xxxxxxx"
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Using ssh-agent, start your local ssh agent:
```bash
eval `ssh-agent -s`
```
Import your local public key `~/.ssh/id_rsa`
```sh
ssh-add
```
You don't need to add `SCP_PASSWORD` or `SCP_KEY_PATH` arguments.
```bash
docker run --rm \
-e SCP_HOST=example.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST \
-e SCP_TARGET=TARGET_FOLDER_PATH \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
Send multiple source or target folder and hosts
```bash
docker run --rm \
-e SCP_HOST=example1.com,example2.com \
-e SCP_USERNAME=xxxxxxx \
-e SCP_PASSWORD=xxxxxxx \
-e SCP_PORT=22 \
-e SCP_SOURCE=SOURCE_FILE_LIST_1,SOURCE_FILE_LIST_2 \
-e SCP_TARGET=TARGET_FOLDER_PATH_1,TARGET_FOLDER_PATH_2 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
### Usage from drone ci
Execute from the working directory:
```bash
docker run --rm \
-e PLUGIN_HOST=example.com \
-e PLUGIN_USERNAME=xxxxxxx \
-e PLUGIN_PASSWORD=xxxxxxx \
-e PLUGIN_PORT=xxxxxxx \
-e PLUGIN_SOURCE=SOURCE_FILE_LIST \
-e PLUGIN_TARGET=TARGET_FOLDER_PATH \
-e PLUGIN_RM=false \
-e PLUGIN_DEBUG=true \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-scp
```
You can get more [information](http://plugins.drone.io/appleboy/drone-scp/) about how to use scp in drone.
## Testing
Test the package with the following command:
```sh
make test
```
+29
View File
@@ -0,0 +1,29 @@
disable-version-check: false
log-level: info
report:
fail-on-severity: critical,high,medium,low
format: ""
no-color: false
output: ""
report: security
severity: critical,high,medium,low,warning
rule:
disable-default-rules: false
only-rule: []
skip-rule: ["go_lang_logger_leak"]
scan:
context: ""
data_subject_mapping: ""
disable-domain-resolution: true
domain-resolution-timeout: 3s
exit-code: -1
external-rule-dir: []
force: false
hide_progress_bar: false
internal-domains: []
parallel: 0
quiet: false
scanner:
- sast
skip-path: []
skip-test: true
+1 -1
View File
@@ -1,4 +1,4 @@
FROM alpine:3.17
FROM alpine:3.21
ARG TARGETOS
ARG TARGETARCH
+13 -12
View File
@@ -1,27 +1,28 @@
module github.com/appleboy/drone-scp
go 1.18
go 1.25.9
require (
github.com/appleboy/com v0.1.7
github.com/appleboy/easyssh-proxy v1.3.10
github.com/fatih/color v1.15.0
github.com/appleboy/com v1.1.0
github.com/appleboy/easyssh-proxy v1.5.0
github.com/fatih/color v1.18.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.5
golang.org/x/crypto v0.9.0
github.com/urfave/cli/v2 v2.27.7
github.com/yassinebenaid/godump v0.11.1
golang.org/x/crypto v0.45.0
)
require (
github.com/ScaleFT/sshkeys v1.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/ScaleFT/sshkeys v1.4.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.1 // 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-isatty v0.0.19 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.8.0 // indirect
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
golang.org/x/sys v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+26 -36
View File
@@ -1,53 +1,43 @@
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
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.1.7/go.mod h1:JUK+oH0SXCLRH57pDMJx6VWVsm8CPdajalmRSWwamBE=
github.com/appleboy/easyssh-proxy v1.3.10 h1:iriF68tlrYoxgWhS7t7Wyr0FA+hJlOem5tMfm+RDlx4=
github.com/appleboy/easyssh-proxy v1.3.10/go.mod h1:T81pu/Cxx/zf/7YXhFCFiucBa4xeQ81ci5b0PFnMRJc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ScaleFT/sshkeys v1.4.0 h1:Yqd0cKA5PUvwV0dgRI67BDHGTsMHtGQBZbLXh1dthmE=
github.com/ScaleFT/sshkeys v1.4.0/go.mod h1:GineMkS8SEiELq8q5DzA2Wnrw65SqdD9a+hm8JOU1I4=
github.com/appleboy/com v1.1.0 h1:HLgRzhtj+4PLuFPPutKexd9zI9F74ymgWhkgPfPtnkc=
github.com/appleboy/com v1.1.0/go.mod h1:IbC1mLvqcIYn2YVNJgAYB9XnhbUh1xYKsOzdEOy0n+c=
github.com/appleboy/easyssh-proxy v1.5.0 h1:OYdSPvYQN3mhnsMH5I2OF1TgwSEcSq33kvjQfTwvZww=
github.com/appleboy/easyssh-proxy v1.5.0/go.mod h1:zcEMrStH91/tcUn3gUGP0KpQwUYLm8tX/Ook1AH98uc=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
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/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/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
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/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
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-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
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/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/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
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-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
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-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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yassinebenaid/godump v0.11.1 h1:SPujx/XaYqGDfmNh7JI3dOyCUVrG0bG2duhO3Eh2EhI=
github.com/yassinebenaid/godump v0.11.1/go.mod h1:dc/0w8wmg6kVIvNGAzbKH1Oa54dXQx8SNKh4dPRyW44=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
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/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+49 -25
View File
@@ -9,6 +9,7 @@ import (
"github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
"github.com/yassinebenaid/godump"
)
// Version set at compile-time
@@ -22,6 +23,10 @@ func main() {
_ = godotenv.Load(filename)
}
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
app := cli.NewApp()
app.Name = "Drone SCP"
app.Usage = "Copy files and artifacts via SSH."
@@ -39,102 +44,115 @@ func main() {
&cli.StringSliceFlag{
Name: "host",
Aliases: []string{"H"},
Usage: "connect to host",
Usage: "Remote server host address or IP",
EnvVars: []string{"PLUGIN_HOST", "SSH_HOST", "INPUT_HOST"},
FilePath: ".host",
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "connect to port",
Usage: "SSH port number (default: 22)",
EnvVars: []string{"PLUGIN_PORT", "SSH_PORT", "INPUT_PORT"},
Value: 22,
},
&cli.StringFlag{
Name: "protocol",
Usage: "Network protocol to use (tcp, tcp4, tcp6)",
EnvVars: []string{"PLUGIN_PROTOCOL", "SSH_PROTOCOL", "INPUT_PROTOCOL"},
Value: "tcp",
},
&cli.StringFlag{
Name: "username",
Aliases: []string{"user", "u"},
Usage: "connect as user",
Usage: "SSH username for authentication",
EnvVars: []string{"PLUGIN_USERNAME", "PLUGIN_USER", "SSH_USERNAME", "INPUT_USERNAME"},
Value: "root",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"P"},
Usage: "user password",
Usage: "SSH password for authentication",
EnvVars: []string{"PLUGIN_PASSWORD", "SSH_PASSWORD", "INPUT_PASSWORD"},
},
&cli.DurationFlag{
Name: "timeout",
Usage: "connection timeout",
Usage: "SSH connection timeout duration (default: 30s)",
EnvVars: []string{"PLUGIN_TIMEOUT", "SSH_TIMEOUT", "INPUT_TIMEOUT"},
Value: 30 * time.Second,
},
&cli.StringFlag{
Name: "ssh-key",
Usage: "private ssh key",
Usage: "SSH private key content for authentication",
EnvVars: []string{"PLUGIN_SSH_KEY", "PLUGIN_KEY", "SSH_KEY", "INPUT_KEY"},
},
&cli.StringFlag{
Name: "ssh-passphrase",
Usage: "The purpose of the passphrase is usually to encrypt the private key.",
Usage: "Passphrase to decrypt the SSH private key",
EnvVars: []string{"PLUGIN_SSH_PASSPHRASE", "PLUGIN_PASSPHRASE", "SSH_PASSPHRASE", "INPUT_PASSPHRASE"},
},
&cli.StringFlag{
Name: "key-path",
Aliases: []string{"i"},
Usage: "ssh private key path",
Usage: "Path to SSH private key file",
EnvVars: []string{"PLUGIN_KEY_PATH", "SSH_KEY_PATH", "INPUT_KEY_PATH"},
},
&cli.StringSliceFlag{
Name: "ciphers",
Usage: "The allowed cipher algorithms. If unspecified then a sensible",
Usage: "List of allowed SSH encryption algorithms",
EnvVars: []string{"PLUGIN_CIPHERS", "SSH_CIPHERS", "INPUT_CIPHERS"},
},
&cli.BoolFlag{
Name: "useInsecureCipher",
Usage: "include more ciphers with use_insecure_cipher",
Usage: "Enable less secure encryption algorithms (not recommended)",
EnvVars: []string{"PLUGIN_USE_INSECURE_CIPHER", "SSH_USE_INSECURE_CIPHER", "INPUT_USE_INSECURE_CIPHER"},
},
&cli.StringFlag{
Name: "fingerprint",
Usage: "fingerprint SHA256 of the host public key, default is to skip verification",
Usage: "SHA256 fingerprint of host public key for verification",
EnvVars: []string{"PLUGIN_FINGERPRINT", "SSH_FINGERPRINT", "INPUT_FINGERPRINT"},
},
&cli.DurationFlag{
Name: "command.timeout",
Usage: "command timeout",
Usage: "Maximum time allowed for command execution (default: 10m)",
EnvVars: []string{"PLUGIN_COMMAND_TIMEOUT", "SSH_COMMAND_TIMEOUT", "INPUT_COMMAND_TIMEOUT"},
Value: 10 * time.Minute,
},
&cli.StringSliceFlag{
Name: "target",
Aliases: []string{"t"},
Usage: "Target path on the server",
Usage: "Destination path on remote server",
EnvVars: []string{"PLUGIN_TARGET", "SSH_TARGET", "INPUT_TARGET"},
},
&cli.StringSliceFlag{
Name: "source",
Aliases: []string{"s"},
Usage: "scp file list",
Usage: "Local files/directories to copy",
EnvVars: []string{"PLUGIN_SOURCE", "SCP_SOURCE", "INPUT_SOURCE"},
},
&cli.BoolFlag{
Name: "rm",
Aliases: []string{"r"},
Usage: "remove target folder before upload data",
Usage: "Delete destination folder before copying",
EnvVars: []string{"PLUGIN_RM", "SCP_RM", "INPUT_RM"},
},
// Proxy settings remain the same as they are already clear
&cli.StringFlag{
Name: "proxy.host",
Usage: "connect to host of proxy",
Usage: "Proxy server host address or IP",
EnvVars: []string{"PLUGIN_PROXY_HOST", "PROXY_SSH_HOST", "INPUT_PROXY_HOST"},
},
&cli.StringFlag{
Name: "proxy.port",
Usage: "connect to port of proxy",
Usage: "Proxy server SSH port (default: 22)",
EnvVars: []string{"PLUGIN_PROXY_PORT", "PROXY_SSH_PORT", "INPUT_PROXY_PORT"},
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{
Name: "proxy.username",
Usage: "connect as user of proxy",
@@ -183,38 +201,38 @@ func main() {
},
&cli.IntFlag{
Name: "strip.components",
Usage: "Remove the specified number of leading path elements.",
Usage: "Strip N leading components from file paths",
EnvVars: []string{"PLUGIN_STRIP_COMPONENTS", "TAR_STRIP_COMPONENTS", "INPUT_STRIP_COMPONENTS"},
},
&cli.StringFlag{
Name: "tar.exec",
Usage: "Alternative `tar` executable to on the dest host",
Usage: "Custom tar executable path on remote host",
EnvVars: []string{"PLUGIN_TAR_EXEC", "SSH_TAR_EXEC", "INPUT_TAR_EXEC"},
Value: "tar",
},
&cli.StringFlag{
Name: "tar.tmp-path",
Usage: "Temporary path for tar file on the dest host",
Usage: "Temporary directory for tar files on remote host",
EnvVars: []string{"PLUGIN_TAR_TMP_PATH", "SSH_TAR_TMP_PATH", "INPUT_TAR_TMP_PATH"},
},
&cli.BoolFlag{
Name: "debug",
Usage: "remove target folder before upload data",
Usage: "Enable debug logging",
EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG"},
},
&cli.BoolFlag{
Name: "overwrite",
Usage: "use --overwrite flag with tar",
Usage: "Force overwrite of existing files",
EnvVars: []string{"PLUGIN_OVERWRITE", "INPUT_OVERWRITE"},
},
&cli.BoolFlag{
Name: "unlink.first",
Usage: "use --unlink-first flag with tar",
Usage: "Remove files before extracting new ones",
EnvVars: []string{"PLUGIN_UNLINK_FIRST", "INPUT_UNLINK_FIRST"},
},
&cli.BoolFlag{
Name: "tar.dereference",
Usage: "use --dereference flag with tar",
Usage: "Follow symbolic links when copying",
EnvVars: []string{"PLUGIN_TAR_DEREFERENCE", "INPUT_TAR_DEREFERENCE"},
},
}
@@ -261,7 +279,8 @@ func run(c *cli.Context) error {
plugin := Plugin{
Config: Config{
Host: c.StringSlice("host"),
Port: c.String("port"),
Port: c.Int("port"),
Protocol: easyssh.Protocol(c.String("protocol")),
Username: c.String("username"),
Password: c.String("password"),
Passphrase: c.String("ssh-passphrase"),
@@ -291,6 +310,7 @@ func run(c *cli.Context) error {
Password: c.String("proxy.password"),
Server: c.String("proxy.host"),
Port: c.String("proxy.port"),
Protocol: easyssh.Protocol(c.String("proxy.protocol")),
Timeout: c.Duration("proxy.timeout"),
Ciphers: c.StringSlice("proxy.ciphers"),
UseInsecureCipher: c.Bool("proxy.useInsecureCipher"),
@@ -298,5 +318,9 @@ func run(c *cli.Context) error {
},
}
if plugin.Config.Debug {
_ = godump.Dump(plugin)
}
return plugin.Exec()
}
+1 -1
View File
@@ -8,5 +8,5 @@ import (
)
func getRealPath(path string) string {
return "/" + strings.Replace(strings.Replace(path, ":", "", -1), "\\", "/", -1)
return "/" + strings.ReplaceAll(strings.ReplaceAll(path, ":", ""), "\\", "/")
}
+16 -14
View File
@@ -26,7 +26,8 @@ type (
// Config for the plugin.
Config struct {
Host []string
Port string
Port int
Protocol easyssh.Protocol
Username string
Password string
Key string
@@ -115,12 +116,14 @@ func (p *Plugin) removeDestFile(os string, ssh *easyssh.MakeConfig) 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{
Server: host,
User: p.Config.Username,
Password: p.Config.Password,
Port: p.Config.Port,
Port: port,
Protocol: p.Config.Protocol,
Key: p.Config.Key,
KeyPath: p.Config.KeyPath,
Passphrase: p.Config.Passphrase,
@@ -133,6 +136,7 @@ func (p *Plugin) removeAllDestFile() error {
User: p.Config.Proxy.User,
Password: p.Config.Proxy.Password,
Port: p.Config.Proxy.Port,
Protocol: p.Config.Proxy.Protocol,
Key: p.Config.Proxy.Key,
KeyPath: p.Config.Proxy.KeyPath,
Passphrase: p.Config.Proxy.Passphrase,
@@ -230,7 +234,7 @@ func (p *Plugin) Exec() error {
return errMissingHost
}
p.DestFile = fmt.Sprintf("%s.tar.gz", random.String(10))
p.DestFile = random.String(10) + ".tar.gz"
// create a temporary file for the archive
dir := os.TempDir()
@@ -306,7 +310,7 @@ func (p *Plugin) Exec() error {
}
for _, target := range p.Config.Target {
target = strings.Replace(target, " ", "\\ ", -1)
target = strings.ReplaceAll(target, " ", "\\ ")
// remove target folder before upload data
if p.Config.Remove {
p.log(host, "Remove target folder:", target)
@@ -326,7 +330,7 @@ func (p *Plugin) Exec() error {
}
if len(errStr) != 0 {
errChannel <- fmt.Errorf(errStr)
errChannel <- fmt.Errorf("%s", errStr)
return
}
@@ -372,7 +376,8 @@ func (p *Plugin) Exec() error {
if err != nil {
c := color.New(color.FgRed)
c.Println("drone-scp error: ", err)
if _, ok := err.(copyError); !ok {
var cerr copyError
if !errors.As(err, &cerr) {
fmt.Println("drone-scp rollback: remove all target tmp file")
if err := p.removeAllDestFile(); err != nil {
return err
@@ -389,19 +394,16 @@ func (p *Plugin) Exec() error {
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) {
// Split the host string by colon (":") to get the host and port
hosts := strings.Split(host, ":")
// Get the default port from the Plugin's Config field
port := p.Config.Port
// If the host string contains a port (i.e. it has more than one element after splitting), set the port to that value
if len(hosts) > 1 {
port := strconv.Itoa(p.Config.Port)
if len(hosts) > 1 &&
(p.Config.Protocol == easyssh.PROTOCOL_TCP ||
p.Config.Protocol == easyssh.PROTOCOL_TCP4) {
host = hosts[0]
port = hosts[1]
}
// Return the host and port as separate strings
return host, port
}
+130 -16
View File
@@ -1,6 +1,7 @@
package main
import (
"io"
"log"
"os"
"os/exec"
@@ -41,7 +42,7 @@ func TestMissingSourceConfig(t *testing.T) {
Config: Config{
Host: []string{"example.com"},
Username: "ubuntu",
Port: "443",
Port: 443,
Password: "1234",
},
}
@@ -81,7 +82,7 @@ func TestSCPFileFromPublicKey(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{filepath.Join(u.HomeDir, "/test")},
@@ -131,7 +132,7 @@ func TestSCPFileFromPublicKeyWithPassphrase(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/test",
Passphrase: "1234",
Source: []string{"tests/a.txt", "tests/b.txt"},
@@ -164,7 +165,7 @@ func TestWrongFingerprint(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{filepath.Join(u.HomeDir, "/test2")},
@@ -188,7 +189,6 @@ func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) {
}
pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf)
if err != nil {
return nil, err
}
@@ -215,7 +215,7 @@ func TestSCPFileFromPublicKeyWithFingerprint(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Fingerprint: ssh.FingerprintSHA256(hostKey),
Source: []string{"tests/a.txt", "tests/b.txt"},
@@ -254,7 +254,7 @@ func TestSCPWildcardFileList(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
Target: []string{filepath.Join(u.HomeDir, "abc")},
@@ -286,7 +286,7 @@ func TestSCPFromProxySetting(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
Target: []string{filepath.Join(u.HomeDir, "def")},
@@ -330,7 +330,7 @@ func TestStripComponentsFlag(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
StripComponents: 2,
@@ -363,7 +363,7 @@ func TestUseInsecureCipherFlag(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
StripComponents: 2,
@@ -403,7 +403,7 @@ func TestIgnoreList(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
StripComponents: 2,
@@ -483,7 +483,7 @@ func TestIncorrectPassword(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
Password: "123456",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/home"},
@@ -506,7 +506,7 @@ func TestNoPermissionCreateFolder(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/a.txt", "tests/b.txt"},
Target: []string{"/etc/test"},
@@ -782,7 +782,7 @@ func TestTargetFolderWithSpaces(t *testing.T) {
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: "22",
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
StripComponents: 2,
@@ -821,7 +821,8 @@ func TestHostPortString(t *testing.T) {
Config: Config{
Host: []string{"localhost:22", "localhost:22"},
Username: "drone-scp",
Port: "8080",
Protocol: easyssh.PROTOCOL_TCP4,
Port: 8080,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*"},
StripComponents: 2,
@@ -848,7 +849,8 @@ func TestHostPortString(t *testing.T) {
func TestHostPort(t *testing.T) {
p := Plugin{
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)
}
}
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)
}
}