Compare commits

...

20 Commits

Author SHA1 Message Date
appleboy 37b95a017d chore: upgrade Go and dependencies to improve compatibility
- Update Go version from 1.22 to 1.23
- Upgrade golang.org/x/crypto from version 0.29.0 to 0.36.0
- Upgrade golang.org/x/sys from version 0.27.0 to 0.31.0
- Change Docker image in GitHub Actions from golang:1.22-alpine to golang:1.23-alpine

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-09 21:43:05 +08:00
appleboy 1fabfc4f97 chore: implement debug functionality with godump integration
- Add a new dependency on `github.com/yassinebenaid/godump`
- Include `godump` in the import statements
- Add a new environment variable `DEBUG` to the existing list
- Implement a debug dump of the plugin if debugging is enabled

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-09 21:42:02 +08:00
Bo-Yi Wu 883f947b4f chore(log): remove prefix out: and err: prefix (#287)
- Simplify log output by removing "out:" and "err:" prefixes in `plugin.go`
- Update test expectations to match the new log output format

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-11-17 14:48:14 +08:00
appleboy 2c52afb7fd fix: improve script file handling and testing robustness
- Add a check to verify if the script file exists before reading it

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-11-17 14:32:06 +08:00
appleboy d56db7a5b3 chore(deps): update dependencies to latest versions
- Update `github.com/urfave/cli/v2` to version `2.27.5`
- Update `golang.org/x/crypto` to version `0.29.0`
- Update `github.com/cpuguy83/go-md2man/v2` to version `2.0.5`
- Update `golang.org/x/sys` to version `0.27.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-11-17 14:18:47 +08:00
appleboy 67cd964f13 ci(github): improve CI workflows and API integration
- Add `fetch-depth: 0` to the `actions/checkout` step in the `goreleaser` GitHub workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-11-16 10:05:31 +08:00
appleboy 2519a9a894 ci(golangci): enable comprehensive linting and update variable initialization
- Add a `.golangci.yaml` configuration file with various linters enabled and specific settings for `gosec` and `perfsprint`.
- Change `isTimeout` from being initialized to `true` to being declared as a `bool` variable without an initial value in `plugin.go`.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-11-16 09:58:21 +08:00
appleboy 1edb4744ca feat(envs): support drone plugin
- Add `PLUGIN_SCRIPT_FILE` to the environment variables list in the main function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-27 22:22:23 +08:00
Kyle Leonhard 43270d582c chore: add support for passing commands via a file (#285) 2024-10-24 09:56:07 +08:00
Lukáš Tesař dc927a6123 fix: typo in success message (#283)
My OCD just kicks in :)) This has bothered me for a long time. Will also update README in https://github.com/appleboy/ssh-action to reflect this change.
2024-10-13 09:00:20 +08:00
Bo-Yi Wu ceb4e12d92 chore: update base image to Alpine 3.20
- Update base image from alpine version 3.17 to 3.20

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-09-07 15:15:40 +08:00
Bo-Yi Wu 2041794fd5 ci: update Go version and enhance GitHub Actions workflow
- Update Go version in GitHub Actions workflow from 1.21 to 1.22

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:42:01 +08:00
Bo-Yi Wu a2d37cbc1d chore: update dependencies and improve test coverage
- Update Go version from 1.18 to 1.22 in go.mod

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:35:48 +08:00
Bo-Yi Wu aa872a30be style: refactor import aliases for easyssh library
- Alias `github.com/appleboy/easyssh-proxy` import as `easyssh` in `main.go`
- Alias `github.com/appleboy/easyssh-proxy` import as `easyssh` in `plugin.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:30:53 +08:00
Bo-Yi Wu c049944302 chore: update Go dependencies to latest versions
- Update `golang.org/x/crypto` dependency from `v0.24.0` to `v0.25.0`
- Update `golang.org/x/sys` dependency from `v0.21.0` to `v0.22.0`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 15:25:54 +08:00
Bo-Yi Wu 0914cd212b test: enable comprehensive debugging in plugin execution (#278)
* test: enable comprehensive debugging in plugin execution

- Add debug logging to `exec` function in `plugin.go`
- Enable debug mode in `TestCommandOutput` and `TestSudoCommand` tests
- Remove redundant command blocks from multiple tests in `plugin_test.go`

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

* test: refactor codebase to improve performance and readability

- Remove debug command block from `TestSudoCommand` test

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

* refactor: refactor test environment setup and command markers

- Add environment markers to `TestCommandOutput` for localhost and 127.0.0.1
- Remove command markers from `TestFingerprint`

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

* fix: improve environment variable handling in debug mode

- Add a check for non-empty environment variables when debug mode is enabled
- Remove redundant environment variable output in tests

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

---------

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

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-07-14 14:23:53 +08:00
Bo-Yi Wu c0e111cbef ci: update GoReleaser action to version 6
- Update GoReleaser action from version 5 to version 6

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-12 15:06:46 +08:00
Bo-Yi Wu 50e34882a3 chore: update Go dependencies to latest versions
- Update `golang.org/x/crypto` dependency from v0.23.0 to v0.24.0
- Update `golang.org/x/sys` dependency from v0.20.0 to v0.21.0

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-05 13:31:31 +08:00
appleboy 31607874dc chore: update dependencies to latest versions
- Update `github.com/urfave/cli/v2` to version `2.27.2`
- Update `golang.org/x/crypto` to version `0.23.0`
- Update `github.com/xrash/smetrics` to version `0.0.0-20240521201337-686a1a2994c1`
- Update `golang.org/x/sys` to version `0.20.0`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-06-01 10:08:07 +08:00
10 changed files with 138 additions and 96 deletions
+7 -8
View File
@@ -26,23 +26,22 @@ jobs:
- 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 - name: Set up QEMU
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v2 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@v2 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
@@ -50,7 +49,7 @@ jobs:
- 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 }}
@@ -62,10 +61,10 @@ jobs:
type=semver,pattern={{major}} type=semver,pattern={{major}}
- name: Build and push - name: Build and push
uses: docker/build-push-action@v4 uses: docker/build-push-action@v6
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 }}
+3 -1
View File
@@ -14,6 +14,8 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup go - name: Setup go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
@@ -22,7 +24,7 @@ jobs:
check-latest: true check-latest: true
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5 uses: goreleaser/goreleaser-action@v6
with: with:
# either 'goreleaser' (default) or 'goreleaser-pro' # either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser distribution: goreleaser
+1 -1
View File
@@ -31,7 +31,7 @@ jobs:
testing: testing:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: golang:1.21-alpine image: golang:1.23-alpine
options: --sysctl net.ipv6.conf.all.disable_ipv6=0 options: --sysctl net.ipv6.conf.all.disable_ipv6=0
steps: steps:
- name: Checkout repository - name: Checkout repository
+42
View File
@@ -0,0 +1,42 @@
run:
timeout: 5m
linters:
enable:
- asciicheck
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- goimports
- gosec
- misspell
- nakedret
- nilerr
- nolintlint
- perfsprint
- revive
- usestdlibvars
- wastedassign
linters-settings:
gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
# Default: [] - means include all rules
includes:
- G102
- G106
- G108
- G109
- G111
- G112
- G201
- G203
perfsprint:
err-error: true
errorf: true
int-conversion: true
sprintf1: true
strconcat: true
+1 -1
View File
@@ -1,4 +1,4 @@
FROM alpine:3.17 FROM alpine:3.20
ARG TARGETOS ARG TARGETOS
ARG TARGETARCH ARG TARGETARCH
+7 -6
View File
@@ -1,23 +1,24 @@
module github.com/appleboy/drone-ssh module github.com/appleboy/drone-ssh
go 1.18 go 1.23.0
require ( require (
github.com/appleboy/easyssh-proxy v1.5.0 github.com/appleboy/easyssh-proxy v1.5.0
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.27.1 github.com/urfave/cli/v2 v2.27.5
golang.org/x/crypto v0.22.0 github.com/yassinebenaid/godump v0.11.1
golang.org/x/crypto v0.36.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.4 // 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/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-20240312152122-5f08fbb34913 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.19.0 // indirect golang.org/x/sys v0.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
+14 -11
View File
@@ -2,8 +2,8 @@ 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/easyssh-proxy v1.5.0 h1:OYdSPvYQN3mhnsMH5I2OF1TgwSEcSq33kvjQfTwvZww= 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/appleboy/easyssh-proxy v1.5.0/go.mod h1:zcEMrStH91/tcUn3gUGP0KpQwUYLm8tX/Ook1AH98uc=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/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=
@@ -19,21 +19,24 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 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/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/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.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.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
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.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
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=
+24 -2
View File
@@ -6,9 +6,10 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/appleboy/easyssh-proxy" easyssh "github.com/appleboy/easyssh-proxy"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.com/yassinebenaid/godump"
) )
// Version set at compile-time // Version set at compile-time
@@ -131,6 +132,11 @@ func main() {
Usage: "execute single commands for github action", Usage: "execute single commands for github action",
EnvVars: []string{"INPUT_SCRIPT"}, EnvVars: []string{"INPUT_SCRIPT"},
}, },
&cli.StringFlag{
Name: "script.file",
Usage: "execute commands from a file for github action",
EnvVars: []string{"PLUGIN_SCRIPT_FILE", "INPUT_SCRIPT_FILE"},
},
&cli.BoolFlag{ &cli.BoolFlag{
Name: "script.stop", Name: "script.stop",
Usage: "stop script after first failure", Usage: "stop script after first failure",
@@ -207,7 +213,7 @@ func main() {
&cli.BoolFlag{ &cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "debug mode", Usage: "debug mode",
EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG"}, EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG", "DEBUG"},
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "envs.format", Name: "envs.format",
@@ -271,6 +277,18 @@ func run(c *cli.Context) error {
scripts = append(scripts, s) scripts = append(scripts, s)
} }
if f := c.String("script.file"); f != "" {
// check file exists
if _, err := os.Stat(f); err != nil {
return err
}
s, err := os.ReadFile(f)
if err != nil {
return err
}
scripts = append(scripts, string(s))
}
plugin := Plugin{ plugin := Plugin{
Config: Config{ Config: Config{
Key: c.String("ssh-key"), Key: c.String("ssh-key"),
@@ -312,5 +330,9 @@ func run(c *cli.Context) error {
Writer: os.Stdout, Writer: os.Stdout,
} }
if plugin.Config.Debug {
_ = godump.Dump(plugin)
}
return plugin.Exec() return plugin.Exec()
} }
+13 -11
View File
@@ -10,7 +10,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/appleboy/easyssh-proxy" easyssh "github.com/appleboy/easyssh-proxy"
) )
var ( var (
@@ -105,9 +105,11 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
}, },
} }
p.log(host, "======CMD======") if p.Config.Debug {
p.log(host, strings.Join(p.Config.Script, "\n")) p.log(host, "======CMD======")
p.log(host, "======END======") p.log(host, strings.Join(p.Config.Script, "\n"))
p.log(host, "======END======")
}
env := []string{} env := []string{}
if p.Config.AllEnvs { if p.Config.AllEnvs {
@@ -123,7 +125,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
p.Config.Script = append(env, p.scriptCommands()...) p.Config.Script = append(env, p.scriptCommands()...)
if p.Config.Debug { if p.Config.Debug && len(env) > 0 {
p.log(host, "======ENV======") p.log(host, "======ENV======")
p.log(host, strings.Join(env, "\n")) p.log(host, strings.Join(env, "\n"))
p.log(host, "======END======") p.log(host, "======END======")
@@ -135,7 +137,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
return return
} }
// read from the output channel until the done signal is passed // read from the output channel until the done signal is passed
isTimeout := true var isTimeout bool
loop: loop:
for { for {
select { select {
@@ -143,11 +145,11 @@ loop:
break loop break loop
case outline := <-stdoutChan: case outline := <-stdoutChan:
if outline != "" { if outline != "" {
p.log(host, "out:", outline) p.log(host, outline)
} }
case errline := <-stderrChan: case errline := <-stderrChan:
if errline != "" { if errline != "" {
p.log(host, "err:", errline) p.log(host, errline)
} }
case err = <-errChan: case err = <-errChan:
} }
@@ -228,9 +230,9 @@ func (p Plugin) Exec() error {
} }
} }
fmt.Println("==============================================") fmt.Println("===============================================")
fmt.Println("✅ Successfully executed commands to all host.") fmt.Println("✅ Successfully executed commands to all hosts.")
fmt.Println("==============================================") fmt.Println("===============================================")
return nil return nil
} }
+26 -55
View File
@@ -365,17 +365,17 @@ func TestCommandOutput(t *testing.T) {
whoami whoami
uname uname
localhost: ======END====== localhost: ======END======
localhost: out: /home/drone-scp localhost: /home/drone-scp
localhost: out: drone-scp localhost: drone-scp
localhost: out: Linux localhost: Linux
127.0.0.1: ======CMD====== 127.0.0.1: ======CMD======
127.0.0.1: pwd 127.0.0.1: pwd
whoami whoami
uname uname
127.0.0.1: ======END====== 127.0.0.1: ======END======
127.0.0.1: out: /home/drone-scp 127.0.0.1: /home/drone-scp
127.0.0.1: out: drone-scp 127.0.0.1: drone-scp
127.0.0.1: out: Linux 127.0.0.1: Linux
` `
) )
@@ -392,6 +392,7 @@ func TestCommandOutput(t *testing.T) {
}, },
CommandTimeout: 60 * time.Second, CommandTimeout: 60 * time.Second,
Sync: true, Sync: true,
Debug: true,
}, },
Writer: &buffer, Writer: &buffer,
} }
@@ -443,10 +444,7 @@ func TestFingerprint(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== drone-scp
whoami
======END======
out: drone-scp
` `
) )
@@ -477,11 +475,7 @@ func TestScriptStopWithMultipleHostAndSyncMode(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== mkdir: can't create directory 'a/b/c': No such file or directory
mkdir a/b/c
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory
` `
) )
@@ -512,11 +506,7 @@ func TestScriptStop(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== mkdir: can't create directory 'a/b/c': No such file or directory
mkdir a/b/c
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory
` `
) )
@@ -546,12 +536,8 @@ func TestNoneScriptStop(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== mkdir: can't create directory 'a/b/c': No such file or directory
mkdir a/b/c mkdir: can't create directory 'd/e/f': No such file or directory
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory
err: mkdir: can't create directory 'd/e/f': No such file or directory
` `
) )
@@ -598,13 +584,13 @@ func TestEnvOutput(t *testing.T) {
export ENV_6='test"' export ENV_6='test"'
export ENV_7='test,!#;?.@$~'\''"' export ENV_7='test,!#;?.@$~'\''"'
======END====== ======END======
out: [test] [test]
out: [test test] [test test]
out: [test ] [test ]
out: [ test test ] [ test test ]
out: [test'] [test']
out: [test"] [test"]
out: [test,!#;?.@$~'"] [test,!#;?.@$~'"]
` `
) )
@@ -733,12 +719,8 @@ func TestUseInsecureCipher(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== mkdir: can't create directory 'a/b/c': No such file or directory
mkdir a/b/c mkdir: can't create directory 'd/e/f': No such file or directory
mkdir d/e/f
======END======
err: mkdir: can't create directory 'a/b/c': No such file or directory
err: mkdir: can't create directory 'd/e/f': No such file or directory
` `
) )
@@ -889,14 +871,9 @@ func TestAllEnvs(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== [foobar]
echo "[${INPUT_1}]" [foobar]
echo "[${GITHUB_2}]" [foobar]
echo "[${PLUGIN_3}]"
======END======
out: [foobar]
out: [foobar]
out: [foobar]
` `
) )
@@ -938,10 +915,7 @@ func TestSudoCommand(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== root
sudo su - -c "whoami"
======END======
out: root
` `
) )
@@ -968,10 +942,7 @@ func TestCommandWithIPv6(t *testing.T) {
var ( var (
buffer bytes.Buffer buffer bytes.Buffer
expected = ` expected = `
======CMD====== drone-scp
whoami
======END======
out: drone-scp
` `
) )