From 664c62485fd931d771f88b960a6a371dbcc283be Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 6 Aug 2024 17:35:22 +1000 Subject: [PATCH] chore: updated release config --- .github/workflows/ci.yaml | 44 ++++++++++++++++++++++++++------------- .releaserc | 20 ++++++++++++++++++ Makefile | 15 +++++++++---- cmd/squish/main.go | 9 +++++++- package.json | 13 +++++++++--- 5 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 .releaserc diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 110d3a4..1b4ad5d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 }} \ No newline at end of file + - 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 \ No newline at end of file diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..4f62935 --- /dev/null +++ b/.releaserc @@ -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" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 6330bad..e0e5b2f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ./... @@ -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; \ @@ -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 diff --git a/cmd/squish/main.go b/cmd/squish/main.go index 6a70de7..24ca21c 100644 --- a/cmd/squish/main.go +++ b/cmd/squish/main.go @@ -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) } } diff --git a/package.json b/package.json index 8443f75..e7cd37f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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"