Skip to content

Commit

Permalink
Update logger. Update build process to use Generate. Rearrange code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexbritvin committed Oct 23, 2024
1 parent 0eb8754 commit 72a4078
Show file tree
Hide file tree
Showing 24 changed files with 1,387 additions and 936 deletions.
68 changes: 30 additions & 38 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
name: Create Archive on Tag
name: Create release

on:
push:
tags:
- '*'
- "v*.*.*"

jobs:
build_and_archive:
create_release:
name: build / push
runs-on: ubuntu-latest

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

- name: Set up Node.js 21
- name: Set up Node.js 22 (LTS)
uses: actions/setup-node@v4
with:
node-version: '21'
node-version: '22'

- name: Enable Corepack
working-directory: client
run: corepack enable

- name: Install dependencies
working-directory: client
run: yarn install

- name: Build project
working-directory: client
run: yarn build

- name: Create archives of dist folder
- name: Build the artifacts
working-directory: client
run: |
zip -r dist.zip dist
tar -czvf dist.tar.gz dist
corepack enable
yarn install
yarn build
- name: Upload archives as artifacts
uses: actions/upload-artifact@v4
with:
name: dist.zip
path: client/dist.zip

- name: Upload tar.gz as artifact
uses: actions/upload-artifact@v4
with:
name: dist.tar.gz
path: client/dist.tar.gz
- name: Create web client artifacts
working-directory: client/dist
run: |
tar -czf ../../client-assets.tar.gz *
zip -r ../../client-assets.zip *
- name: Upload dist.zip and dist.tar.gz to the release
uses: svenstaro/upload-release-action@v2
- name: Determine if prerelease
run: |
TAG="${GITHUB_REF##*/}"
if [[ "$TAG" == *-* ]]; then
echo "PRERELEASE=true" >> $GITHUB_ENV
else
echo "PRERELEASE=false" >> $GITHUB_ENV
fi
- name: Release
uses: softprops/action-gh-release@v2
with:
file: client/dist.*
file_glob: true
tag: ${{ github.ref_name }}
release_name: ${{ github.ref_name }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
prerelease: ${{ env.PRERELEASE }}
files: |
client-assets.tar.gz
client-assets.zip
31 changes: 17 additions & 14 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,24 @@ run:
deadline: 10s
issues-exit-code: 1
tests: true
skip-dirs:
- bin
- vendor
- var
- tmp
skip-files:
- \.pb\.go$
- \.pb\.goclay\.go$
- \.gen.go$
- server/streams.go # @fixme remove when implemented

output:
format: colored-line-number
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
govet:
check-shadowing: true
shadow: true
golint:
min-confidence: 0
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2

linters:
disable-all: true
enable:
Expand All @@ -43,10 +34,22 @@ linters:
- goconst
- gosec
- goimports
- megacheck # (staticcheck + gosimple + unused in one linter) - enable before push
- gosimple
- staticcheck
- unused

issues:
exclude-use-default: false
exclude-dirs:
- bin
- vendor
- var
- tmp
exclude-files:
- \.pb\.go$
- \.pb\.goclay\.go$
- \.gen.go$
- server/streams.go # @fixme remove when implemented
exclude:
# # _ instead of err checks
# - G104
Expand Down
27 changes: 12 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export GOSUMDB=off

GOPATH?=$(HOME)/go
FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))

NODE_TAG=21-alpine3.19
NODE_TAG=22 # Always use LTS
SWAGGER_UI_DIR:=./swagger-ui

# Build available information.
GIT_HASH:=$(shell git log --format="%h" -n 1 2> /dev/null)
Expand All @@ -19,12 +18,6 @@ else
LDFLAGS_EXTRA=-s -w
BUILD_OPTS=-trimpath
endif
DEV?=0
ifeq ($(DEV), 1)
BUILD_OPTS+=-tags dev
else
BUILD_OPTS+=-tags embed
endif

BUILD_ENVPARMS:=CGO_ENABLED=0

Expand All @@ -33,25 +26,28 @@ LOCAL_BIN:=$(CURDIR)/bin

# Linter config.
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
GOLANGCI_TAG:=1.55.2

SWAGGER_UI_DIR:=./swagger-ui
GOLANGCI_TAG:=1.61.0

.PHONY: all
all: deps test build
all: deps front test build

# Install go dependencies
.PHONY: deps
deps:
$(info Installing go dependencies...)
go mod download

