Skip to content

GurdipSCode/devops-build-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

devops-build-scripts - Build Tools

Build Status PowerShell .NET Python Go License PRs Welcome

A collection of build scripts and utilities for multi-language projects.

Supported Languages

Language Version Build Script Status
.NET Core 6.0, 7.0, 8.0 dotnet-build.ps1
PowerShell 5.1+ / 7.x ps-build.ps1
Python 3.9+ python-build.ps1
Go 1.21+ go-build.ps1

Quick Start

# Clone the repository
git clone https://github.com/yourorg/build-tools.git
cd build-tools

# Run a build
.\scripts\dotnet-build.ps1 -ProjectPath "C:\src\MyApp"

Installation

Prerequisites

Ensure the following are installed on your system:

Setup

# Add to PATH (optional)
$env:PATH += ";C:\path\to\build-tools\scripts"

# Or import as module
Import-Module .\BuildTools.psd1

Usage

.NET Build

# Basic build
.\dotnet-build.ps1

# Full pipeline: clean, build, test, publish
.\dotnet-build.ps1 -Clean -Test -Publish -Configuration Release

# Self-contained executable
.\dotnet-build.ps1 -Publish -Runtime win-x64 -SelfContained -SingleFile

# Target specific framework
.\dotnet-build.ps1 -Framework net8.0

Parameters:

Parameter Description Default
-ProjectPath Path to .sln or .csproj .
-Configuration Debug or Release Release
-Runtime Target RID (win-x64, linux-x64, etc.) -
-Framework Target framework -
-Clean Clean before build false
-Test Run unit tests false
-Publish Publish artifacts false
-SelfContained Include .NET runtime false
-SingleFile Single file output false

PowerShell Build

# Analyze and test module
.\ps-build.ps1 -ModulePath .\src\MyModule

# Build with Pester tests
.\ps-build.ps1 -Test -CodeCoverage

# Package as .nupkg
.\ps-build.ps1 -Package -OutputDir .\artifacts

Parameters:

Parameter Description Default
-ModulePath Path to module .
-Test Run Pester tests false
-CodeCoverage Generate coverage report false
-Analyze Run PSScriptAnalyzer false
-Package Create NuGet package false

Python Build

# Build with pip
.\python-build.ps1 -ProjectPath .\myapp

# Create virtual environment and install deps
.\python-build.ps1 -CreateVenv -Install

# Run tests with pytest
.\python-build.ps1 -Test -Coverage

# Build wheel package
.\python-build.ps1 -Package -OutputDir .\dist

Parameters:

Parameter Description Default
-ProjectPath Path to project .
-CreateVenv Create virtual environment false
-Install Install dependencies false
-Test Run pytest false
-Coverage Generate coverage report false
-Lint Run flake8/pylint false
-Package Build wheel/sdist false

Go Build

# Build binary
.\go-build.ps1 -ProjectPath .\myapp

# Build with race detection
.\go-build.ps1 -Race

# Cross-compile for Linux
.\go-build.ps1 -GOOS linux -GOARCH amd64

# Run tests with coverage
.\go-build.ps1 -Test -Coverage

Parameters:

Parameter Description Default
-ProjectPath Path to Go module .
-OutputName Binary name project name
-GOOS Target OS current
-GOARCH Target architecture current
-Race Enable race detector false
-Test Run tests false
-Coverage Generate coverage false
-Lint Run golangci-lint false

CI/CD Integration

Azure DevOps

trigger:
  - main

pool:
  vmImage: 'windows-latest'

steps:
  - checkout: self

  - task: PowerShell@2
    displayName: 'Build .NET'
    inputs:
      filePath: '$(Build.SourcesDirectory)/scripts/dotnet-build.ps1'
      arguments: '-Clean -Test -Publish -Configuration Release'

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.SourcesDirectory)/publish'
      ArtifactName: 'drop'

GitHub Actions

name: Build

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0.x'

      - name: Build
        shell: pwsh
        run: .\scripts\dotnet-build.ps1 -Clean -Test -Publish

      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-output
          path: publish/

Project Structure

build-tools/
├── scripts/
│   ├── dotnet-build.ps1    # .NET Core build script
│   ├── ps-build.ps1        # PowerShell module build
│   ├── python-build.ps1    # Python build script
│   └── go-build.ps1        # Go build script
├── templates/
│   ├── azure-pipelines.yml
│   └── github-actions.yml
├── tests/
│   └── *.Tests.ps1
├── docs/
│   └── *.md
├── BuildTools.psd1
├── BuildTools.psm1
├── LICENSE
└── README.md

Configuration

Create a build-config.json in your project root:

{
  "dotnet": {
    "configuration": "Release",
    "framework": "net8.0",
    "runtime": "win-x64",
    "selfContained": true
  },
  "python": {
    "version": "3.11",
    "venvPath": ".venv"
  },
  "go": {
    "version": "1.21",
    "ldflags": "-s -w"
  }
}

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please read CONTRIBUTING.md for details on our code of conduct and contribution guidelines.

Changelog

See CHANGELOG.md for release history.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

About

Scripts for the CI process - dotnet, Python, NPM, etc.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published