diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml new file mode 100644 index 0000000..d84d29e --- /dev/null +++ b/.github/workflows/releaser.yml @@ -0,0 +1,49 @@ +# .github/workflows/release.yml +name: goreleaser + +on: + pull_request: + push: + # run only against tags + tags: + - "*" + +permissions: + contents: write + packages: write + # issues: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + # More assembly might be required: Docker logins, GPG, etc. + # It all depends on your needs. + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + # 'latest', 'nightly', or a semver + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + - name: Publish to NPM + uses: actions/setup-node@v4 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + run: cd ./npm && npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 4b74373..1f7185a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ go.work .amock/ dist/ +build/ +cmd/ +.idea/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 32b2c54..928192c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,6 +12,7 @@ before: hooks: - go mod download - go mod tidy + - cd npm && npm version from-git builds: - env: @@ -80,6 +81,11 @@ brews: folder: Formula + repository: + owner: matronator + name: homebrew-tap + branch: main + # Caveats for the user of your binary. # Default is empty. caveats: "" @@ -90,7 +96,7 @@ brews: # SPDX identifier of your app's license. # Default is empty. - license: "MIT" + license: "GPL-3.0-only" # Packages your package depends on. dependencies: diff --git a/.idea/amock.iml b/.idea/amock.iml index 5e764c4..999be74 100644 --- a/.idea/amock.iml +++ b/.idea/amock.iml @@ -2,7 +2,10 @@ - + + + + diff --git a/Formula/amock.rb b/Formula/amock.rb deleted file mode 100644 index cf05aa2..0000000 --- a/Formula/amock.rb +++ /dev/null @@ -1,43 +0,0 @@ -# typed: false -# frozen_string_literal: true - -# This file was generated by GoReleaser. DO NOT EDIT. -class Amock < Formula - desc "A simple mock server for REST APIs." - homepage "https://github.com/matronator/amock" - version "0.1.2" - license "MIT" - - depends_on "git" - depends_on "go" - - on_macos do - if Hardware::CPU.intel? - url "https://github.com/matronator/amock/releases/download/v0.1.2/amock_Darwin_x86_64.tar.gz" - sha256 "f4f950995563d22ce98754b5237dc4043cf80c3c150d16fded30eaca5490032a" - - def install - bin.install "amock" - end - end - if Hardware::CPU.arm? - url "https://github.com/matronator/amock/releases/download/v0.1.2/amock_Darwin_arm64.tar.gz" - sha256 "8c310d787c5e8590902c613efc3b13957e5c2239c4eb57e457841a6d3a869da9" - - def install - bin.install "amock" - end - end - end - - on_linux do - if Hardware::CPU.intel? - url "https://github.com/matronator/amock/releases/download/v0.1.2/amock_Linux_x86_64.tar.gz" - sha256 "f7c1a14ce068eddff9ec547f44091d8e2c9c51d7b513a23fe175fe6cda79ea21" - - def install - bin.install "amock" - end - end - end -end diff --git a/README.md b/README.md index ea65dac..0b9ebd7 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,23 @@ Amock is a simple API mock server that uses JSON files to define entities from w * [Amock](#amock) * [API Mock Server](#api-mock-server) * [Instalation](#instalation) + * [npm (macOS, Linux, Windows)](#npm-macos-linux-windows) + * [GoBinaries (macOS, Linux)](#gobinaries-macos-linux) * [Homebrew (macOS)](#homebrew-macos) - * [Download from releases (macOS, Linux, Windows)](#download-from-releases-macos-linux-windows) - * [Manual installation (macOS, Linux, Windows)](#manual-installation-macos-linux-windows) + * [Manually download from releases (macOS, Linux, Windows)](#manually-download-from-releases-macos-linux-windows) + * [1. Move the binary to `/usr/local/bin` or some other folder in your PATH:](#1-move-the-binary-to-usrlocalbin-or-some-other-folder-in-your-path) + * [macOS/Linux](#macoslinux) + * [Windows](#windows) + * [2. Add the directory to your PATH:](#2-add-the-directory-to-your-path) + * [macOS/Linux](#macoslinux-1) + * [Windows](#windows-1) + * [With GUI (recommended)](#with-gui-recommended) + * [With PowerShell](#with-powershell) + * [Build from source (macOS, Linux, Windows)](#build-from-source-macos-linux-windows) + * [macOS/Linux](#macoslinux-2) + * [Windows](#windows-2) + * [With GUI (recommended)](#with-gui-recommended-1) + * [With PowerShell](#with-powershell-1) * [Usage](#usage) * [Configuration](#configuration) * [Entity files](#entity-files) @@ -26,32 +40,120 @@ Amock is a simple API mock server that uses JSON files to define entities from w ## Instalation +### npm (macOS, Linux, Windows) + +```bash +npm install -g amock-cli +``` + +### GoBinaries (macOS, Linux) + +```bash +curl -sf https://gobinaries.com/matronator/amock | sh +``` + ### Homebrew (macOS) ```bash brew install matronator/tap/amock ``` -### Download from releases (macOS, Linux, Windows) +### Manually download from releases (macOS, Linux, Windows) + +Go to the [releases page](https://github.com/matronator/amock/releases/latest) and download the latest version for your OS. Extract the files and do either one of these: -Go to the [releases page](https://github.com/matronator/amock/releases/latest) and download the latest version for your OS. Extract the files and move the binary to a directory in your PATH or add the directory to your PATH. +1. Move the binary to a folder in your `$PATH`, or... +2. Add the folder to your `$PATH` + +#### 1. Move the binary to `/usr/local/bin` or some other folder in your PATH: + +##### macOS/Linux ```bash -# Either move the binary to a directory in your PATH -mv path/to/extracted/binary/amock /usr/local/bin +sudo mv path/to/extracted/binary/amock /usr/local/bin +``` -# Or add the directory to your PATH +##### Windows + +```txt +move path\to\extracted\binary\amock.exe C:\path\to\bin +``` + +#### 2. Add the directory to your PATH: + +First move the extracted binary to some permanent folder. Then add the directory to your PATH by running: + +##### macOS/Linux + +```bash export PATH=$PATH:path/to/extracted/binary ``` -### Manual installation (macOS, Linux, Windows) +To make this permanent, add this line to your `~/.bashrc` or `~/.zshrc` or `~/.profile` file. + +##### Windows + +###### With GUI (recommended) -Requires Go 1.16 or later +1. Open `"My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path"` +2. Add the path to the `amock.exe` file to the list +3. Restart your terminal + +###### With PowerShell + +```powershell +$PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine") +$amock_path = "C:\path\to\amock" +if( $PATH -notlike "*"+$amock_path+"*" ){ + [Environment]::SetEnvironmentVariable("PATH", "$PATH;$amock_path", "Machine") +} +``` + +### Build from source (macOS, Linux, Windows) + +> [!IMPORTANT] +> Requires Go 1.16 or later + +#### macOS/Linux + +```bash +git clone https://github.com/matronator/amock.git +cd amock +go build -o cmd/amock -ldflags="-s -w" . +sudo mv cmd/amock /usr/local/bin +# have to use sudo because /usr/local/bin is protected +``` + +Make sure that /user/local/bin is in your PATH. If not edit your `~/.bashrc` or `~/.zshrc` or `~/.profile` and add the following line: + +```bash +export PATH=$PATH:/usr/local/bin +``` + +#### Windows ```bash git clone https://github.com/matronator/amock.git cd amock -go install +go build -o cmd/amock.exe -ldflags="-s -w" . +``` + +Next move the `amock.exe` to some permanent location and add it to your PATH with either the GUI or PowerShell: + +##### With GUI (recommended) + +1. Open `"My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path"` +2. Add the path to the `amock.exe` file to the list +3. Restart your terminal + +##### With PowerShell + +```powershell +$PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine") +$amock_path = "C:\path\to\amock" +if( $PATH -notlike "*"+$amock_path+"*" ){ + [Environment]::SetEnvironmentVariable("PATH", "$PATH;$amock_path", "Machine") +} ``` ## Usage diff --git a/build/amock b/cmd/amock similarity index 56% rename from build/amock rename to cmd/amock index 6dad3f1..2840143 100755 Binary files a/build/amock and b/cmd/amock differ diff --git a/.amock.json b/examples/.amock.json similarity index 100% rename from .amock.json rename to examples/.amock.json diff --git a/npm/package.json b/npm/package.json index 3ce7569..8fb85aa 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "amock-cli", - "version": "0.1.2", + "version": "0.1.3", "description": "Simple API mock server", "main": "index.js", "directories": {