Skip to content

Commit

Permalink
feat: build script for executables (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
csmig authored Mar 10, 2023
1 parent 057aea4 commit c2c0024
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Directory for the STIGMAN Watcher binaries

# Content can be written here by executing:
# $ ../build.sh
#
# This file hopes to prevent commits to this directory

# Ignore everything in this directory
*

# Except this file
!.gitignore
48 changes: 48 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# This file is used to build binaries on a Linux device. It is not tested elsewhere, yet.
# Requires:
# - Node.js and module "pkg" (npm install -g pkg)
# - zip
# - tar
# - gpg, if you wish to produce detached signatures

keyring=stig-manager.gpg
signing_key="nuwcdivnpt-bot@users.noreply.github.com"

bin_dir=./bin
dist_dir=./dist

# stop the script if SIGINT received during any command
trap 'exit 1' INT

# Change to this script directory
cd "$(dirname "$(realpath "$0")")"

# Prepare
[ ! -d "$bin_dir" ] && mkdir -p "$bin_dir"
[ ! -d "$dist_dir" ] && mkdir -p "$dist_dir"
rm -rf $bin_dir/*
rm -rf $dist_dir/*
printf "[BUILD_TASK] Fetching node_modules\n"
rm -rf ./node_modules
npm ci

describe=$(git describe --tags | sed 's/\(.*\)-.*/\1/')
printf "\n[BUILD_TASK] Using version string: $describe\n"

# Make binaries
printf "\n[BUILD_TASK] Building binaries in $bin_dir\n"
pkg -C gzip --public --public-packages=* --no-bytecode pkg.config.json
# Windows archive
windows_archive=$dist_dir/stigman-watcher-win-$describe.zip
printf "\n[BUILD_TASK] Creating $windows_archive\n"
zip --junk-paths $windows_archive ./dotenv-example $bin_dir/stigman-watcher-win.exe
[[ $1 == "--sign" ]] && gpg --keyring $keyring --default-key $signing_key --armor --detach-sig $windows_archive
# Linux archive
linux_archive=$dist_dir/stigman-watcher-linux-$describe.tar.gz
printf "\n[BUILD_TASK] Creating $linux_archive\n"
tar -czvf $linux_archive --xform='s|^|stigman-watcher/|S' -C . dotenv-example -C $bin_dir stigman-watcher-linuxstatic
[[ $1 == "--sign" ]] && gpg --keyring $keyring --default-key $signing_key --armor --detach-sig $linux_archive

printf "\n[BUILD_TASK] Done\n"
12 changes: 12 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Directory for the STIGMAN Watcher distribution archives

# Content can be written here by executing:
# $ ../build.sh
#
# This file hopes to prevent commits to this directory

# Ignore everything in this directory
*

# Except this file
!.gitignore
8 changes: 8 additions & 0 deletions pkg.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "stigman-watcher",
"bin": "./index.js",
"pkg": {
"targets": [ "node18-win", "node18-linuxstatic" ],
"outputPath": "./bin"
}
}

0 comments on commit c2c0024

Please sign in to comment.