Skip to content

Commit

Permalink
chore: updated release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined committed Aug 6, 2024
1 parent d26ba0a commit 3d79676
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 111 deletions.
59 changes: 8 additions & 51 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,28 @@ on:

jobs:

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

release:
name: Release
needs: test
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.22.5'

- name: Build
run: |
GOOS=linux GOARCH=amd64 go build -o squish-linux-amd64
GOOS=darwin GOARCH=amd64 go build -o squish-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o squish-windows-amd64.exe
- name: Build all architectures
run: make build-all

- name: Upload Release Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./squish-linux-amd64
asset_name: squish-linux-amd64
asset_content_type: application/octet-stream

- name: Upload Release Assets (MacOS)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./squish-darwin-amd64
asset_name: squish-darwin-amd64
asset_content_type: application/octet-stream

- name: Upload Release Assets (Windows)
uses: actions/upload-release-asset@v1
files: |
build/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./squish-windows-amd64.exe
asset_name: squish-windows-amd64.exe
asset_content_type: application/octet-stream

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -83,6 +40,6 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Publish to npm
run: pnpm publish --access public
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
node_modules
/squish
build/
/squish_unix
73 changes: 37 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
BINARY_NAME=squish
BINARY_UNIX=$(BINARY_NAME)_unix

# Build directory
BUILD_DIR=build

# Supported OSs and Architectures
PLATFORMS=darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm linux/arm64 windows/386 windows/amd64

.PHONY: all test clean build build-all

all: test build

build:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/squish
$(GOBUILD) -o $(BINARY_NAME) -v

test:
$(GOTEST) -v ./...
Expand All @@ -20,41 +27,35 @@ clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)

rm -rf $(BUILD_DIR)

build-all: clean
mkdir -p $(BUILD_DIR)
$(foreach platform,$(PLATFORMS),\
$(eval GOOS=$(word 1,$(subst /, ,$(platform))))\
$(eval GOARCH=$(word 2,$(subst /, ,$(platform))))\
$(eval EXTENSION=$(if $(filter windows,$(GOOS)),.exe))\
$(eval BINARY=$(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(EXTENSION))\
echo "Building for $(GOOS)/$(GOARCH)..." && \
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -o $(BINARY) -v \
&& if [ "$(GOOS)" = "linux" ]; then \
if [ "$(GOARCH)" = "amd64" ]; then \
cp $(BINARY) $(BUILD_DIR)/$(BINARY_NAME)-linux-x86_64; \
elif [ "$(GOARCH)" = "arm64" ]; then \
cp $(BINARY) $(BUILD_DIR)/$(BINARY_NAME)-linux-aarch64; \
fi; \
fi; \
)

# Cross compilation for Unix
build-unix:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v

# Run the application
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./cmd/squish
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)

# Dependencies
deps:
$(GOGET) ./...
$(GOMOD) tidy

# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v ./cmd/squish

# Linting
lint:
golangci-lint run

# Format code
fmt:
gofmt -s -w .

# Check if code is formatted
fmt-check:
test -z $$(gofmt -l .)

# Generate mocks for testing
mocks:
mockgen -source=pkg/esbuild/plugin.go -destination=pkg/esbuild/mocks/mock_plugin.go

# Self-bundle (assuming squish can bundle itself)
self-bundle: build
./$(BINARY_NAME) --src ./cmd/squish --dist ./dist

# Install golangci-lint
install-linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1

.PHONY: all build test clean run deps build-linux lint fmt fmt-check mocks self-bundle install-linter
$(GOGET) -v ./...
24 changes: 0 additions & 24 deletions main.go

This file was deleted.

0 comments on commit 3d79676

Please sign in to comment.