Files
cmder/.github/workflows/build.yml
2026-04-12 03:42:33 +03:30

256 lines
7.8 KiB
YAML

#---------------------------------#
# general configuration #
#---------------------------------#
name: Build Cmder
# Controls when the action will run. Triggers the workflow on push or pull request events but only for the main branch
on:
push:
branches: [ "master" ]
tags:
- "v*"
pull_request:
branches: [ "master", "development" ]
workflow_dispatch:
#---------------------------------#
# environment configuration #
#---------------------------------#
env:
# Path to the root of the Cmder project.
CMDER_ROOT: ${{ github.workspace }}
permissions:
contents: read
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
name: Build Project
runs-on: windows-latest
permissions:
contents: write
discussions: write
steps:
- name: Check out repository code (Action from GitHub)
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Summary - Repository checkout
shell: pwsh
run: |
# Get Cmder version
. scripts/utils.ps1
$cmderVersion = Get-VersionStr
$buildTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
# Determine branch link (handle PR merge refs)
$branchName = "${{ github.ref_name }}"
$branchLink = ""
if ($branchName -match '^(\d+)/(merge|head)$') {
# This is a PR merge/head ref, link to the PR
$prNumber = $Matches[1]
$branchLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
} elseif ("${{ github.event_name }}" -eq "pull_request") {
# This is a pull request event, link to the PR
$branchLink = "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
} else {
# Regular branch, link to the branch tree
$branchLink = "https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}"
}
$summary = @"
## 📦 Build Cmder - Workflow Summary
<small>Build started: ``$buildTime``</small>
### Repository Information
| Property | Value |
| --- | --- |
| Repository | [``${{ github.repository }}``](https://github.com/${{ github.repository }}) |
| Branch | [``$branchName``]($branchLink) |
| Commit | [``${{ github.sha }}``](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |
| Actor | [@${{ github.actor }}](https://github.com/${{ github.actor }}) |
| Workflow | ``${{ github.workflow }}`` |
| Cmder Version | **$cmderVersion** |
---
### 🗃️ Vendor Packages ([sources.json](vendor/sources.json))
| Package | Version |
| --- | --- |
"@
# Read vendor sources.json and add to summary
$vendorSources = Get-Content -Raw "vendor/sources.json" | ConvertFrom-Json
if ($vendorSources.Count -eq 0) {
$summary += "`n| _No vendor packages found_ | |"
} else {
foreach ($vendor in $vendorSources) {
# Create release link based on vendor package
$versionLink = "$($vendor.version)"
if ($vendor.url) {
# Extract owner/repo/tag from the URL and create release link
# Handle both /releases/download/ and /archive/ URLs
if ($vendor.url -match 'github\.com/([^/]+)/([^/]+)/(releases/download|archive)/([^/]+)') {
$owner = $Matches[1]
$repo = $Matches[2]
$tag = $Matches[4]
$versionLink = "[$($vendor.version)](https://github.com/$owner/$repo/releases/tag/$tag)"
}
}
$summary += "`n| ``$($vendor.name)`` | $versionLink |"
}
}
$summary += "`n"
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v3
- name: Build Cmder Launcher
shell: pwsh
working-directory: scripts
run: .\build.ps1 -Compile -verbose
- name: Summary - Build completed
if: success()
shell: pwsh
run: |
$summary = @"
---
✅ Cmder built successfully.
"@
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
- name: Pack the built files
shell: pwsh
working-directory: scripts
run: .\pack.ps1 -verbose
- name: Upload artifact (cmder.zip)
uses: actions/upload-artifact@v7
with:
path: build/cmder.zip
name: cmder.zip
archive: false
if-no-files-found: error
- name: Upload artifact (cmder.7z)
uses: actions/upload-artifact@v7
with:
path: build/cmder.7z
name: cmder.7z
archive: false
- name: Upload artifact (cmder_mini.zip)
uses: actions/upload-artifact@v7
with:
path: build/cmder_mini.zip
name: cmder_mini.zip
archive: false
- name: Upload artifact (hashes.txt)
uses: actions/upload-artifact@v7
with:
path: build/hashes.txt
name: hashes.txt
archive: false
- name: Summary - Artifacts uploaded
if: success()
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
# Source utility functions
. scripts/utils.ps1
$summary = @"
### 🗃️ Artifacts
| Artifact | Size | Hash (SHA256) |
| --- | --- | --- |
"@
# Get all files from the build directory (excluding directories and hidden files)
if (Test-Path "build") {
$buildFiles = Get-ChildItem -Path "build" -File | Where-Object { -not $_.Name.StartsWith('.') } | Sort-Object Name
foreach ($file in $buildFiles) {
$artifact = $file.Name
$path = $file.FullName
$sizeFormatted = Format-FileSize -Bytes $file.Length
$hash = (Get-FileHash $path -Algorithm SHA256).Hash
# Try to get the actual artifact download URL
$downloadUrl = Get-ArtifactDownloadUrl -ArtifactName $artifact -Repository "${{ github.repository }}" -RunId "${{ github.run_id }}"
$warning = ""
if (-not $downloadUrl) {
# Fallback to workflow run page if artifact URL fetch fails
$downloadUrl = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
$warning = " ⚠️"
}
# Determine emoji based on file type
if ($artifact -match '\.txt$') {
$emoji = "📄"
} elseif ($artifact -match '\.(zip|rar|7z)$') {
$emoji = "🗄️"
} else {
$emoji = "📦"
}
$summary += "`n| $emoji [``$artifact``$warning]($downloadUrl) | $sizeFormatted | ``$hash`` |"
}
}
$summary += "`n"
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
build/cmder.zip
build/cmder.7z
build/cmder_mini.zip
build/hashes.txt
draft: true
generate_release_notes: true
if: startsWith(github.ref, 'refs/tags/')
- name: Summary - Release created
if: startsWith(github.ref, 'refs/tags/')
shell: pwsh
run: |
$summary = @"
---
### Release Information
🚀 Draft release created for tag: **``${{ github.ref_name }}``**
Release includes:
- Full version (``cmder.zip``, ``cmder.7z``)
- Mini version (``cmder_mini.zip``)
- File hashes (``hashes.txt``)
> ⚠️ Release is in **draft** mode. Please review and publish manually.
"@
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8