diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 744e0871..95cd4ce9 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -49,39 +49,3 @@ jobs: make examples git diff --exit-code examples - tests-windows: - name: tests-windows-latest - runs-on: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: "1.22.x" - - - name: Cache Go dependencies - uses: actions/cache@v4 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Build code - shell: pwsh - run: | - .\win_setup.ps1 build - - - name: Run tests - shell: pwsh - run: | - .\win_setup.ps1 test - - - name: Check examples - shell: pwsh - run: | - .\win_setup.ps1 clean-examples - .\win_setup.ps1 examples - git diff --exit-code examples diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5b715911..a9a655f0 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -58,6 +58,16 @@ builds: - darwin goarch: - arm64 + - <<: *build-common + id: oasis-windows-amd64 + binary: oasis.exe + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 archives: - name_template: "{{replace .ProjectName \" \" \"_\" | tolower}}_{{.Version}}_{{.Os}}_{{.Arch}}" @@ -66,6 +76,10 @@ archives: - oasis-linux-amd64 - oasis-linux-arm64 - oasis-darwin-universal + - oasis-windows-amd64 + format_overrides: + - goos: windows + format: zip checksum: name_template: SHA256SUMS-{{.Version}}.txt diff --git a/Makefile b/Makefile index e35e1aa0..938ed605 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,10 @@ clean: rm -f oasis $(GO) clean -testcache +windows-build: + @$(PRINT) "$(MAGENTA)*** Building for Windows...$(OFF)\n" + GOOS=windows GOARCH=amd64 $(GO) build -v -o oasis.exe $(GOFLAGS) $(GO_EXTRA_FLAGS) + # List of targets that are not actual files. .PHONY: \ all build \ @@ -83,3 +87,4 @@ clean: $(lint-targets) lint \ $(test-targets) test \ clean + windows diff --git a/scripts/gen_example.ps1 b/scripts/gen_example.ps1 deleted file mode 100644 index 1d50018c..00000000 --- a/scripts/gen_example.ps1 +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env pwsh - -param( - [Parameter(Mandatory=$true)][string]$InFile, - [Parameter(Mandatory=$true)][string]$OutFile -) - -# Set strict mode -Set-StrictMode -Version Latest -$ErrorActionPreference = "Stop" - -# Get absolute paths -$OASIS_CMD = (Resolve-Path "./oasis.exe").Path -$IN = (Resolve-Path $InFile).Path -New-Item -ItemType File -Path $OutFile -Force | Out-Null -$OUT = (Resolve-Path $OutFile).Path -$EXAMPLE_NAME = (Split-Path (Split-Path $IN) -Leaf) -$CUSTOM_CFG_DIR = Join-Path (Split-Path $IN) "config" -$CFG_DIR = Join-Path $env:TEMP "cli_examples\$EXAMPLE_NAME" -$CFG_FLAG = "--config $(Join-Path $CFG_DIR 'cli.toml')" -$USER_CFG_DIR = Join-Path $env:LOCALAPPDATA "oasis" -$RESTORE_CFG_DIR = Join-Path $env:LOCALAPPDATA "oasis.backup" - -# Check if input filename ends with .y.in -$YES_FLAG = "" -if ($IN -match "\.y\.in$") { - $YES_FLAG = "-y -o NUL" -} - -Write-Host "Running $EXAMPLE_NAME/$(Split-Path $IN -Leaf):" - -function Initialize-Config { - # Init config in the first scenario step only - $firstFile = Get-ChildItem (Split-Path $IN) -Filter "*.in" | Select-Object -First 1 - if ($IN -ne $firstFile.FullName) { - return - } - - # Clean up existing config directory - if (Test-Path $CFG_DIR) { - Remove-Item -Recurse -Force $CFG_DIR - } - New-Item -ItemType Directory -Force -Path (Split-Path $CFG_DIR) | Out-Null - - # Check for example-specific config - if (Test-Path $CUSTOM_CFG_DIR) { - Copy-Item -Recurse $CUSTOM_CFG_DIR $CFG_DIR - return - } - - # Otherwise, generate a clean config file - if (Test-Path $USER_CFG_DIR) { - if (Test-Path $RESTORE_CFG_DIR) { - Write-Error "Cannot initialize config: restore config directory $RESTORE_CFG_DIR already exists. Please restore it into $USER_CFG_DIR or remove it" - exit 1 - } - # Backup existing config - Move-Item -Path $USER_CFG_DIR -Destination $RESTORE_CFG_DIR - } - - # Generate initial config by running network ls - & $OASIS_CMD network ls > $null - if (-not (Test-Path $USER_CFG_DIR)) { - Write-Error "Failed to generate config file at $USER_CFG_DIR" - exit 1 - } - - # Move the fresh config to example directory - Move-Item -Path $USER_CFG_DIR -Destination $CFG_DIR - - # Restore original config if it existed - if (Test-Path $RESTORE_CFG_DIR) { - Move-Item -Path $RESTORE_CFG_DIR -Destination $USER_CFG_DIR - } -} - -Initialize-Config - -# Replace "oasis" with actual path -$content = Get-Content $IN -$CMD = $content -replace '^oasis\b', $OASIS_CMD # Only replace 'oasis' at start of line -$CMD = "$CMD $CFG_FLAG $YES_FLAG" -Write-Host " $CMD" - -# Set timezone to UTC -$env:TZ = "UTC" - -# Execute command -Push-Location (Split-Path $IN) -try { - Invoke-Expression $CMD | Out-File -FilePath $OUT -Encoding utf8 -} finally { - Pop-Location -} - -# Trim transaction signing prompts if needed -if ($YES_FLAG -and (Get-Content $OUT | Select-String "Sign this transaction\?" -Quiet)) { - $content = Get-Content $OUT - $content[0..($content.Length-3)] | Set-Content $OUT -} \ No newline at end of file diff --git a/win_setup.ps1 b/win_setup.ps1 deleted file mode 100644 index eed62a52..00000000 --- a/win_setup.ps1 +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env pwsh - -# Configuration variables -$OASIS_CLI_GIT_ORIGIN_REMOTE = "origin" -$RELEASE_BRANCH = "master" -$OASIS_GO = if ($env:OASIS_GO) { $env:OASIS_GO } else { "go" } - -# Get version information -function Get-ProjectVersion { - $GIT_VERSION = git describe --tags --match "v*" --abbrev=0 2>$null | Select-Object -First 1 - if ($GIT_VERSION) { - $GIT_VERSION = $GIT_VERSION.TrimStart('v') - } - - $GIT_COMMIT_EXACT_TAG = if ((git describe --tags --match "v*" --exact-match 2>$null)) { "YES" } else { "NO" } - - if ($GIT_COMMIT_EXACT_TAG -eq "YES") { - $script:VERSION = $GIT_VERSION - } else { - $TAG_VERSION = git describe --tags --abbrev=0 - $GIT_DESCRIBE = git describe --always --match "" --dirty=+dirty - $script:VERSION = "$TAG_VERSION-git$GIT_DESCRIBE" - } - - # Set Go linker flags - $script:GOLDFLAGS_VERSION = "-X=github.com/oasisprotocol/cli/version.Software=$VERSION" - $script:GOLDFLAGS = "`"$GOLDFLAGS_VERSION`"" - if ($GOLDFLAGS) { - $script:GO_EXTRA_FLAGS = "-ldflags=$GOLDFLAGS" - } -} - -# Helper functions -function Assert-GitClean { - $status = git status --porcelain - if ($status) { - Write-Error "Error: Git workspace is dirty." - exit 1 - } -} - -function Test-GoModTidy { - & $OASIS_GO mod tidy - $status = git status --porcelain go.mod go.sum - if ($status) { - Write-Error "Error: Changes detected after running 'go mod tidy'" - git diff go.mod go.sum - exit 1 - } -} - -function Test-GitLint { - $BRANCH = "$OASIS_CLI_GIT_ORIGIN_REMOTE/$RELEASE_BRANCH" - $COMMIT_SHA = git rev-parse $BRANCH - Write-Host "*** Running gitlint for commits from $BRANCH ($($COMMIT_SHA.Substring(0,7)))..." - gitlint --commits "$BRANCH..HEAD" -} - -# Build targets -function Invoke-Build { - Write-Host "*** Building Go code..." - # Dependency: Check for Go files, go.sum, and go.mod - $goFiles = Get-ChildItem -Recurse -Filter "*.go" | Select-Object -ExpandProperty FullName - if (!(Test-Path "go.sum") -or !(Test-Path "go.mod")) { - Write-Error "Missing go.sum or go.mod" - exit 1 - } - & $OASIS_GO build -v -o oasis.exe $GO_EXTRA_FLAGS -} - -function Invoke-Examples { - Write-Host "*** Generating examples..." - $inFiles = Get-ChildItem -Recurse -Path "examples" -Filter "*.in" - foreach ($inFile in $inFiles) { - $outFile = $inFile.FullName -replace '\.in$', '.out' - Remove-Item -Force $outFile -ErrorAction SilentlyContinue - if (Test-Path "scripts/gen_example.ps1") { - & "scripts/gen_example.ps1" -InFile $inFile.FullName -OutFile $outFile - } else { - Write-Warning "scripts/gen_example.ps1 not found" - } - } -} - -function Invoke-CleanExamples { - Get-ChildItem -Recurse -Path "examples" -Filter "*.out" | Remove-Item -Force -} - -function Invoke-Format { - Write-Host "*** Running Go formatters..." - gofumpt -w . - goimports -w -local github.com/oasisprotocol/cli . -} - -function Invoke-Lint { - Write-Host "*** Running linters..." - Invoke-LintGo - Invoke-LintDocs - Invoke-LintGit - Invoke-LintGoModTidy -} - -function Invoke-LintGo { - Write-Host "*** Running Go linters..." - $env:GOPATH = $null - golangci-lint run --verbose -} - -function Invoke-LintDocs { - Write-Host "*** Running markdownlint-cli..." - npx --yes markdownlint-cli "**/*.md" -} - -function Invoke-LintGit { - Test-GitLint -} - -function Invoke-LintGoModTidy { - Write-Host "*** Checking go mod tidy..." - Assert-GitClean - Test-GoModTidy -} - -function Invoke-Test { - Write-Host "*** Running tests..." - Invoke-TestUnit -} - -function Invoke-TestUnit { - Write-Host "*** Running unit tests..." - & $OASIS_GO test -v -race ./... -} - -function Invoke-Clean { - Write-Host "*** Cleaning up..." - & $OASIS_GO clean -x - Remove-Item -Force oasis* -ErrorAction SilentlyContinue - & $OASIS_GO clean -testcache -} - -function Invoke-ReleaseBuild { - Write-Host "*** Running goreleaser..." - goreleaser release --clean -} - -# Main execution -Get-ProjectVersion - -# Handle command line arguments -$target = if ($args.Count -gt 0) { $args[0] } else { "build" } - -switch ($target) { - "build" { Invoke-Build } - "examples" { Invoke-Examples } # Fix - "clean-examples" { Invoke-CleanExamples } - "fmt" { Invoke-Format } - "lint" { Invoke-Lint } - "lint-go" { Invoke-LintGo } - "lint-docs" { Invoke-LintDocs } - "lint-git" { Invoke-LintGit } - "lint-go-mod-tidy" { Invoke-LintGoModTidy } - "test" { Invoke-Test } - "test-unit" { Invoke-TestUnit } - "clean" { Invoke-Clean } - "release-build" { Invoke-ReleaseBuild } - default { - Write-Error "Invalid target: $target" - exit 1 - } -} \ No newline at end of file