Skip to content

Commit 382b5b4

Browse files
authored
build: Add automated GitHub Actions release workflow (#2)
- Includes adjustments to build process to assign dev version numbers based on commit count
1 parent da1835f commit 382b5b4

File tree

4 files changed

+203
-19
lines changed

4 files changed

+203
-19
lines changed

.github/workflows/release.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Create Release
2+
3+
# TRIGGERS: When this workflow runs
4+
on:
5+
push:
6+
tags:
7+
- 'v*' # Trigger on version tags like v0.1.0
8+
workflow_dispatch: # Allow manual triggering from Actions tab
9+
10+
# PERMISSIONS: What this workflow can do
11+
permissions:
12+
contents: write # Required to create releases and push tags
13+
14+
jobs:
15+
release:
16+
strategy:
17+
matrix:
18+
include:
19+
- os: windows-latest
20+
- os: ubuntu-latest
21+
22+
runs-on: ${{ matrix.os }}
23+
24+
steps:
25+
# STEP: Install dependencies for Windows
26+
- name: Install dependencies for Windows
27+
if: runner.os == 'Windows'
28+
run: |
29+
choco install --no-progress pandoc # Set up Pandoc (for markdown to HTML conversion)
30+
choco install --no-progress innosetup # Set up Inno Setup (for building Windows installers)
31+
32+
# STEP: Set up MSYS2 environment
33+
- name: Set up MSYS2 (Windows only)
34+
if: runner.os == 'Windows'
35+
uses: msys2/setup-msys2@v2
36+
with:
37+
update: true
38+
msystem: ucrt64
39+
install: >-
40+
curl
41+
git
42+
zip
43+
make
44+
mingw-w64-ucrt-x86_64-gcc
45+
mingw-w64-ucrt-x86_64-boost
46+
env:
47+
MSYS2_PATH_TYPE: inherit
48+
49+
# STEP: Install dependencies for Linux
50+
- name: Install dependencies for Linux
51+
if: runner.os == 'Linux'
52+
run: |
53+
sudo apt-get update
54+
sudo apt-get install -y \
55+
pandoc \
56+
zip \
57+
make \
58+
gcc \
59+
g++ \
60+
libboost-all-dev
61+
62+
# STEP: Get the repository code
63+
- name: Checkout code
64+
uses: actions/checkout@v6
65+
with:
66+
fetch-depth: 0 # Fetch full history so we can count all commits
67+
68+
# STEP: Determine version
69+
# - Tagged releases: use version from tag (e.g. v0.1.0)
70+
# - Dev builds: use dev.<commit_count>
71+
# - Parse version components into environment variables for build system
72+
- name: Determine version
73+
id: version
74+
shell: bash
75+
run: |
76+
TAG=$(git tag --points-at HEAD | grep '^v' | sort -V | tail -n 1 || true)
77+
BUILD_COMMIT_COUNT=$(git rev-list --count HEAD)
78+
79+
if [[ -n "$TAG" ]]; then
80+
# Tagged production release: use version from tag (e.g. v0.1.0)
81+
VERSION="${TAG}"
82+
IS_TAGGED=true
83+
else
84+
# Development build: use version dev.<commit count>
85+
VERSION="dev.${BUILD_COMMIT_COUNT}"
86+
IS_TAGGED=false
87+
fi
88+
echo "version=$VERSION" >> $GITHUB_OUTPUT
89+
echo "is_tagged=$IS_TAGGED" >> $GITHUB_OUTPUT
90+
echo "Version: $VERSION (tagged: $IS_TAGGED)"
91+
92+
# Parse version components into environment variables for build system
93+
if [[ "$VERSION" =~ ^v([0-9]+)\.([0-9]+)$ ]]; then
94+
# vX.Y format
95+
echo "ENV_BUILD_VERSION_MAJOR=${BASH_REMATCH[1]}" >> $GITHUB_ENV
96+
echo "ENV_BUILD_VERSION_MINOR=${BASH_REMATCH[2]}" >> $GITHUB_ENV
97+
echo -e "Set version environment variables:\nENV_BUILD_VERSION_MAJOR=${BASH_REMATCH[1]}\nENV_BUILD_VERSION_MINOR=${BASH_REMATCH[2]}\n"
98+
elif [[ "$VERSION" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
99+
# vX.Y.Z format
100+
echo "ENV_BUILD_VERSION_MAJOR=${BASH_REMATCH[1]}" >> $GITHUB_ENV
101+
echo "ENV_BUILD_VERSION_MINOR=${BASH_REMATCH[2]}" >> $GITHUB_ENV
102+
echo "ENV_BUILD_VERSION_PATCH=${BASH_REMATCH[3]}" >> $GITHUB_ENV
103+
echo -e "Set version environment variables:\nENV_BUILD_VERSION_MAJOR=${BASH_REMATCH[1]}\nENV_BUILD_VERSION_MINOR=${BASH_REMATCH[2]}\nENV_BUILD_VERSION_PATCH=${BASH_REMATCH[3]}\n"
104+
else
105+
# dev.X format
106+
echo "ENV_BUILD_VERSION_MAJOR=dev" >> $GITHUB_ENV
107+
echo "ENV_BUILD_VERSION_MINOR=${BUILD_COMMIT_COUNT}" >> $GITHUB_ENV
108+
echo -e "$VERSION does not match vX.Y or vX.Y.Z, set version environment variables:\nENV_BUILD_VERSION_MAJOR=dev\nENV_BUILD_VERSION_MINOR=${BUILD_COMMIT_COUNT}\n"
109+
fi
110+
111+
# STEP: Build
112+
- name: Build project on Windows
113+
if: runner.os == 'Windows'
114+
shell: msys2 {0}
115+
run: |
116+
export PATH="$PATH:/c/Program Files/Pandoc:/c/Program Files (x86)/Inno Setup 6/"
117+
make clean all
118+
119+
- name: Build project on Linux
120+
if: runner.os == 'Linux'
121+
shell: bash
122+
run: |
123+
make clean all
124+
125+
# STEP: Create GitHub release
126+
- name: Create GitHub Release
127+
uses: softprops/action-gh-release@v1
128+
with:
129+
# Tag name: use existing tag (v0.1.0) or created build number tag (dev.123)
130+
tag_name: ${{ steps.version.outputs.version }}
131+
132+
# Release title
133+
name: ${{ steps.version.outputs.version }}
134+
135+
# Release description
136+
body: |
137+
${{ steps.version.outputs.is_tagged == 'true' && 'Production release' || 'Development build' }} for version ${{ steps.version.outputs.version }}
138+
139+
Commit: ${{ github.sha }}
140+
141+
# Upload relevant build artifacts
142+
files: |
143+
build/sqlcw-*.zip
144+
build/sqlcw-*-installer.exe
145+
146+
fail_on_unmatched_files: false
147+
148+
# Build releases are marked as pre-release, tagged releases are stable
149+
prerelease: ${{ steps.version.outputs.is_tagged != 'true' }}
150+
env:
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,34 @@ BUILD_VERSION_MAJOR := $(or $(ENV_BUILD_VERSION_MAJOR),0)
2626
BUILD_VERSION_MINOR := $(or $(ENV_BUILD_VERSION_MINOR),0)
2727
BUILD_VERSION_PATCH := $(or $(ENV_BUILD_VERSION_PATCH),0)
2828

29-
# Generate version string: "X.Y.Z" if environment vars are set, otherwise "dev"
30-
BUILD_VERSION_STR := $(if $(and $(ENV_BUILD_VERSION_MAJOR),$(ENV_BUILD_VERSION_MINOR)),$(BUILD_VERSION_MAJOR).$(BUILD_VERSION_MINOR).$(BUILD_VERSION_PATCH),dev)
29+
# Generate version string based on provided environment variables
30+
# - Default fallback is "dev"
31+
# - If ENV_BUILD_VERSION_MAJOR == "dev" and ENV_BUILD_VERSION_MINOR exists → "dev.<minor>"
32+
# - Else if ENV_BUILD_VERSION_MAJOR and ENV_BUILD_VERSION_MINOR exist → "X.Y.Z"
33+
BUILD_VERSION_STR := dev # Default fallback
34+
35+
# Special dev case: major="dev" and minor exists
36+
ifeq ($(ENV_BUILD_VERSION_MAJOR),dev)
37+
ifdef ENV_BUILD_VERSION_MINOR
38+
BUILD_VERSION_STR := $(BUILD_VERSION_MAJOR).$(BUILD_VERSION_MINOR)
39+
endif
40+
41+
# Normal semantic version case: major and minor exist
42+
else ifdef ENV_BUILD_VERSION_MAJOR
43+
ifdef ENV_BUILD_VERSION_MINOR
44+
BUILD_VERSION_STR := $(BUILD_VERSION_MAJOR).$(BUILD_VERSION_MINOR).$(BUILD_VERSION_PATCH)
45+
endif
46+
endif
47+
# End version string generation
48+
49+
# Assign numeric FILEVERSION for Windows .rc file
50+
ifeq ($(or $(filter dev,$(ENV_BUILD_VERSION_MAJOR)),$(filter dev,$(BUILD_VERSION_STR))),)
51+
# Normal build: use the real version numbers
52+
BUILD_FILEVERSION_RC := $(BUILD_VERSION_MAJOR),$(BUILD_VERSION_MINOR),$(BUILD_VERSION_PATCH),0
53+
else
54+
# Development build: use all 0s
55+
BUILD_FILEVERSION_RC := 0,0,0,0
56+
endif
3157

3258
# Alternative: Pass build info as preprocessor definitions instead of build_info.h
3359
# Uncomment these lines and remove $(BUILD_INFO_FILE) from compilation prerequisites
@@ -36,16 +62,18 @@ BUILD_VERSION_STR := $(if $(and $(ENV_BUILD_VERSION_MAJOR),$(ENV_BUILD_VERSION_M
3662

3763
# Platform-specific configuration
3864
ifdef MSYSTEM
39-
# Building on Windows (MSYS2/MinGW)
40-
PLATFORM := win64
41-
TARGET := $(BUILD_DIR)/sqlcw.exe
42-
# Boost libraries on Windows use -mt suffix (multi-threaded)
43-
LIBS := $(addsuffix -mt, $(addprefix -l,$(BOOST_LIBS)))
65+
# Building on Windows (MSYS2/MinGW)
66+
PLATFORM := win64
67+
TARGET := $(BUILD_DIR)/sqlcw.exe
68+
# Boost libraries on Windows use -mt suffix (multi-threaded)
69+
LIBS := $(addsuffix -mt, $(addprefix -l,$(BOOST_LIBS)))
70+
WINDRES_OBJECT_FILE := $(OBJ_DIR)/windres.o
4471
else
45-
# Building on Linux/Unix
46-
PLATFORM := linux_$(shell uname -m)
47-
TARGET := $(BUILD_DIR)/sqlcw
48-
LIBS := $(addprefix -l,$(BOOST_LIBS))
72+
# Building on Linux/Unix
73+
PLATFORM := linux_$(shell uname -m)
74+
TARGET := $(BUILD_DIR)/sqlcw
75+
LIBS := $(addprefix -l,$(BOOST_LIBS))
76+
WINDRES_OBJECT_FILE :=
4977
endif
5078

5179
# Phony targets (not actual files)
@@ -86,15 +114,13 @@ $(BUILD_INFO_FILE): | $(BUILD_DIR)
86114
@echo "#define BUILD_VERSION_MINOR $(BUILD_VERSION_MINOR)" >> $(BUILD_INFO_FILE)
87115
@echo "#define BUILD_VERSION_PATCH $(BUILD_VERSION_PATCH)" >> $(BUILD_INFO_FILE)
88116
@echo "#define BUILD_COMPILER \"$(BUILD_COMPILER)\"" >> $(BUILD_INFO_FILE)
117+
@echo "#define BUILD_FILEVERSION_RC $(BUILD_FILEVERSION_RC)" >> $(BUILD_INFO_FILE)
89118
@echo "#endif" >> $(BUILD_INFO_FILE)
90119

91120
# Compile Windows resource file (icon, version info, etc.)
92121
.build-windres: $(BUILD_INFO_FILE)
93122
ifdef MSYSTEM
94-
windres -I $(BUILD_DIR) -i $(SRC_DIR)/sqlcw.rc -o $(OBJ_DIR)/windres.o
95-
WINDRES_OBJECT_FILE := $(OBJ_DIR)/windres.o
96-
else
97-
WINDRES_OBJECT_FILE :=
123+
windres -I $(BUILD_DIR) -i $(SRC_DIR)/sqlcw.rc -o $(WINDRES_OBJECT_FILE)
98124
endif
99125

100126
# Package application executable and documentation for distribution

installer/sqlcw_installer.iss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
#define MyAppName "sqlcw"
22
#define MyAppURL "https://github.com/peter277/sqlcw"
33
#define MyAppExeName "sqlcw.exe"
4+
#define MyAppPublisher "peter277"
45
#define ProjectDir ExtractFileDir(ExtractFileDir(SourcePath))
56

67
#define VerMajor GetEnv("ENV_BUILD_VERSION_MAJOR")
78
#define VerMinor GetEnv("ENV_BUILD_VERSION_MINOR")
89
#define VerPatch GetEnv("ENV_BUILD_VERSION_PATCH") != "" ? GetEnv("ENV_BUILD_VERSION_PATCH") : "0"
910

10-
#if VerMajor != "" && VerMinor != ""
11+
// Determine MyAppVersion
12+
#if (VerMajor == "dev") && (VerMinor != "")
13+
// Special dev case: dev.<minor>
14+
#define MyAppVersion "dev." + VerMinor
15+
#elif (VerMajor != "") && (VerMinor != "")
16+
// Normal semantic version
1117
#define MyAppVersion VerMajor + "." + VerMinor + "." + VerPatch
1218
#else
19+
// Fallback
1320
#define MyAppVersion "dev"
1421
#endif
1522

@@ -20,7 +27,7 @@ AppId={{0D0F4C50-15D5-4CDF-A7C7-316375B5359A}
2027
AppName={#MyAppName}
2128
AppVersion={#MyAppVersion}
2229
AppVerName={#MyAppName} {#MyAppVersion}
23-
;AppPublisher={#MyAppPublisher}
30+
AppPublisher={#MyAppPublisher}
2431
AppPublisherURL={#MyAppURL}
2532
AppSupportURL={#MyAppURL}
2633
AppUpdatesURL={#MyAppURL}

src/sqlcw.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sqlcwIcon ICON "sqlcw.ico"
55
#include "build_info.h"
66

77
1 VERSIONINFO
8-
FILEVERSION BUILD_VERSION_MAJOR,BUILD_VERSION_MINOR,BUILD_VERSION_PATCH,0
8+
FILEVERSION BUILD_FILEVERSION_RC
99
//PRODUCTVERSION BUILD_VERSION_MAJOR,BUILD_VERSION_MINOR,BUILD_VERSION_PATCH,0
1010
{
1111
BLOCK "StringFileInfo" // Information dependent on a particular language and code page
@@ -16,7 +16,7 @@ FILEVERSION BUILD_VERSION_MAJOR,BUILD_VERSION_MINOR,BUILD_VERSION_PATCH,0
1616
VALUE "FileDescription", "SQL Code Wrapper command-line executable"
1717
//VALUE "FileVersion", BUILD_VERSION_STR
1818
VALUE "InternalName", "sqlcw"
19-
VALUE "LegalCopyright", "GNU General Public License v3"
19+
VALUE "LegalCopyright", "MIT License"
2020
VALUE "OriginalFilename", "sqlcw.exe"
2121
VALUE "ProductName", "SQL Code Wrapper"
2222
VALUE "ProductVersion", BUILD_VERSION_STR

0 commit comments

Comments
 (0)