Skip to content

Commit

Permalink
feat: add --version flag (#18)
Browse files Browse the repository at this point in the history
resolves #17
  • Loading branch information
BrunnerLivio authored Oct 5, 2023
1 parent c593050 commit 2eefe0f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 60 deletions.
1 change: 1 addition & 0 deletions .VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__VERSION__
43 changes: 29 additions & 14 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,32 @@ env:
IMAGE_NAME: brunnerlivio/tsp-web

jobs:
"next-version":
permissions:
contents: write
packages: read
pages: read
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18.x
cache: npm
- name: Install dependencies
run: npm ci
- name: Next version
run: DRY_RUN=true npm run semantic-release -- --dry-run --no-ci
- name: Archive Version
uses: actions/upload-artifact@v3
with:
name: "VERSION"
path: .VERSION

"build":
needs: ["next-version"]
strategy:
matrix:
version:
Expand All @@ -32,33 +57,23 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: "1.19"

- uses: actions/download-artifact@master
with:
name: "VERSION"
- name: Install dependencies
run: make install

- name: Build ${{ matrix.version.NAME }}
run: GOOS=${{ matrix.version.GOOS }} GOARCH=${{ matrix.version.GOARCH }} GOARM=${{ matrix.version.GOARM }} go build -o ${{ matrix.version.OUTPUT }} ./main.go

- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: "tsp-web"
path: |
.bin/*
"docker-build":
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

"semantic-release":
runs-on: ubuntu-latest
needs: ["build", "docker-build"]
needs: ["build"]
permissions:
contents: write
packages: write
Expand Down
78 changes: 40 additions & 38 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,46 @@ const plugins = [
registry: process.env.REGISTRY || "ghcr.io",
},
],
[
"@semantic-release/github",
{
assets: [
// Windows
{
path: "tsp-web.exe",
label: "TSP Web (windows/amd64)",
},
// Linux
{
path: "tsp-web_linux_amd64",
label: "TSP Web (linux/amd64)",
},
{
path: "tsp-web_linux_arm64",
label: "TSP Web (linux/arm64)",
},
{
path: "tsp-web_linux_armv5",
label: "TSP Web (linux/armv5)",
},
{
path: "tsp-web_linux_armv7",
label: "TSP Web (linux/armv7)",
},
// Mac
{
path: "tsp-web_darwin_arm64",
label: "TSP Web (darwin/arm64)",
},
{
path: "tsp-web_darwin_amd64",
label: "TSP Web (darwin/amd64)",
},
],
},
],
process.env.DRY_RUN === "true"
? null
: [
"@semantic-release/github",
{
assets: [
// Windows
{
path: "tsp-web.exe",
label: "TSP Web (windows/amd64)",
},
// Linux
{
path: "tsp-web_linux_amd64",
label: "TSP Web (linux/amd64)",
},
{
path: "tsp-web_linux_arm64",
label: "TSP Web (linux/arm64)",
},
{
path: "tsp-web_linux_armv5",
label: "TSP Web (linux/armv5)",
},
{
path: "tsp-web_linux_armv7",
label: "TSP Web (linux/armv7)",
},
// Mac
{
path: "tsp-web_darwin_arm64",
label: "TSP Web (darwin/arm64)",
},
{
path: "tsp-web_darwin_amd64",
label: "TSP Web (darwin/amd64)",
},
],
},
],
].filter(Boolean);

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ts -L sleep sleep 30
| `--host` | `TSP_WEB_HOSTNAME` | The hostname to run TSP-Web on | `192.168.0.20` | `localhost` |
| `--log-level` | `TSP_WEB_LOG_LEVEL` | The log level can be `'debug' or 'info' or 'warn'` | `warn` | `info` |
| `--no-color` | - | Whether the logs should be displayed without colors | - | `false` |
| `--version` | - | Prints the version | - | |

### Configuration

Expand Down
1 change: 1 addition & 0 deletions internal/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type TspWebArgs struct {
LogLevel string
NoColor bool
Host string
Version bool
}
24 changes: 16 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
//go:embed web/*
var static embed.FS

//go:embed .VERSION
var version string

const maxPort uint64 = 65535

func parseArgs() (args.TspWebArgs, error) {
Expand All @@ -29,11 +32,14 @@ func parseArgs() (args.TspWebArgs, error) {
logLevel := flag.String("log-level", utils.Getenv("TSP_WEB_LOG_LEVEL", "info"), "The log level for tsp-web")
noColor := flag.Bool("no-color", false, "Disable colorized output")
host := flag.String("host", utils.Getenv("TSP_WEB_HOSTNAME", "localhost"), "The host for tsp-web")
version := flag.Bool("version", false, "Print the version and exit")

flag.Parse()

if *portArg > maxPort {
return args.TspWebArgs{}, fmt.Errorf("invalid value \"%d\" for flag -port: parse error", *portArg)
log.Errorf("invalid value \"%d\" for flag -port: value out of range", *portArg)
flag.Usage()
os.Exit(1)
}

Port := uint16(*portArg)
Expand All @@ -43,7 +49,9 @@ func parseArgs() (args.TspWebArgs, error) {
Port: Port,
LogLevel: *logLevel,
NoColor: *noColor,
Host: *host}, nil
Host: *host,
Version: *version,
}, nil
}

func setLogLevel(logLevel string) {
Expand All @@ -63,18 +71,18 @@ func main() {
api.Static = static

args, err := parseArgs()

if args.Version {
fmt.Println(version)
os.Exit(0)
}

setLogLevel(args.LogLevel)
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
DisableColors: args.NoColor,
})

if err != nil {
log.Error(err)
flag.Usage()
os.Exit(1)
}

userconf.Load(args)
go userconf.StartWatcher(args)
err = api.Run(args)
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"scripts": {
"semantic-release": "semantic-release"
},
"repository": {
"type": "git",
"url": "https://github.com/brunnerlivio/tsp-web"
},
"devDependencies": {
"@semantic-release-plus/docker": "^3.1.2",
"@semantic-release/changelog": "^6.0.3",
Expand Down

0 comments on commit 2eefe0f

Please sign in to comment.