Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix macos stuff #1

Merged
merged 12 commits into from
May 15, 2024
Merged
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
38 changes: 32 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
name: 🧪 & 📣
on:
- push
- pull_request
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
Expand All @@ -11,19 +18,38 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
# - windows-latest
architecture:
- x64
- arm64
exclude:
- os: windows-latest
architecture: arm64
# exclude:
# - os: windows-latest
# architecture: arm64
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: brew install parallel
if: runner.os == 'macOS'
- run: bun i
- run: make tests

release:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- uses: dyne/pnpm@v1
- run: pnpm build
- run: pnpm semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
slangroom-exec
slangroom-exec-*
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs
Expand Down
48 changes: 48 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"repositoryUrl": "[email protected]:dyne/slangroom-exec.git",
"dryRun": false,
"plugins": [
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/commit-analyzer",
{
"preset": "angular",
"releaseRules": [
{ "type": "build", "scope": "deps", "release": "patch" },
{ "type": "build", "scope": "deps-dev", "release": "patch" }
]
}
],
[
"@semantic-release/npm",
{
"npmPublish": true
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json"
],
"message": "chore(release): 🚀 ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
[
"@semantic-release/github",
{
"assets": [
{ "path": "slangroom-exec-darwin-x64", "name": "slangroom-exec-Darwin-x86_64" },
{ "path": "slangroom-exec-darwin-arm64", "name": "slangroom-exec-Darwin-arm64" },
{ "path": "slangroom-exec-linux-x64", "name": "slangroom-exec-Linux-x86_64" },
{ "path": "slangroom-exec-linux-arm64", "name": "slangroom-exec-Linux-arm64" }
]
}
]
],
"branches": [
"main"
]
}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.PHONY: help


PLATFORMS = linux-x64 linux-arm64 windows-x64 darwin-x64 darwin-arm64
SOURCES = $(shell find src -type f -name '*.ts')
LIBS = node_modules
Expand All @@ -27,7 +26,11 @@ clean: ## 🧹 Clean the build
@echo "🧹 Cleaned the build"

