#---------------------------------# # 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 and PR information $refName = "${{ github.ref_name }}" $headRef = "${{ github.head_ref }}" $eventName = "${{ github.event_name }}" $prNumber = $null $actualBranchName = $refName $branchLink = "" $prLink = "" # Check if this is a PR merge ref (e.g., "3061/merge") if ($refName -match '^(\d+)/(merge|head)$') { $prNumber = $Matches[1] # Use head_ref for the actual branch name if available if ($headRef) { $actualBranchName = $headRef } $branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName" $prLink = "https://github.com/${{ github.repository }}/pull/$prNumber" } elseif ($eventName -eq "pull_request") { # This is a pull request event $prNumber = "${{ github.event.pull_request.number }}" if ($headRef) { $actualBranchName = $headRef } $branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName" $prLink = "https://github.com/${{ github.repository }}/pull/$prNumber" } else { # Regular branch, link to the branch tree $branchLink = "https://github.com/${{ github.repository }}/tree/$refName" } $summary = @" ## 📦 Build Cmder - Workflow Summary Build started: ``$buildTime`` ### Repository Information | Property | Value | | --- | --- | | Repository | [``${{ github.repository }}``](https://github.com/${{ github.repository }}) | | Branch | [``$actualBranchName``]($branchLink) | $(if ($prNumber) { "| Pull Request | [#$prNumber]($prLink) |" }) | 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] $pathType = $Matches[3] $tag = $Matches[4] if ($pathType -eq 'archive') { $tag = $tag -replace '\.(?:tar\.gz|tgz|zip)$', '' } $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@v3 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