diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f3f1b63 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,38 @@ +on: [push] + +name: build + +jobs: + build: + runs-on: ubuntu-22.04 + strategy: + matrix: + arch: + - amd64 + - arm64 + os: + - linux + go-version: + - 1.15 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '${{ matrix.go-version }}' + + # build {{ + - name: make deps + run: make deps + - name: make build + run: make build CGO_ENABLED=0 GOARCH=${{ matrix.arch }} GOVVV_PKG=${{ github.repository_owner }}/${{ github.event.repository.name }} + # }} + + - name: debug + run: | + ls -al + ls -al deps/ + + - uses: actions/upload-artifact@v3 + with: + name: xc.${{ matrix.os }}-${{ matrix.arch }} + path: bin/xc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..eb41ea8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,127 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: release + +jobs: + create_release: + name: create release + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + - name: create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + build: + runs-on: ubuntu-22.04 + needs: create_release + strategy: + matrix: + arch: + - amd64 + #- arm64 + os: + - linux + go-version: + - 1.15 + include: + - arch: amd64 + rpm_arch: x86_64 + # - arch: arm64 + # rpm_arch: aarch64 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '${{ matrix.go-version }}' + + # build {{ + - name: make deps + run: make deps + - name: make build + run: make build CGO_ENABLED=0 GOARCH=${{ matrix.arch }} GOVVV_PKG=${{ github.repository_owner }}/${{ github.event.repository.name }} + # }} + + - name: debug + run: | + ls -al + ls -al deps/ + + - name: get release version + id: release-version + run: | + echo "$GITHUB_REF_NAME" | sed 's|^[a-zA-Z]\+|RELEASE_VERSION=|' >> $GITHUB_OUTPUT + + # create asset {{ + - name: create archives + run: | + zip --junk-paths ${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.zip bin/* + tar --create --gzip --verbose --exclude='.gitignore' --file=${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.tgz --directory=bin/ . + - name: create package deb + uses: bpicode/github-action-fpm@master + with: + fpm_opts: "--debug --name ${{ github.event.repository.name }} --output-type deb --version ${{ steps.release-version.outputs.RELEASE_VERSION }} --architecture ${{ matrix.arch }} --exclude '*/.gitignore' --exclude '*/.git' --input-type dir" + fpm_args: "./bin" + - name: create package rpm + uses: bpicode/github-action-fpm@master + with: + fpm_opts: "--debug --name ${{ github.event.repository.name }} --output-type rpm --version ${{ steps.release-version.outputs.RELEASE_VERSION }} --architecture ${{ matrix.rpm_arch }} --exclude '*/.gitignore' --exclude '*/.git' --input-type dir" + fpm_args: "./bin" + # }} + + - name: debug + run: | + ls -al ./ + + # upload-release-asset {{ + - name: upload-release-asset zip + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.zip + asset_name: ${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.zip + asset_content_type: application/zip + + - name: upload-release-asset tgz + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.tgz + asset_name: ${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}.${{ matrix.os }}-${{ matrix.arch }}.tgz + asset_content_type: application/gzip + + - name: upload-release-asset deb + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ github.event.repository.name }}_${{ steps.release-version.outputs.RELEASE_VERSION }}_${{ matrix.arch }}.deb + asset_name: ${{ github.event.repository.name }}_${{ steps.release-version.outputs.RELEASE_VERSION }}_${{ matrix.arch }}.deb + asset_content_type: application/octet-stream + + - name: upload-release-asset rpm + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}-1.${{ matrix.rpm_arch }}.rpm + asset_name: ${{ github.event.repository.name }}-${{ steps.release-version.outputs.RELEASE_VERSION }}-1.${{ matrix.rpm_arch }}.rpm + asset_content_type: application/octet-stream + # }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e6d48c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: all deps build +export PATH:=deps:$(PATH) +export CGO_ENABLED:=0 +export GOOS:=linux +export GOARCH:=amd64 +GOVVV_PKG:=main + +all: deps build + +deps: + go mod download + go build -o deps/govvv github.com/ahmetb/govvv + +build: + @$(eval FLAGS := $$(shell PATH=$(PATH) govvv -flags -pkg $(GOVVV_PKG) )) + go build \ + -o bin/xc \ + -ldflags="$(FLAGS)" \ + cmd/xc/main.go diff --git a/go.mod b/go.mod index 40ba174..93c7211 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/viert/sekwence v0.0.0-20190110111110-24bab1ce82a0 golang.org/x/crypto v0.1.0 gopkg.in/cheggaaa/pb.v1 v1.0.28 + github.com/ahmetb/govvv v0.3.0 ) go 1.15 diff --git a/go.sum b/go.sum index 9386566..69bd93b 100644 --- a/go.sum +++ b/go.sum @@ -64,3 +64,5 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/cheggaaa/pb.v1 v1.0.28 h1:n1tBJnnK2r7g9OW2btFH91V92STTUevLXYFb8gy9EMk= gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +github.com/ahmetb/govvv v0.3.0 h1:YGLGwEyiUwHFy5eh/RUhdupbuaCGBYn5T5GWXp+WJB0= +github.com/ahmetb/govvv v0.3.0/go.mod h1:4WRFpdWtc/YtKgPFwa1dr5+9hiRY5uKAL08bOlxOR6s= diff --git a/remote/serial.go b/remote/serial.go index 51e19f4..8c47846 100644 --- a/remote/serial.go +++ b/remote/serial.go @@ -15,6 +15,7 @@ import ( "github.com/viert/xc/log" "github.com/viert/xc/term" "golang.org/x/crypto/ssh/terminal" + "golang.org/x/sys/unix" ) func forwardUserInput(in *poller.FD, out *os.File, stopped *bool) { @@ -146,7 +147,7 @@ func runAtHost(host string, cmd *exec.Cmd, r *ExecResult) { defer func() { log.Debug("Setting stdin back to blocking mode") si.Close() - syscall.Dup2(stdinBackup, int(os.Stdin.Fd())) + unix.Dup2(stdinBackup,int(os.Stdin.Fd())) syscall.SetNonblock(int(os.Stdin.Fd()), false) }() @@ -231,7 +232,7 @@ func RunSerial(hosts []string, argv string, delay int) *ExecResult { execLoop: for i, host := range hosts { - msg := term.HR(7) + " " + host + " " + term.HR(36-len(host)) + msg := term.HR(7) + " " + host + " " + term.HR(136-len(host)) fmt.Println(term.Blue(msg)) if argv != "" {