Skip to content

Commit 5bbde89

Browse files
author
Scott Arbeit
committed
Adding support for contributing using Windows.
1 parent b84ee4d commit 5bbde89

5 files changed

Lines changed: 163 additions & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ Please note that this project is released with a [Contributor Code of Conduct][c
1111
## Submitting a pull request
1212

1313
1. [Fork][fork] and clone the repository
14-
2. Configure and install the dependencies: `script/bootstrap`
15-
3. Make sure the tests pass on your machine: `make test`
14+
15+
16+
17+
2. Configure and install the dependencies
18+
- On Unix-y machines: `script/bootstrap`
19+
- On Windows: `script/bootstrap.ps1` (requires PowerShell 7+)
20+
3. Make sure the tests pass on your machine
21+
- On Unix-y machines: `make test`
22+
- On Windows machines: `make -f Makefile.win test` (because there's a different Makefile when building on Windows)
1623
4. Create a new branch: `git checkout -b my-branch-name`
1724
5. Make your change, add tests, and make sure the tests still pass
1825
6. Push to your fork and [submit a pull request][pr]

Makefile.win

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Windows-specific Makefile for git-sizer designed for PowerShell
2+
3+
PACKAGE := github.com/github/git-sizer
4+
GO111MODULES := 1
5+
6+
# Use the project's go wrapper script via the -File parameter to avoid loading your profile
7+
GOSCRIPT := $(CURDIR)/script/go.ps1
8+
# GOSCRIPTCORRECTED := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "$(GOSCRIPT) -replace '/', '\'")
9+
GO := pwsh.exe -NoProfile -ExecutionPolicy Bypass -File $(GOSCRIPT)
10+
11+
# Get the build version from git using try/catch instead of "||"
12+
BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$null } catch { Write-Output 'unknown' }")
13+
LDFLAGS := -X github.com/github/git-sizer/main.BuildVersion=$(BUILD_VERSION)
14+
GOFLAGS := -mod=readonly
15+
16+
ifdef USE_ISATTY
17+
GOFLAGS := $(GOFLAGS) --tags isatty
18+
endif
19+
20+
# Default target
21+
all: bin/git-sizer.exe
22+
23+
# Main binary target
24+
bin/git-sizer.exe:
25+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }"
26+
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o .\bin\git-sizer.exe .
27+
28+
# Test target
29+
test: bin/git-sizer.exe gotest
30+
31+
# Run go tests
32+
gotest:
33+
$(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./...
34+
35+
# Clean up builds
36+
clean:
37+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "if (Test-Path bin) { Remove-Item -Recurse -Force bin }"
38+
39+
# Help target
40+
help:
41+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan"
42+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''"
43+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Targets:' -ForegroundColor Green"
44+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' all - Build git-sizer (default)'"
45+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' test - Run tests'"
46+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' clean - Clean build artifacts'"
47+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''"
48+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Example usage:' -ForegroundColor Green"
49+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win'"
50+
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win test'"
51+

script/bootstrap.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env pwsh
2+
3+
# Exit immediately if any command fails
4+
$ErrorActionPreference = "Stop"
5+
6+
# Change directory to the parent directory of the script
7+
Set-Location -Path (Split-Path -Parent $PSCommandPath | Split-Path -Parent)
8+
9+
# Set ROOTDIR environment variable to the current directory
10+
$env:ROOTDIR = (Get-Location).Path
11+
12+
# Check if the operating system is macOS
13+
if ($IsMacOS) {
14+
brew bundle
15+
}
16+
17+
# Source the ensure-go-installed.ps1 script
18+
. ./script/ensure-go-installed.ps1

script/ensure-go-installed.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This script is meant to be sourced with ROOTDIR set.
2+
3+
if (-not $env:ROOTDIR) {
4+
Write-Error 'ensure-go-installed.ps1 invoked without ROOTDIR set!'
5+
}
6+
7+
# Function to check if Go is installed and at least version 1.21
8+
function GoOk {
9+
$goVersionOutput = & go version 2>$null
10+
if ($goVersionOutput) {
11+
$goVersion = $goVersionOutput -match 'go(\d+)\.(\d+)' | Out-Null
12+
$majorVersion = [int]$Matches[1]
13+
$minorVersion = [int]$Matches[2]
14+
return ($majorVersion -eq 1 -and $minorVersion -ge 21)
15+
}
16+
return $false
17+
}
18+
19+
# Function to set up a local Go installation if available
20+
function SetUpVendoredGo {
21+
$GO_VERSION = "go1.23.7"
22+
$VENDORED_GOROOT = Join-Path -Path $env:ROOTDIR -ChildPath "vendor/$GO_VERSION/go"
23+
if (Test-Path -Path "$VENDORED_GOROOT/bin/go") {
24+
$env:GOROOT = $VENDORED_GOROOT
25+
$env:PATH = "$env:GOROOT/bin;$env:PATH"
26+
}
27+
}
28+
29+
# Function to check if Make is installed and install it if needed
30+
function EnsureMakeInstalled {
31+
$makeInstalled = $null -ne (Get-Command "make" -ErrorAction SilentlyContinue)
32+
if (-not $makeInstalled) {
33+
#Write-Host "Installing Make using winget..."
34+
winget install --no-upgrade --nowarn -e --id GnuWin32.Make
35+
if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 0x8A150061) {
36+
Write-Error "Failed to install Make. Please install it manually. Exit code: $LASTEXITCODE"
37+
}
38+
# Refresh PATH to include the newly installed Make
39+
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
40+
}
41+
42+
# Add GnuWin32 bin directory directly to the PATH
43+
$gnuWin32Path = "C:\Program Files (x86)\GnuWin32\bin"
44+
if (Test-Path -Path $gnuWin32Path) {
45+
$env:PATH = "$gnuWin32Path;$env:PATH"
46+
} else {
47+
Write-Host "Couldn't find GnuWin32 bin directory at the expected location."
48+
# Also refresh PATH from environment variables as a fallback
49+
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User")
50+
}
51+
}
52+
53+
SetUpVendoredGo
54+
55+
if (-not (GoOk)) {
56+
& ./script/install-vendored-go >$null
57+
if ($LASTEXITCODE -ne 0) {
58+
exit 1
59+
}
60+
SetUpVendoredGo
61+
}
62+
63+
# Ensure Make is installed
64+
EnsureMakeInstalled

script/go.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ensure that script errors stop execution
2+
$ErrorActionPreference = "Stop"
3+
4+
# Determine the root directory of the project.
5+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
6+
$ROOTDIR = (Resolve-Path (Join-Path $scriptDir "..")).Path
7+
8+
# Source the ensure-go-installed functionality.
9+
# (This assumes you have a corresponding PowerShell version of ensure-go-installed.
10+
# If not, you could call the bash version via bash.exe if available.)
11+
$ensureScript = Join-Path $ROOTDIR "script\ensure-go-installed.ps1"
12+
if (Test-Path $ensureScript) {
13+
. $ensureScript
14+
} else {
15+
Write-Error "Unable to locate '$ensureScript'. Please provide a PowerShell version of ensure-go-installed."
16+
}
17+
18+
# Execute the actual 'go' command with passed arguments.
19+
# This re-invokes the Go tool in PATH.
20+
$goExe = "go"
21+
& $goExe @args

0 commit comments

Comments
 (0)