build binary for all

This commit is contained in:
hzrd149 2024-11-08 13:27:12 +00:00
parent 10261400ef
commit 5beca53c97
3 changed files with 64 additions and 42 deletions

View File

@ -1,4 +1,4 @@
name: Build and Release
name: Build exe
on:
push:
@ -48,34 +48,11 @@ 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
@ -83,19 +60,3 @@ jobs:
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
exe/makefile Normal file
View File

@ -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}/*

View File

@ -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 ?? "/",