tests: slangroom-exec ## 🧪 Run tests
ifeq ($(OS),Windows_NT)
./test/bats/bin/bats test/*.bats
else
./test/bats/bin/bats -j 15 test/*.bats
endif
bun test --coverage

$(LIBS): package.json
Expand Down
107 changes: 56 additions & 51 deletions src/slexfe
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,47 @@
# into a string that can be used in the slangroom-exec command

print_help() {
echo -e "\033[1mUsage:\033[0m"
echo -e " $0 [options]\n"
echo -e "\033[1mOptions:\033[0m"
echo -e " -c, --conf conf filename to read"
echo -e " -s, --slangroom-contract slangroom-contract filename to read"
echo -e " -d, --data data filename to read"
echo -e " -k, --keys keys filename to read"
echo -e " -e, --extra extra filename to read"
echo -e " -x, --context context filename to read"
echo -e " -F, --filename lookup files based on a prefix"
echo -e " -h, --help Print this help message"
echo -e "\nEncode the parameters into a base64 string."
printf "\033[1mUsage:\033[0m"
printf " $0 [options]\n"
printf "\033[1mOptions:\033[0m"
printf " -c conf conf filename to read"
printf " -s slangroom-contract slangroom-contract filename to read"
printf " -d data data filename to read"
printf " -k keys keys filename to read"
printf " -e extra extra filename to read"
printf " -x context context filename to read"
printf " -F filename lookup files based on a prefix"
printf " -h Print this help message"
printf "\nEncode the parameters into a base64 string."
exit 1
}

# Function to encode to base64
encode_base64() {
cat "$1" 2>/dev/null | base64 -w 0
if [[ "$OSTYPE" == "darwin"* ]]; then
cat "$1" 2>/dev/null | base64
else
cat "$1" 2>/dev/null | base64 -w 0
fi
}

encode_json_base64() {
jq -c . "$1" 2>/dev/null | base64 -w 0
if [[ "$OSTYPE" == "darwin"* ]]; then
jq -c . "$1" 2>/dev/null | base64
else
jq -c . "$1" 2>/dev/null | base64 -w 0
fi
}

# check that jq and getopt are installed

if ! command -v jq &> /dev/null; then
echo "jq is not installed. Please install jq to use this script."
printf "jq is not installed. Please install jq to use this script."
exit 1
fi

if ! command -v getopt &> /dev/null; then
echo "getopt is not installed. Please install getopt to use this script."
printf "getopt is not installed. Please install getopt to use this script."
exit 1
fi

Expand All @@ -48,48 +56,45 @@ keys=""
extra=""
context=""

OPTIONS=$(getopt -o c:s:d:k:e:x:F:h --long conf:,slangroom-contract:,data:,keys:,extra:,context:,filename:,help -n 'parse-options' -- "$@")
if [ $? -ne 0 ]; then
echo "Failed to parse options." >&2
exit 1
fi
eval set -- "$OPTIONS"

while true; do
case "$1" in
-c|--conf)
conf=$(encode_base64 "$2"); shift 2 ;;
-s|--slangroom-contract)
slangroom_contract=$(encode_base64 "$2"); shift 2 ;;
-d|--data)
data=$(encode_json_base64 "$2"); shift 2 ;;
-k|--keys)
keys=$(encode_json_base64 "$2"); shift 2 ;;
-e|--extra)
extra=$(encode_json_base64 "$2"); shift 2 ;;
-x|--context)
context=$(encode_base64 "$2"); shift 2 ;;
-F|--filename)
conf=$(encode_base64 "${2}.conf")
slangroom_contract=$(encode_base64 "${2}.slang")
data=$(encode_json_base64 "${2}.data.json")
keys=$(encode_json_base64 "${2}.keys.json")
extra=$(encode_json_base64 "${2}.extra.json")
context=$(encode_base64 "${2}.context")
shift 2 ;;
-h|--help)
while getopts "c:s:d:k:e:x:F:h" opt; do
case ${opt} in
c)
conf=$(encode_base64 "${OPTARG}");;
s)
slangroom_contract=$(encode_base64 "${OPTARG}");;
d)
data=$(encode_json_base64 "${OPTARG}");;
k)
keys=$(encode_json_base64 "${OPTARG}");;
e)
extra=$(encode_json_base64 "${OPTARG}");;
x)
context=$(encode_base64 "${OPTARG}");;
F)
conf=$(encode_base64 "${OPTARG}.conf")
slangroom_contract=$(encode_base64 "${OPTARG}.slang")
data=$(encode_json_base64 "${OPTARG}.data.json")
keys=$(encode_json_base64 "${OPTARG}.keys.json")
extra=$(encode_json_base64 "${OPTARG}.extra.json")
context=$(encode_base64 "${OPTARG}.context");;
h)
print_help ;;
--)
shift; break ;;
*)
echo "Internal error!"; exit 1 ;;
\?)
printf "Invalid option: -${OPTARG}" >&2
exit 1 ;;
:)
printf "Option -${OPTARG} requires an argument." >&2
exit 1 ;;
esac
done
shift $((OPTIND -1))


# if slangroom-contract is empty, read it from stdin
if [ -z "$slangroom_contract" ]; then
slangroom_contract=$(encode_base64 -)
fi

# Print the encoded string
echo -e "${conf}\n${slangroom_contract}\n${data}\n${keys}\n${extra}\n${context}"
printf "${conf}\n${slangroom_contract}\n${data}\n${keys}\n${extra}\n${context}"

2 changes: 1 addition & 1 deletion test/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ setup() {
run_slangroom_exec
assert_output --partial "Invalid Zencode prefix 1: 'Gibberish'"
assert_failure 1
}
}
2 changes: 1 addition & 1 deletion test/test_helper/common-setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ load_fixture() {

run_slangroom_exec() {
bats_require_minimum_version 1.5.0
run bats_pipe echo "$slang_input" \| ./slangroom-exec
run bats_pipe printf "$slang_input" \| ./slangroom-exec
}