mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-09 18:23:21 +08:00
chore(release): support multiple platform
This commit is contained in:
parent
f11e2ed931
commit
1dcc9acbe5
@ -248,8 +248,9 @@ platform:
|
|||||||
os: linux
|
os: linux
|
||||||
steps:
|
steps:
|
||||||
- commands:
|
- commands:
|
||||||
|
- export PATH=$PATH:$GOPATH/bin
|
||||||
- make release
|
- make release
|
||||||
image: golang:1.18
|
image: techknowlogick/xgo:go-1.18.x
|
||||||
name: build-all-binary
|
name: build-all-binary
|
||||||
pull: always
|
pull: always
|
||||||
when:
|
when:
|
||||||
|
39
.github/workflows/go.yml
vendored
39
.github/workflows/go.yml
vendored
@ -23,3 +23,42 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: v1.46.2
|
version: v1.46.2
|
||||||
args: --verbose
|
args: --verbose
|
||||||
|
|
||||||
|
# build:
|
||||||
|
# strategy:
|
||||||
|
# matrix:
|
||||||
|
# os: [ubuntu-latest]
|
||||||
|
# go: [ 1.18]
|
||||||
|
# include:
|
||||||
|
# - os: ubuntu-latest
|
||||||
|
# go-build: ~/.cache/go-build
|
||||||
|
# name: ${{ matrix.os }} @ Go ${{ matrix.go }}
|
||||||
|
# runs-on: ${{ matrix.os }}
|
||||||
|
# env:
|
||||||
|
# GO111MODULE: on
|
||||||
|
# GOPROXY: https://proxy.golang.org
|
||||||
|
# steps:
|
||||||
|
# - name: Set up Go ${{ matrix.go }}
|
||||||
|
# uses: actions/setup-go@v3
|
||||||
|
# with:
|
||||||
|
# go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
# - name: Checkout Code
|
||||||
|
# uses: actions/checkout@v3
|
||||||
|
# with:
|
||||||
|
# ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
# - uses: actions/cache@v3
|
||||||
|
# with:
|
||||||
|
# path: |
|
||||||
|
# ${{ matrix.go-build }}
|
||||||
|
# ~/go/pkg/mod
|
||||||
|
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
# restore-keys: |
|
||||||
|
# ${{ runner.os }}-go-
|
||||||
|
# - name: initial docker
|
||||||
|
# uses: docker-practice/actions-setup-docker@master
|
||||||
|
# - name: build all binaries
|
||||||
|
# run: |
|
||||||
|
# set -x
|
||||||
|
# make release
|
||||||
|
34
.github/workflows/goreleaser.yml
vendored
Normal file
34
.github/workflows/goreleaser.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: Goreleaser
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
goreleaser:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
-
|
||||||
|
name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.18
|
||||||
|
-
|
||||||
|
name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v3
|
||||||
|
with:
|
||||||
|
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||||
|
distribution: goreleaser
|
||||||
|
version: latest
|
||||||
|
args: release --rm-dist
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ coverage.txt
|
|||||||
release
|
release
|
||||||
drone-ssh
|
drone-ssh
|
||||||
.cover
|
.cover
|
||||||
|
dist
|
||||||
|
139
Makefile
139
Makefile
@ -1,17 +1,18 @@
|
|||||||
DIST := dist
|
DIST := dist
|
||||||
EXECUTABLE := drone-ssh
|
EXECUTABLE := drone-ssh
|
||||||
GOFMT ?= gofumpt -l -s
|
GOFMT ?= gofumpt -l -s
|
||||||
|
DIST := dist
|
||||||
|
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
||||||
GO ?= go
|
GO ?= go
|
||||||
|
SHASUM ?= shasum -a 256
|
||||||
|
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||||
|
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||||
|
XGO_VERSION := go-1.18.x
|
||||||
|
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
|
||||||
|
|
||||||
# for dockerhub
|
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
||||||
DEPLOY_ACCOUNT := appleboy
|
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
|
||||||
DEPLOY_IMAGE := $(EXECUTABLE)
|
WINDOWS_ARCHS ?= windows/amd64
|
||||||
|
|
||||||
TARGETS ?= linux darwin windows
|
|
||||||
ARCHS ?= amd64
|
|
||||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
||||||
TAGS ?=
|
|
||||||
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
|
||||||
|
|
||||||
ifneq ($(shell uname), Darwin)
|
ifneq ($(shell uname), Darwin)
|
||||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||||
@ -19,12 +20,48 @@ else
|
|||||||
EXTLDFLAGS =
|
EXTLDFLAGS =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(DRONE_TAG),)
|
ifeq ($(HAS_GO), GO)
|
||||||
VERSION ?= $(DRONE_TAG)
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
||||||
else
|
export PATH := $(GOPATH)/bin:$(PATH)
|
||||||
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
|
||||||
|
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
|
||||||
|
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(OS), Windows_NT)
|
||||||
|
GOFLAGS := -v -buildmode=exe
|
||||||
|
EXECUTABLE ?= $(EXECUTABLE).exe
|
||||||
|
else ifeq ($(OS), Windows)
|
||||||
|
GOFLAGS := -v -buildmode=exe
|
||||||
|
EXECUTABLE ?= $(EXECUTABLE).exe
|
||||||
|
else
|
||||||
|
GOFLAGS := -v
|
||||||
|
EXECUTABLE ?= $(EXECUTABLE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
STORED_VERSION_FILE := VERSION
|
||||||
|
|
||||||
|
ifneq ($(DRONE_TAG),)
|
||||||
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
||||||
|
RELASE_VERSION ?= $(VERSION)
|
||||||
|
else
|
||||||
|
ifneq ($(DRONE_BRANCH),)
|
||||||
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
||||||
|
else
|
||||||
|
VERSION ?= master
|
||||||
|
endif
|
||||||
|
|
||||||
|
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
|
||||||
|
ifneq ($(STORED_VERSION),)
|
||||||
|
RELASE_VERSION ?= $(STORED_VERSION)
|
||||||
|
else
|
||||||
|
RELASE_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
TAGS ?=
|
||||||
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@ -59,23 +96,6 @@ build: $(EXECUTABLE)
|
|||||||
$(EXECUTABLE): $(SOURCES)
|
$(EXECUTABLE): $(SOURCES)
|
||||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
||||||
|
|
||||||
release: release-dirs release-build release-copy release-check
|
|
||||||
|
|
||||||
release-dirs:
|
|
||||||
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
||||||
|
|
||||||
release-build:
|
|
||||||
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
|
|
||||||
$(GO) install github.com/mitchellh/gox@master; \
|
|
||||||
fi
|
|
||||||
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
|
||||||
|
|
||||||
release-copy:
|
|
||||||
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
|
|
||||||
|
|
||||||
release-check:
|
|
||||||
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
||||||
|
|
||||||
build_linux_amd64:
|
build_linux_amd64:
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
||||||
|
|
||||||
@ -88,20 +108,6 @@ build_linux_arm64:
|
|||||||
build_linux_arm:
|
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)
|
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)
|
||||||
|
|
||||||
docker_image:
|
|
||||||
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
|
|
||||||
|
|
||||||
docker: docker_image
|
|
||||||
|
|
||||||
docker_deploy:
|
|
||||||
ifeq ($(tag),)
|
|
||||||
@echo "Usage: make $@ tag=<tag>"
|
|
||||||
@exit 1
|
|
||||||
endif
|
|
||||||
# deploy image
|
|
||||||
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
|
||||||
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
|
||||||
|
|
||||||
ssh-server:
|
ssh-server:
|
||||||
adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
|
adduser -h /home/drone-scp -s /bin/sh -D -S drone-scp
|
||||||
echo drone-scp:1234 | chpasswd
|
echo drone-scp:1234 | chpasswd
|
||||||
@ -120,6 +126,51 @@ ssh-server:
|
|||||||
coverage:
|
coverage:
|
||||||
sed -i '/main.go/d' coverage.txt
|
sed -i '/main.go/d' coverage.txt
|
||||||
|
|
||||||
|
.PHONY: deps-backend
|
||||||
|
deps-backend:
|
||||||
|
$(GO) mod download
|
||||||
|
$(GO) install $(GXZ_PAGAGE)
|
||||||
|
$(GO) install $(XGO_PACKAGE)
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: release-windows release-linux release-darwin release-copy release-compress release-check
|
||||||
|
|
||||||
|
$(DIST_DIRS):
|
||||||
|
mkdir -p $(DIST_DIRS)
|
||||||
|
|
||||||
|
.PHONY: release-windows
|
||||||
|
release-windows: | $(DIST_DIRS)
|
||||||
|
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
||||||
|
ifeq ($(CI),true)
|
||||||
|
cp -r /build/* $(DIST)/binaries/
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: release-linux
|
||||||
|
release-linux: | $(DIST_DIRS)
|
||||||
|
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
||||||
|
ifeq ($(CI),true)
|
||||||
|
cp -r /build/* $(DIST)/binaries/
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: release-darwin
|
||||||
|
release-darwin: | $(DIST_DIRS)
|
||||||
|
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
||||||
|
ifeq ($(CI),true)
|
||||||
|
cp -r /build/* $(DIST)/binaries/
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: release-copy
|
||||||
|
release-copy: | $(DIST_DIRS)
|
||||||
|
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
|
||||||
|
|
||||||
|
.PHONY: release-check
|
||||||
|
release-check: | $(DIST_DIRS)
|
||||||
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
||||||
|
|
||||||
|
.PHONY: release-compress
|
||||||
|
release-compress: | $(DIST_DIRS)
|
||||||
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PAGAGE) -k -9 $${file}; done;
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(GO) clean -x -i ./...
|
$(GO) clean -x -i ./...
|
||||||
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
||||||
|
@ -160,9 +160,10 @@
|
|||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: 'build-all-binary',
|
name: 'build-all-binary',
|
||||||
image: 'golang:1.18',
|
image: 'techknowlogick/xgo:go-1.18.x',
|
||||||
pull: 'always',
|
pull: 'always',
|
||||||
commands: [
|
commands: [
|
||||||
|
'export PATH=$PATH:$GOPATH/bin',
|
||||||
'make release'
|
'make release'
|
||||||
],
|
],
|
||||||
when: {
|
when: {
|
||||||
|
Loading…
Reference in New Issue
Block a user