Skip to content

Commit

Permalink
Merge pull request #171 from dokku/binary-check
Browse files Browse the repository at this point in the history
tests: check that binary builds correctly and respect go version from go.mod
  • Loading branch information
josegonzalez authored Jun 29, 2024
2 parents 873b459 + 3406be2 commit 98dedb5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,33 @@ jobs:
with:
name: build
path: build/**/*

binary-check:
name: binary-check
runs-on: ubuntu-22.04
needs: build
steps:
- uses: actions/checkout@v4
- name: Get Repository Name
id: repo-name
run: |
echo "REPOSITORY_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)" >> $GITHUB_OUTPUT
echo "TARGET_ARCHITECTURE=$(dpkg --print-architecture)" >> $GITHUB_OUTPUT
echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_OUTPUT
- name: Build binaries
uses: crazy-max/ghaction-xgo@v3
with:
xgo_version: latest
go_version: "${{ steps.repo-name.outputs.GO_VERSION }}"
dest: dist
prefix: ${{ steps.repo-name.outputs.REPOSITORY_NAME }}
targets: linux/${{ steps.repo-name.outputs.TARGET_ARCHITECTURE }}
v: true
x: false
race: false
ldflags: -s -w -X main.Version=${{ github.ref_name }}
buildmode: default
trimpath: true
- name: Check version
run: |
"dist/${{ steps.repo-name.outputs.REPOSITORY_NAME }}-linux-${{ steps.repo-name.outputs.TARGET_ARCHITECTURE }}" --version
3 changes: 2 additions & 1 deletion .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ jobs:
id: repo-name
run: |
echo "REPOSITORY_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)" >> $GITHUB_OUTPUT
echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_OUTPUT
- name: Build binaries
uses: crazy-max/ghaction-xgo@v3
with:
xgo_version: latest
go_version: 1.22
go_version: "${{ steps.repo-name.outputs.GO_VERSION }}"
dest: dist
prefix: ${{ steps.repo-name.outputs.REPOSITORY_NAME }}
targets: darwin/amd64,darwin/arm64,linux/arm64,linux/amd64
Expand Down
10 changes: 9 additions & 1 deletion plugn.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,25 @@ func isArg(argument string) bool {
return len(os.Args) > 1 && os.Args[1] == argument
}

func isVersionArg() bool {
return isArg("version") || isArg("--version") || isArg("-v")
}

func main() {
os.Setenv("PLUGN_VERSION", Version)
if data, err := os.ReadFile(".plugn"); err == nil {
if path, err := filepath.Abs(string(data)); err == nil {
os.Setenv("PLUGIN_PATH", path)
}
}
if !isArg("version") && os.Getenv("PLUGIN_PATH") == "" {
if !isVersionArg() && os.Getenv("PLUGIN_PATH") == "" {
fmt.Println("!! PLUGIN_PATH is not set in environment")
os.Exit(2)
}
if isVersionArg() {
os.Args[1] = "version"
}

PluginPath = os.Getenv("PLUGIN_PATH")
if isArg("gateway") {
runGateway()
Expand Down

0 comments on commit 98dedb5

Please sign in to comment.