Skip to content

Commit

Permalink
chore: updated release config
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined committed Aug 6, 2024
1 parent bf42e2f commit 664c624
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
44 changes: 29 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,54 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ created ]

jobs:

release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

- name: Build all architectures
run: make build-all
env:
VERSION: ${{ steps.semantic.outputs.new_release_version }}

- name: Upload Release Assets
uses: softprops/action-gh-release@v1
if: steps.semantic.outputs.new_release_published == 'true'
with:
files: |
build/*
files: build/*
tag_name: v${{ steps.semantic.outputs.new_release_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'

- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update main branch with release commit
if: steps.semantic.outputs.new_release_published == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "chore(release): ${{ steps.semantic.outputs.new_release_version }} [skip ci]"
git push
20 changes: 20 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}],
["@semantic-release/git", {
"assets": ["CHANGELOG.md", "package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}],
["@semantic-release/exec", {
"prepareCmd": "make build VERSION=${nextRelease.version}",
"publishCmd": "echo 'Binary version ${nextRelease.version} has been built'"
}],
"@semantic-release/github",
"@semantic-release/npm"
]
}
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=squish
BINARY_UNIX=$(BINARY_NAME)_unix
MAIN_GO=./cmd/squish/main.go

# Build directory
BUILD_DIR=build

# Version (to be overwritten by semantic-release)
VERSION ?= development

# Ldflags for stripping debug information and setting version
LDFLAGS=-ldflags "-s -w -X main.Version=$(VERSION)"

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

Expand All @@ -18,7 +25,7 @@ PLATFORMS=darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm linux/arm64
all: test build

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

test:
$(GOTEST) -v ./...
Expand All @@ -37,7 +44,7 @@ build-all: clean
$(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 ./cmd/squish\
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) $(LDFLAGS) -o $(BINARY) -v $(MAIN_GO) \
&& if [ "$(GOOS)" = "linux" ]; then \
if [ "$(GOARCH)" = "amd64" ]; then \
cp $(BINARY) $(BUILD_DIR)/$(BINARY_NAME)-linux-x86_64; \
Expand All @@ -49,11 +56,11 @@ build-all: clean

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

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

# Dependencies
Expand Down
9 changes: 8 additions & 1 deletion cmd/squish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import (
"squish/internal/cli"
)

var Version = "development"

func main() {
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Printf("Squish version %s\n", Version)
return
}

if err := cli.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
fmt.Println(err)
os.Exit(1)
}
}
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@foxycorps/squish",
"version": "0.1.0",
"version": "0.0.0",
"description": "A minimalistic package bundler for TypeScript",
"bin": {
"squish": "./bin/squish"
},
"scripts": {
"postinstall": "node install.js"
"postinstall": "node install.js",
"semantic-release": "semantic-release"
},
"files": [
"bin",
Expand All @@ -28,8 +29,14 @@
"url": "https://github.com/foxycorps/squish/issues"
},
"homepage": "https://github.com/foxycorps/squish#readme",
"dependencies": {
"node-fetch": "^3.3.2"
},
"devDependencies": {
"node-fetch": "^3.2.0"
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"semantic-release": "^19.0.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down

0 comments on commit 664c624

Please sign in to comment.