go-release-action
go-release-action copied to clipboard
How to include multiple binaries in one .zip file ?
Hallo,
We have the following project structure:
├── cmd
│ ├── first
│ │ ├── first.go
│ ├── second
│ │ ├── second.go
and want to pack the "first" and "second" binaries in one .zip file. Calling the action multiple times will generate files for each binary.
on:
release:
types: [created]
jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
project_path: ./cmd/first
binary_name: first
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
project_path: ./cmd/second
binary_name: second
Unfortunately, it's not support at the moment. Will you expect to package all binaries under cmd
or pick up several of them? I may need to figure out a way to achieve it.
@wangyoucao577 It would be nice to build several binaries under some folder e.g. dist
and from these folder to package all binaries in a zip
file in the release.
Or add the ability to give many paths in the project_path
parameter.
Something like: project_path: ./cmd/first ./cmd/secone
or project_path: ./dist/*
At the moment i should call the action many times for each binary which will generate many files for each one.
after read the docker script and run log
I found one way to achive it (multi output binary) // not by normal usage (seems normal usage not support that)
https://github.com/wangyoucao577/go-release-action/blob/405af3ff0774ced2ab4faabbb58aab048fee188d/release.sh
# build
BUILD_ARTIFACTS_FOLDER=build-artifacts-$(date +%s)
mkdir -p ${INPUT_PROJECT_PATH}/${BUILD_ARTIFACTS_FOLDER}
cd ${INPUT_PROJECT_PATH}
if [[ "${INPUT_BUILD_COMMAND}" =~ ^make.* ]]; then
# start with make, assumes using make to build golang binaries, execute it directly
GOAMD64=${GOAMD64_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} eval ${INPUT_BUILD_COMMAND}
if [ -f "${BINARY_NAME}${EXT}" ]; then
# assumes the binary will be generated in current dir, copy it for later processes
cp ${BINARY_NAME}${EXT} ${BUILD_ARTIFACTS_FOLDER}/
fi
else
GOAMD64=${GOAMD64_FLAG} GOOS=${INPUT_GOOS} GOARCH=${INPUT_GOARCH} ${INPUT_BUILD_COMMAND} -o ${BUILD_ARTIFACTS_FOLDER}/${BINARY_NAME}${EXT} ${INPUT_BUILD_FLAGS} ${LDFLAGS_PREFIX} "${INPUT_LDFLAGS}"
fi
that means go build
way only output one file.
the make
way may output multi file, but only one output ${BINARY_NAME}${EXT}
so little hack can output multi-files: // copy output to BUILD_ARTIFACTS_FOLDER by ourself
in .yml:
build_command: make DEST=${BUILD_ARTIFACTS_FOLDER}
in Makefile:
FLAGS= -ldflags='-s -w'
all: ssh-keep-c ssh-keep-s
echo "DEST: $(DEST)"
[ -z "$(DEST)" ] || cp -pv $^ $(DEST)
ssh-keep-c: client.go
GO111MODULE=off GOPATH=$(PWD) go build -o $@ $(FLAGS) $^
ssh-keep-s: server.go
GO111MODULE=off GOPATH=$(PWD) go build -o $@ $(FLAGS) $^
the full example here:
https://github.com/yurenchen000/ssh-keep/blob/v1.0.1/.github/workflows/release.yml
https://github.com/yurenchen000/ssh-keep/blob/v1.0.1/Makefile
@wangyoucao577 would you like to add this make
usage to More Examples
?
seems there no make
example yet
@yurenchen000 added new example for make
.
@Fadiabb @yurenchen000 I made a branch to support this feature, would you please help to have a try? Thanks! wangyoucao577/go-release-action@feature/multi-binaries
.
Currently it only supports project_path: ./cmd/first ./cmd/secone
schema. The project_path: ./dist/*
has not been supported yet.
:+1: good job, I'd like to try it..
update: unfortunately, I don't use that scheme which build each binary in independent directory.
BTW:
the usage of
build_command: make DEST=${BUILD_ARTIFACTS_FOLDER}
can do almost any flexible processing according to user needs
maybe a hack way can also for go build.
build_command: 'make /dev/null; go build -o ${BUILD_ARTIFACTS_FOLDER}/bin1; go build -o ${BUILD_ARTIFACTS_FOLDER}/bin2'
Oh, no need to hack for this. As you said, the make
schema can do it too. Just keep the scheme which suitable for you. Maybe others can help have a try for the new schema.
@wangyoucao577
seems $BUILD_ARTIFACTS_FOLDER
variable is useful for make cmd (for multiple files in one .tgz/.zip)
I learned it from your source code, maybe it value to be documented ?
Good point. PR is welcome once this feature merged! 😄