Skip to content

Commit

Permalink
New Parameter: pre_command (#5)
Browse files Browse the repository at this point in the history
* 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 149e442.

* Revert "again to make sure github action rebuild"

This reverts commit 6de4fa0.

* Revert "force rebuild action"

This reverts commit 050f497.

* docs for pre_command
  • Loading branch information
wangyoucao577 authored Mar 9, 2020
1 parent 0458dd4 commit c041883
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -45,6 +46,7 @@ jobs:
| goversion | **Optional** | The `Go` compiler version. `1.14` by default, optional `1.13`. <br>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/).<br>E.g., `https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz`. |
| project_path | **Optional** | Where to run `go build`. <br>Use `.` by default. |
| binary_name | **Optional** | Specify another binary name if do not want to use repository basename. <br>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

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# action.yml
name: 'Go Release Binaries'
author: 'Jay Zhang <wangyoucao577@gmail.com>'
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.'
Expand All @@ -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'
Expand All @@ -38,6 +42,7 @@ runs:
- ${{ inputs.project_path }}
- ${{ inputs.binary_name }}
- ${{ inputs.compression }}
- ${{ inputs.pre_command }}
branding:
icon: 'package'
color: 'blue'
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=''
Expand Down

0 comments on commit c041883

Please sign in to comment.