Skip to content

Commit

Permalink
Tool build (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
trobro authored Jul 23, 2022
1 parent 8a182f8 commit 9bab3c4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
47 changes: 17 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,30 @@ on:
- 'v[0-9]+.[0-9]+**'

jobs:

build_hjson-cli_releases:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]


steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Build the ${{ runner.os }} hjson-cli binary
run: |
mkdir binaries
cd hjson-cli
go build
- name: Rename hjson-cli binary to reflect ${{ runner.os }}
run: |
mv hjson-cli/hjson-cli.exe binaries/hjson-cli_${{ github.ref_name }}_${{ runner.os }}.exe
if: ${{ contains(matrix.os, 'windows') }}

- name: Rename hjson-cli binary to reflect ${{ runner.os }}
run: |
mv hjson-cli/hjson-cli binaries/hjson-cli_${{ github.ref_name }}_${{ runner.os }}
if: runner.os != 'Windows'

uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build the hjson-cli binaries
run: ./build_release.sh

- name: Upload hjson-cli artifacts
uses: actions/upload-artifact@v2
with:
name: output
path: binaries/*
if-no-files-found: error


release_artifacts:
needs: [build_hjson-cli_releases]
runs-on: ubuntu-latest
Expand All @@ -51,21 +38,21 @@ jobs:
uses: actions/download-artifact@v2
with:
path: artifacts

- name: Show the downloaded artifacts
run: |
pwd
ls -laR *
- name: Release binaries
uses: ncipollo/release-action@v1
with:
# ncipollo/release-action needs a tag! Either a usual "GIT TAG" or an dedicated TAG, see below!
# set a TAG if you want to build a release, i.e. via "workflow_dispatch" on GitHub _AND_ do not push a regular GIT TAG
# and the other way around, if you want to build releases based on pushed GIT TAGs, make sure you un-comment the "tag:" line below!
tag: ${{ github.ref_name }}
tag: ${{ github.ref_name }}
draft: true
artifactErrorsFailBuild: true
artifacts: "artifacts/output/*"
token: ${{ secrets.GITHUB_TOKEN }}

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Options:
Omit braces at the root.
-quoteAlways
Always quote string values.
-v
Show version.
```

Sample:
Expand Down
23 changes: 12 additions & 11 deletions build_release.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
#!/bin/bash

cd `dirname $0`
ROOT=$PWD/_dist
ROOT=$PWD
BINARIES=$ROOT/binaries

if [ -d "$ROOT" ]; then rm -rf $ROOT; fi
if [ -d "$BINARIES" ]; then rm -rf $BINARIES; fi

mkdir $ROOT
mkdir $BINARIES

function build() {
export GOOS=$1
export GOARCH=$2

echo build $GOOS $GOARCH
OUT=$ROOT/${GOOS}_${GOARCH}
VERSION=`cd $ROOT && git describe --tags`
OUT=${BINARIES}/hjson_${VERSION}_${GOOS}_${GOARCH}
mkdir $OUT
cd $OUT
go build github.com/hjson/hjson-go/hjson-cli
go build -ldflags "-w -s -X main.Version=${VERSION}" github.com/hjson/hjson-go/v4/hjson-cli
if [[ $3 == "zip" ]]; then
mv $OUT/hjson-cli.exe $OUT/hjson.exe
zip -j ${OUT}.zip $OUT/*
else
mv $OUT/hjson-cli $OUT/hjson
tar -czf ${OUT}.tar.gz -C $OUT .
fi
rm -r $OUT

}

# not all targets can be built on travis

# build android arm
build darwin 386
build android arm64
build darwin amd64
# build darwin arm
# build darwin arm64
build darwin arm64
build dragonfly amd64
build freebsd 386
build freebsd amd64
Expand All @@ -56,3 +55,5 @@ build plan9 amd64
build solaris amd64
build windows 386 zip
build windows amd64 zip
build windows arm zip
build windows arm64 zip
12 changes: 10 additions & 2 deletions hjson-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/hjson/hjson-go/v4"
)

// Can be set when building for example like this:
// go build -ldflags "-X main.Version=v3.0"
var Version string

func fixJSON(data []byte) []byte {
data = bytes.Replace(data, []byte("\\u003c"), []byte("<"), -1)
data = bytes.Replace(data, []byte("\\u003e"), []byte(">"), -1)
Expand Down Expand Up @@ -40,15 +44,19 @@ func main() {
var bracesSameLine = flag.Bool("bracesSameLine", false, "Print braces on the same line.")
var omitRootBraces = flag.Bool("omitRootBraces", false, "Omit braces at the root.")
var quoteAlways = flag.Bool("quoteAlways", false, "Always quote string values.")

// var showVersion = flag.Bool("V", false, "Show version.")
var showVersion = flag.Bool("v", false, "Show version.")

flag.Parse()
if *help || flag.NArg() > 1 {
flag.Usage()
os.Exit(1)
}

if *showVersion {
fmt.Println(Version)
os.Exit(0)
}

var err error
var data []byte
if flag.NArg() == 1 {
Expand Down

0 comments on commit 9bab3c4

Please sign in to comment.