Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.idea
*.coverprofile
*~
.*.swp

/build-v*
/yj
Expand All @@ -13,11 +14,20 @@
*.so
*.dylib

# Debian build related files
deb/
debian/changelog
debian/.debhelper/
debian/debhelper-build-stamp
debian/files
debian/yj.substvars
debian/yj/

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# vendor/
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
EXE = deb/yj
EXE_DIR := $(shell dirname $(EXE))
VERSION := $(shell git describe --tags --dirty | sed -e 's/v\(.*\)/\1/' -e 's/-g.*//')

.PHONY: all clean deb install

all::
./build.sh $(VERSION)

deb:
echo "yj ($(VERSION)) stable; urgency=medium\n\n * See https://github.com/sclevine/yj/releases\n\n -- Stephen Levine <[email protected]> $$(date -R)" >debian/changelog
dpkg-buildpackage -us -uc -b

clean:
-rm -rf $(EXE_DIR)

$(EXE):
mkdir -p $(EXE_DIR)
go build -ldflags "-X main.Version=$(VERSION)" -o $(EXE) .

install: $(EXE)
install -m 0755 -d $(DESTDIR)/usr/bin
install -D -m 0555 $(EXE) $(DESTDIR)/usr/bin/$(shell filename $(EXE))

# vi: ts=8:sw=8:noai:noexpandtab:filetype=make
41 changes: 40 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ out=build-v${version}
cd "$(dirname "${BASH_SOURCE[0]}")"
mkdir -p "$out"

create_deb () {
local IMAGE=$1
local PLATFORM=$2

# We need to build the DEB inside a docker container for each OS. That
# docker container runs as root user yet the volume mounted source directory
# is (in all likelihood) not owned by root. This presents a minor problem for
# the Makefile which is used to create the DEB because that relies on Git to
# determine the version. Git is quite picky about directory ownership
# mismatches. So, we need to copy the source code over to another directory
# inside the docker container before building. This happens to be a good
# solution for another problem, which is identifying the resulting DEB, which
# is always placed in the .. directory (for details, see
# https://groups.google.com/g/linux.debian.bugs.dist/c/1KiGKfuFH3Y), and needs
# to be renamed with an OS specific name anyways.
docker run --platform=${PLATFORM} --rm -v $(pwd):/src ${IMAGE} /bin/bash -c "
mkdir /build && \
cp -R /src /build && \
cd /build/src && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential ca-certificates debhelper dpkg-dev git golang-go && \
make deb && \
cd .. && \
source /etc/os-release && \
mv yj*.deb /src/\$(ls yj*.deb | sed 's/yj_/yj_'"\${ID}_\${VERSION_ID}_\${VERSION_CODENAME}_"'/')
"
mv yj*.deb "${out}"
}

for PLAT in linux/arm64 linux/amd64; do
create_deb debian:10-slim ${PLAT}
create_deb debian:11-slim ${PLAT}
create_deb debian:12-slim ${PLAT}
create_deb ubuntu:20.04 ${PLAT}
create_deb ubuntu:22.04 ${PLAT}
done

GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=$version" -o "$out/yj-macos-amd64" .
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.Version=$version" -o "$out/yj-macos-arm64" .
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$version" -o "$out/yj-linux-amd64" .
Expand All @@ -16,4 +55,4 @@ GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-X main.Version=$version" -o "$
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=$version" -o "$out/yj.exe" .

docker build . --build-arg "version=$version" -t "sclevine/yj:$version"
docker tag "sclevine/yj:$version" "sclevine/yj:latest"
docker tag "sclevine/yj:$version" "sclevine/yj:latest"
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
16 changes: 16 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Source: yj
Section: utils
Priority: optional
Maintainer: Paul Grinberg <[email protected]>
Build-Depends: ca-certificates,
debhelper (>= 10),
git,
golang-go
Standards-Version: 4.1.2
Homepage: https://github.com/sclevine/yj

Package: yj
Architecture: any
Depends: ${misc:Depends}
Description: Convert between YAML, TOML, JSON, and HCL
Tool to convert between YAML, TOML, JSON, and HCL.
21 changes: 21 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: yj
Source: https://github.com/sclevine/yj

Files: *
Copyright: 2016-2024 Stephen Levine
License: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.
On Debian systems, the complete text of the Apache version 2.0 license
can be found in "/usr/share/common-licenses/Apache-2.0"
12 changes: 12 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/make -f

DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
dh $@

override_dh_auto_build:
make deb/yj

# vi: ts=8:sw=8:noai:noexpandtab:filetype=make