Skip to content

Commit

Permalink
build binary for all
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Nov 8, 2024
1 parent 1026140 commit 5beca53
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
45 changes: 3 additions & 42 deletions .github/workflows/exe.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Release
name: Build exe

on:
push:
Expand Down Expand Up @@ -48,54 +48,15 @@ jobs:
with:
go-version: "1.23"

- name: Set Version
run: |
if [ "${{ github.event_name }}" == "push" && startsWith(github.ref, 'refs/tags/') ]; then
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
fi
- name: Create bin directory
run: mkdir -p exe/bin

- name: Build for Windows
run: |
cd exe && GOOS=windows GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o bin/myapp-windows-amd64.exe
- name: Build for macOS
run: |
cd exe && GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o bin/myapp-darwin-amd64
- name: Build for Linux
run: |
cd exe && GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o bin/myapp-linux-amd64
# Add executable permissions to macOS and Linux binaries
- name: Make binaries executable
run: |
chmod +x exe/bin/myapp-darwin-amd64
chmod +x exe/bin/myapp-linux-amd64
- name: Build exe
run: cd exe && make

# Upload as workflow artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: exe/bin/*

# Create Release
# - name: Create Release
# if: startsWith(github.ref, 'refs/tags/')
# id: create_release
# uses: softprops/action-gh-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# files: |
# bin/myapp-windows-amd64.exe
# bin/myapp-darwin-amd64
# bin/myapp-linux-amd64
# draft: false
# prerelease: false
# generate_release_notes: true
56 changes: 56 additions & 0 deletions exe/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Variables
VERSION ?= $(shell git describe --tags --always --dirty)
BINARY_NAME=noStrudel
BUILD_DIR=bin

# Build flags
LDFLAGS=-ldflags="-X 'main.Version=${VERSION}'"

# Ensure builds directory exists
$(shell mkdir -p ${BUILD_DIR})

.PHONY: all clean windows linux darwin

all: copy windows linux darwin

# Build source
copy: source
cp -r ../dist/* web

source:
cd ../ && \
pnpm install && \
VITE_COMMIT_HASH=$(shell git rev-parse --short HEAD) \
VITE_APP_VERSION=$(shell jq -r .version ../package.json) \
pnpm build

# Windows builds
windows: windows-amd64 windows-arm64

windows-amd64:
GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-windows-amd64.exe

windows-arm64:
GOOS=windows GOARCH=arm64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-windows-arm64.exe

# Linux builds
linux: linux-amd64 linux-arm64

linux-amd64:
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-linux-amd64

linux-arm64:
GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-linux-arm64

# macOS builds
darwin: darwin-amd64 darwin-arm64

darwin-amd64:
GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-darwin-amd64

darwin-arm64:
GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME}-darwin-arm64

# Clean build directory
clean:
rm -rf ${BUILD_DIR}/*
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { VitePWA } from "vite-plugin-pwa";

console.log("Build with:");
for (const [key, value] of Object.entries(process.env)) {
if (key.startsWith("VITE_")) console.log(`${key}: ${value}`);
}

// https://vitejs.dev/config/
export default defineConfig({
base: process.env.VITE_BASE ?? "/",
Expand Down

0 comments on commit 5beca53

Please sign in to comment.