From acdf14d29e2df6b73e9553862ecef9cc7ff9a4dd Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Sun, 12 Jan 2025 11:04:11 +0100 Subject: [PATCH] Update the release flow and GH action --- .github/workflows/releases.yml | 54 ++++++++++++++++------------------ main.go | 4 ++- scripts/get.sh | 28 ++++++++++++++++++ 3 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 scripts/get.sh diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index aa9fef9..0c5fb63 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -10,6 +10,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} strategy: matrix: # build targets @@ -20,47 +22,43 @@ jobs: goarch: '386' - goos: darwin goarch: amd64 + - goos: darwin + goarch: arm64 steps: - name: Checkout source code - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v4 with: - lfs: true fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.23 + + - name: Check if the version string was updated + run: | + VERSION=$(echo ${GITHUB_REF} | awk -F/ '{print substr($3,2,10);}') + grep "var version string = \"$VERSION\"" main.go || echo "The version string inside main.go should be updated to $VERSION" && exit 1 - - name: Build for Linux-amd64 + - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }} env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} - run: | - v=$(echo ${GITHUB_REF} | awk -F/ '{print substr($3,2,10);}') - go build -x -v -mod=vendor -ldflags "-X main.version=${v} -w -s" -o "tty-share_${GOOS}-${GOARCH}" + go build -x -v -mod=vendor -o "tty-share_${GOOS}-${GOARCH}" - - name: Upload to artifact storage - uses: actions/upload-artifact@v2 + - name: Release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/heads/tmp_dev') with: - path: tty-share_${{ matrix.goos }}-${{ matrix.goarch }} - if-no-files-found: error - # only meant for sharing with the publish job - retention-days: 1 + files: tty-share_* + + - name: Get tty-share + if: ${{ matrix.goarch == 'arm64' }} + run: | + curl -L https://github.com/elisescu/tty-share/releases/download/v2.4.0/tty-share_linux-amd64 -o tty-share + chmod u+x ./tty-share + export TERM=xterm-256color + ./tty-share -A --public --headless --headless-cols 255 --headless-rows 50 --no-wait --listen :8001 - publish: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v2 - with: - path: tty-share_* - - uses: "marvinpinto/action-automatic-releases@latest" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false - files: | - tty-share_* - id: "automatic_releases" diff --git a/main.go b/main.go index f6545c4..8904b4b 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,9 @@ import ( log "github.com/sirupsen/logrus" ) -var version string = "0.0.0" +// This should be updated manually. Most of distro packagers prefer to build golang without +// complex linker flags that could set the version from the outside +var version string = "2.4.0" func createServer(frontListenAddress string, frontendPath string, pty server.PTYHandler, sessionID string, allowTunneling bool, crossOrigin bool, baseUrlPath string) *server.TTYServer { config := ttyServer.TTYServerConfig{ diff --git a/scripts/get.sh b/scripts/get.sh new file mode 100644 index 0000000..7fca6e8 --- /dev/null +++ b/scripts/get.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env sh +OS=$(uname -s) +ARCH=$(uname -m) + +# Detect OS +case "$OS" in + Linux*) OS_NAME="linux";; + Darwin*) OS_NAME="darwin";; + *) echo "Unsupported OS: $OS"; exit 1;; +esac + +# Detect architecture +case "$ARCH" in + x86_64) ARCH_NAME="amd64";; + i386) ARCH_NAME="386";; + arm64) ARCH_NAME="arm64";; + *) echo "Unsupported architecture: $ARCH"; exit 1;; +esac + +# Construct the binary name (adjust to match your artifact naming) +BINARY="tty-share_${OS_NAME}-${ARCH_NAME}" +DOWNLOAD_URL="https://github.com/elisescu/tty-share/releases/latest/download/${BINARY}" + +echo "Downloading ${DOWNLOAD_URL} ..." + +# Download the appropriate binary +curl -sL ${DOWNLOAD_URL} -o "${tty-share}" +chmod +x "${tty-share}"