Skip to content

Commit 48cad71

Browse files
committed
Implement versioning and build enhancements with cross-platform support
1 parent 8ba48d2 commit 48cad71

File tree

7 files changed

+990
-7
lines changed

7 files changed

+990
-7
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
test:
1313
name: Test
1414
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
1517
strategy:
1618
matrix:
1719
go: [1.21.x, 1.22.x, 1.23.x, 1.24.x]
@@ -105,18 +107,37 @@ jobs:
105107

106108
- name: Build binaries
107109
run: |
108-
# Build for different platforms
109-
OS = ["darwin", "freebsd", "linux", "windows"]
110-
ARCH = ["amd64", "arm64"]
110+
# Set the build time environment variable
111+
BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
112+
113+
# Add run permissions to the build script
114+
chmod +x ./scripts/build.sh
111115
112-
for os in OS:
113-
for arch in ARCH:
114-
GOOS=$os GOARCH=$arch go build -o articulate-parser-$os-$arch main.go
116+
# Display help information for the build script
117+
./scripts/build.sh --help
118+
119+
# Build for all platforms
120+
./scripts/build.sh \
121+
--verbose \
122+
-ldflags "-s -w -X github.com/kjanat/articulate-parser/internal/version.Version=${{ github.ref_name }} -X github.com/kjanat/articulate-parser/internal/version.BuildTime=$BUILD_TIME -X github.com/kjanat/articulate-parser/internal/version.GitCommit=${{ github.sha }}"
123+
124+
- name: Upload a Build Artifact
125+
uses: actions/[email protected]
126+
with:
127+
# Artifact name
128+
name: build-artifacts # optional, default is artifact
129+
# A file, directory or wildcard pattern that describes what to upload
130+
path: build/
131+
if-no-files-found: ignore
132+
retention-days: 1
133+
compression-level: 9
134+
overwrite: true
135+
include-hidden-files: true
115136

116137
- name: Create Release
117138
uses: softprops/action-gh-release@v2
118139
with:
119-
files: articulate-parser-*
140+
files: build/*
120141
generate_release_notes: true
121142
draft: false
122143
prerelease: ${{ startsWith(github.ref, 'refs/tags/v0.') }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ go.work
3030
output/
3131
articulate-sample.json
3232
test-output.*
33+
go-os-arch-matrix.csv
34+
35+
# Build artifacts
36+
build/

internal/version/version.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Package version provides version information for the Articulate Parser.
2+
// It includes the current version, build time, and Git commit hash.
3+
package version
4+
5+
// Version information.
6+
var (
7+
// Version is the current version of the application.
8+
Version = "0.1.0"
9+
10+
// BuildTime is the time the binary was built.
11+
BuildTime = "unknown"
12+
13+
// GitCommit is the git commit hash.
14+
GitCommit = "unknown"
15+
)

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"time"
1515

1616
"github.com/unidoc/unioffice/document"
17+
18+
"github.com/kjanat/articulate-parser/internal/version"
1719
)
1820

1921
// Core data structures based on the Articulate Rise JSON format
@@ -547,8 +549,17 @@ func (p *ArticulateParser) processItemToDocx(doc *document.Document, item Item)
547549
}
548550

549551
func main() {
552+
// Handle version flag
553+
if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
554+
fmt.Printf("articulate-parser %s\n", version.Version)
555+
fmt.Printf("Build time: %s\n", version.BuildTime)
556+
fmt.Printf("Commit: %s\n", version.GitCommit)
557+
os.Exit(0)
558+
}
559+
550560
if len(os.Args) < 3 {
551561
fmt.Println("Usage: articulate-parser <input_uri_or_file> <output_format> [output_path]")
562+
fmt.Println(" articulate-parser -v|--version")
552563
fmt.Println(" input_uri_or_file: Articulate Rise URI or local JSON file path")
553564
fmt.Println(" output_format: md (Markdown) or docx (Word Document)")
554565
fmt.Println(" output_path: Optional output file path")

scripts/_build_tools_available.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
param(
2+
[switch]$AsCheckmark
3+
)
4+
5+
# Get the list from 'go tool dist list'
6+
$dists = & go tool dist list
7+
8+
# Parse into OS/ARCH pairs
9+
$parsed = $dists | ForEach-Object {
10+
$split = $_ -split '/'
11+
[PSCustomObject]@{ OS = $split[0]; ARCH = $split[1] }
12+
}
13+
14+
# Find all unique OSes and arches, sorted
15+
$oses = $parsed | Select-Object -ExpandProperty OS -Unique | Sort-Object
16+
$arches = $parsed | Select-Object -ExpandProperty ARCH -Unique | Sort-Object
17+
18+
# Group by OS, and build custom objects
19+
$results = foreach ($os in $oses) {
20+
$props = @{}
21+
$props.OS = $os
22+
foreach ($arch in $arches) {
23+
$hasArch = $parsed | Where-Object { $_.OS -eq $os -and $_.ARCH -eq $arch }
24+
if ($hasArch) {
25+
if ($AsCheckmark) {
26+
$props[$arch] = ''
27+
} else {
28+
$props[$arch] = $true
29+
}
30+
} else {
31+
$props[$arch] = $false
32+
}
33+
}
34+
[PSCustomObject]$props
35+
}
36+
37+
# Output
38+
$results | Format-Table -AutoSize

0 commit comments

Comments
 (0)