From c0418831bd2ff5951db2a58c3830edd98f78145a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 9 Mar 2020 20:34:25 +0800 Subject: [PATCH] New Parameter: pre_command (#5) * new feature "pre_command" that will be executed before go build * fix shell syntax * force rebuild action * again to make sure github action rebuild * print env to easy to debug * try to force github action rebuild * Revert "try to force github action rebuild" This reverts commit 149e4422d0571b726c08b65eb72f49c7964d025a. * Revert "again to make sure github action rebuild" This reverts commit 6de4fa0437dc6c32b0cd3caa7502c30dc11568c5. * Revert "force rebuild action" This reverts commit 050f497e56606c5275ee934825cc2361ed7dd4b6. * docs for pre_command --- README.md | 2 ++ action.yml | 7 ++++++- entrypoint.sh | 3 +++ release.sh | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d37102..e0ef50d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Automatically publish `Go` binaries to Github Release Assets through Github Acti - Support multiple `GOOS`/`GOARCH` build in parallel by [Github Action Matrix Strategy](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) gracefully. - Publish `.zip` instead of `.tar.gz` for `windows`. - No `musl` library dependency issue on `linux`. +- Support extra command that will be executed before `go build`. You may want to use it to solve dependency if you're NOT using [Go Modules](https://github.com/golang/go/wiki/Modules). ## Usage @@ -45,6 +46,7 @@ jobs: | goversion | **Optional** | The `Go` compiler version. `1.14` by default, optional `1.13`.
It also takes download URL instead of version string if you'd like to use more specified version. But make sure your URL is `linux-amd64` package, better to find the URL from [Go - Downloads](https://golang.org/dl/).
E.g., `https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz`. | | project_path | **Optional** | Where to run `go build`.
Use `.` by default. | | binary_name | **Optional** | Specify another binary name if do not want to use repository basename.
Use your repository's basename if not set. | +| pre_command | **Optional** | Extra command that will be executed before `go build`. You may want to use it to solve dependency if you're NOT using [Go Modules](https://github.com/golang/go/wiki/Modules). | ### Advanced Example diff --git a/action.yml b/action.yml index af6c0ed..43f71d9 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ # action.yml name: 'Go Release Binaries' author: 'Jay Zhang ' -description: 'Release Go binaries to Github Assets' +description: 'Release Go binaries to GitHub Release Assets' inputs: github_token: description: 'GITHUB_TOKEN for uploading releases to Github asserts.' @@ -27,6 +27,10 @@ inputs: description: 'Specify another binary name if do not want to use repository basename' required: false default: '' + pre_command: + description: 'Extra command that will be executed before `go build`, may for solving dependency' + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' @@ -38,6 +42,7 @@ runs: - ${{ inputs.project_path }} - ${{ inputs.binary_name }} - ${{ inputs.compression }} + - ${{ inputs.pre_command }} branding: icon: 'package' color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh index 2cf8b16..f83fb1e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,10 @@ # prepare golang source /setup-go.sh + +# easy to debug if anything wrong go version +env # build & release go binaries /release.sh diff --git a/release.sh b/release.sh index 2843b25..8b4808c 100755 --- a/release.sh +++ b/release.sh @@ -12,6 +12,11 @@ RELEASE_ASSET_NAME=${BINARY_NAME}-${RELEASE_TAG}-${INPUT_GOOS}-${INPUT_GOARCH} RELEASE_ASSETS_UPLOAD_URL=$(cat ${GITHUB_EVENT_PATH} | jq -r .release.upload_url) RELEASE_ASSETS_UPLOAD_URL=${RELEASE_ASSETS_UPLOAD_URL%\{?name,label\}} +# execute pre-command if exist, e.g. `go get -v ./...` +if [ ! -z "${INPUT_PRE_COMMAND}" ]; then + ${INPUT_PRE_COMMAND} +fi + # build binary cd ${INPUT_PROJECT_PATH} EXT=''