# Build front dependencies.
.PHONY: front
front: front-install front-build
@if [ ! -d "$(SWAGGER_UI_DIR)" ]; then \
echo "Downloading Swagger UI..."; \
curl -Ss https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | grep tarball_url | cut -d '"' -f 4 |\
xargs curl -LsS -o swagger-ui.tar.gz; \
xargs curl -LsS -o swagger-ui.tar.gz; \
rm -rf $(SWAGGER_UI_DIR) $(SWAGGER_UI_DIR)-tmp && mkdir $(SWAGGER_UI_DIR)-tmp; \
tar xzf swagger-ui.tar.gz -C $(SWAGGER_UI_DIR)-tmp --strip=1; \
mv $(SWAGGER_UI_DIR)-tmp/dist $(SWAGGER_UI_DIR) && rm -rf $(SWAGGER_UI_DIR)-tmp && rm swagger-ui.tar.gz; \
mv $(SWAGGER_UI_DIR)-tmp/dist $(SWAGGER_UI_DIR); \
rm -rf $(SWAGGER_UI_DIR)-tmp && rm swagger-ui.tar.gz; \
sed -i.bkp "s|https://petstore.swagger.io/v2/swagger.json|/api/swagger.json|g" $(SWAGGER_UI_DIR)/swagger-initializer.js; \
fi

Expand All @@ -68,6 +64,7 @@ build:
# Application related information available on build time.
$(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
$(eval BIN?=$(LOCAL_BIN)/launchr)
go generate ./...
$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr

# Install launchr
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bin/launchr web --help

The documentation for `launchr` usage can be found in [the main project](https://github.com/launchrctl/launchr).

@todo update readme
## To build the client:
### Node
```shell
Expand Down Expand Up @@ -79,6 +80,7 @@ Useful make commands:
2. Test the code - `make test`
3. Lint the code - `make lint`

@todo review
## Test for release

```shell
Expand Down
59 changes: 59 additions & 0 deletions assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package web

import (
"io/fs"
"os"
"path/filepath"
)

var clientAssetsFS fs.FS
var swaggerAssetsFS fs.FS

// SetClientAssetsFS sets the global web client assets filesystem.
func SetClientAssetsFS(f fs.FS) {
clientAssetsFS = f
}

// SetSwaggerUIAssetsFS sets the filesystem containing the swagger UI assets.
func SetSwaggerUIAssetsFS(f fs.FS) {
swaggerAssetsFS = f
}

// GetClientAssetsFS returns web client assets.
func GetClientAssetsFS() fs.FS {
if clientAssetsFS != nil {
return clientAssetsFS
}
// If client assets were not set, we are in the development environment.
path := filepath.Join("client", "dist")
_, err := os.Stat(path)
if os.IsNotExist(err) {
panic(path + " assets are not available")
}
SetClientAssetsFS(os.DirFS(path))
return clientAssetsFS
}

// GetSwaggerUIAssetsFS returns web assets for swagger-ui.
func GetSwaggerUIAssetsFS() (fs.FS, error) {
if swaggerAssetsFS != nil {
return swaggerAssetsFS, nil
}
// If client assets were not set, we are in the development environment.
path := filepath.Join("swagger-ui")
_, err := os.Stat(path)
if err != nil {
return nil, err
}
SetSwaggerUIAssetsFS(os.DirFS(path))
return swaggerAssetsFS, nil
}

// MustSubFS returns fs by subpath.
func MustSubFS(orig fs.FS, path string) fs.FS {
sub, err := fs.Sub(orig, path)
if err != nil {
panic(err)
}
return sub
}
13 changes: 13 additions & 0 deletions cmd/launchr/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build ignore

package main

import (
"github.com/launchrctl/launchr"

_ "github.com/launchrctl/web"
)

func main() {
launchr.GenAndExit()
}
5 changes: 2 additions & 3 deletions cmd/launchr/launchr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
package main

import (
"os"

"github.com/launchrctl/launchr"

_ "github.com/launchrctl/web"
)

func main() {
os.Exit(launchr.Run(&launchr.AppOptions{}))
launchr.RunAndExit()
}
37 changes: 0 additions & 37 deletions files.dev.go

This file was deleted.

31 changes: 0 additions & 31 deletions files.release.go

This file was deleted.

Loading

0 comments on commit 72a4078

Please sign in to comment.