Commit 2adfad4f authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

ci: First run with incremental build

parent 1644cc2c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ build-and-publish:
    - git clone https://user:${ACCESS_TOKEN}@code-int.ornl.gov/sites/fact-sheets.git site
    - ls
    - ls site
    - rm -rf ./site/html
    - rm -rf ./site/html/_astro
    - mv html/ ./site/
    - cd site
    - git lfs track "*.pdf*" && mv .gitattributes html
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
  "scripts": {
    "dev": "astro dev --host --open",
    "start": "astro dev",
    "prebuild": "pwsh -Command ./scripts/Invoke-Export.ps1",
    "prebuild": "pwsh -Command ./scripts/Invoke-Export.ps1 -Changed",
    "build": "astro build",
    "preview": "astro preview",
    "astro": "astro",
+119 −88
Original line number Diff line number Diff line
#Requires -Modules Prelude
[CmdletBinding()]
Param(
    [Parameter(Position = 0)]
    [String] $Id
    [Parameter(Position = 0, ValueFromPipeline = $True)]
    [Array] $Path,
    [Switch] $Changed,
    [String] $Url = 'https://fact-sheets.ornl.gov',
    [String] $Root = "${PSScriptRoot}/../pdf-export"
)

Begin {
    function Get-Changed {
        <#
        .SYNOPSIS
        Get list of file names that were changed in a certain commit or the most recent Git commit.
        #>
        [CmdletBinding()]
        Param(
            [Parameter(Mandatory = $False, Position = 0)]
            [String] $Commit = ''
        )
        $Commit = if ($Commit.Length -gt 0) { $Commit } else { & git log -n 1 --pretty=format:"%H" }
        $Changed = & git diff-tree --no-commit-id --name-only -r $Commit 
        $Files = $Changed | Where-Object { (Split-Path -Extension $_) -eq '.json' }
        $Files
    }
    function Export-QrCode {
        <#
        .SYNOPSIS
@@ -12,7 +31,7 @@ function Export-QrCode {
        #>
        [CmdletBinding()]
        Param(
        [Parameter(Mandatory = $True, Position = 0)]
            [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)]
            [ValidateNotNullOrEmpty()]
            [String] $Data,
            [Parameter(Mandatory = $False, Position = 1)]
@@ -21,8 +40,10 @@ function Export-QrCode {
            [int] $Scale = 2,
            [String] $Color = '96,27,100,15'
        )
        Process {
            if (Test-Command zint) {
                $Output = Join-Path $Root "${Name}.png"
                "=> [INFO] Generating QR code for ${Data}" | Write-Verbose
                & zint --data $Data --barcode QRCODE --output $Output --scale $Scale --fg $Color
                if (!(Test-Path $Output)) {
                    "    ❌ {{#red ${Output}}} not found" | Write-Color
@@ -33,7 +54,7 @@ function Export-QrCode {
                exit 1
            }
        }

    }
    function Export-Pdf {
        <#
        .SYNOPSIS
@@ -41,16 +62,18 @@ function Export-Pdf {
        #>
        [CmdletBinding()]
        Param(
        [Parameter(Mandatory = $True, Position = 0)]
            [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)]
            [ValidateNotNullOrEmpty()]
        [String] $Id,
            [Array] $Path,
            [Parameter(Mandatory = $False, Position = 1)]
        [String] $Root = "${PSScriptRoot}/../pdf-export"
            [String] $Root = $PSScriptRoot
        )
        Process {
            $Id = Split-Path -LeafBase $Path
            $Output = Join-Path $Root "../public/pdf/${Id}.pdf"
            $Template = Join-Path $Root 'template.html'
            $Html = Join-Path $Root "/_${Id}.html"
    $Json = Get-Content -Path (Join-Path $Root "/../src/content/projects/${Id}.json") | ConvertFrom-Json
            $Json = Get-Content -Path $Path | ConvertFrom-Json
            $Extension = if (Test-Path (Join-Path $Root "/../src/assets/${Id}.png")) { 'png' } else { 'jpg' }
            $Data = @{
                'id' = $Json.meta.id
@@ -71,30 +94,38 @@ function Export-Pdf {
            }
            $Data | ConvertTo-Json | Write-Verbose
            New-Template -File $Template -Data $Data | Out-File -FilePath $Html -Encoding utf8
    #
    # Requires weasyprint version 62.3 or later
    #
    if (Test-Command weasyprint) {
            "{{#gray Generating PDF from}} {{#green ${Path}}}..." | Write-Color
            if (Test-Command weasyprint) { # Requires weasyprint version 62.3 or later
                & weasyprint $Html $Output --jpeg-quality 95 --dpi 300
            } else {
                & "${Root}\bin\weasyprint.exe" $Html $Output --jpeg-quality 95 --dpi 300
            }
        }

$Url = 'https://fact-sheets.ornl.gov'
$Root = "${PSScriptRoot}/../pdf-export"
if ($Id) {
    "{{#gray Generating QR for}} {{#green ${Id}}}..." | Write-Color
    Export-QrCode -Data "${Url}/${Id}" -Root $Root -Name "_qr_${Id}"
    "{{#gray Generating PDF for}} {{#green ${Id}}}..." | Write-Color
    Export-Pdf -Id $Id -Root $Root
    }
    function Invoke-Run {
        Param(
            [Parameter(Mandatory = $True, Position = 0)]
            [ValidateNotNullOrEmpty()]
            [Array] $Path
        )
        $Id = Split-Path -LeafBase $Path
        "${Url}/${Id}" | Export-QrCode -Root $Root -Name "_qr_${Id}"
        $Path | Export-Pdf -Root $Root
    }
}
Process {
    if (!$Changed) {
        if (Test-Path -PathType Leaf $Path) {
            Invoke-Run $Path
        } else {
    $ProjectsFolder = Join-Path $Root '../src/content/projects'
    Get-ChildItem -Path $ProjectsFolder | Select-Object -ExpandProperty BaseName | ForEach-Object {
        $Id = $_
        "{{#gray Generating QR for}} {{#green ${Id}}}..." | Write-Color
        Export-QrCode -Data "${Url}/${Id}" -Root $Root -Name "_qr_${Id}"
        "{{#gray Generating PDF for}} {{#green ${Id}}}..." | Write-Color
        Export-Pdf -Id $Id -Root $Root
            Get-ChildItem -Path $Path | Select-Object -ExpandProperty FullName | ForEach-Object {
                Invoke-Run $_
            }
        }
    }
}
End {
    if ($Changed) {
        Invoke-Run (Get-Changed)
    }
}
 No newline at end of file