go-release-action icon indicating copy to clipboard operation
go-release-action copied to clipboard

How to include multiple binaries in one .zip file ?

Open Fadiabb opened this issue 2 years ago • 9 comments

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

Fadiabb avatar Apr 14 '22 08:04 Fadiabb

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 avatar Apr 14 '22 13:04 wangyoucao577

@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.

Fadiabb avatar Apr 19 '22 09:04 Fadiabb

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 avatar Dec 25 '22 19:12 yurenchen000

@yurenchen000 added new example for make.

wangyoucao577 avatar Dec 31 '22 02:12 wangyoucao577

@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.

wangyoucao577 avatar Jan 02 '23 09:01 wangyoucao577

:+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'

yurenchen000 avatar Jan 02 '23 17:01 yurenchen000

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 avatar Jan 03 '23 01:01 wangyoucao577

@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 ?

yurenchen000 avatar Jan 09 '23 07:01 yurenchen000

Good point. PR is welcome once this feature merged! 😄

wangyoucao577 avatar Jan 09 '23 12:01 wangyoucao577