diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c306f64..316c6eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -11,13 +18,13 @@ 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: @@ -25,5 +32,24 @@ jobs: - 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 }} diff --git a/.gitignore b/.gitignore index 0da5af0..54833a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ slangroom-exec +slangroom-exec-* # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore # Logs diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..ec178ca --- /dev/null +++ b/.releaserc @@ -0,0 +1,48 @@ +{ + "repositoryUrl": "git@github.com: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" + ] +} diff --git a/Makefile b/Makefile index b785ef4..80582f2 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/src/slexfe b/src/slexfe index abc9d16..6c60b82 100755 --- a/src/slexfe +++ b/src/slexfe @@ -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 @@ -48,43 +56,39 @@ 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 @@ -92,4 +96,5 @@ if [ -z "$slangroom_contract" ]; then 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}" + diff --git a/test/e2e.bats b/test/e2e.bats index 089e630..7a3b2f9 100644 --- a/test/e2e.bats +++ b/test/e2e.bats @@ -48,4 +48,4 @@ setup() { run_slangroom_exec assert_output --partial "Invalid Zencode prefix 1: 'Gibberish'" assert_failure 1 -} \ No newline at end of file +} diff --git a/test/test_helper/common-setup.bash b/test/test_helper/common-setup.bash index aef6f5c..ac09002 100644 --- a/test/test_helper/common-setup.bash +++ b/test/test_helper/common-setup.bash @@ -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 } \ No newline at end of file