|
| 1 | +name: "Signing file" |
| 2 | +description: "Install and configure the environment to then do the signing of files." |
| 3 | +inputs: |
| 4 | + paths: |
| 5 | + description: "Paths to sign" |
| 6 | + required: true |
| 7 | + signtools-extra-args: |
| 8 | + description: "Additionnal arguments to pass to signtool" |
| 9 | +outputs: |
| 10 | + cert_path: |
| 11 | + description: "certificate path" |
| 12 | + value: ${{ steps.setup-cert.outputs.SM_CLIENT_CERT_FILE }} |
| 13 | + |
| 14 | +runs: |
| 15 | + using: "composite" |
| 16 | + steps: |
| 17 | + - name: Setup for SMCTL authentication |
| 18 | + id: setup-cert |
| 19 | + shell: pwsh |
| 20 | + run: | |
| 21 | + Write-Output "::group::Check for required environment variable" |
| 22 | + if (-not $env:SM_CLIENT_CERT_FILE_B64) { |
| 23 | + Write-Output "::error title=Environment Variable Error::SM_CLIENT_CERT_FILE_B64 is not set" |
| 24 | + exit 1 |
| 25 | + } else { |
| 26 | + Write-Output "SM_CLIENT_CERT_FILE_B64 is set correctly" |
| 27 | + } |
| 28 | + Write-Output "::endgroup::" |
| 29 | + Write-Output "::group::Retrieve client certificate for auth" |
| 30 | + if (!(Test-Path ".\.build\certificates\codesign.pfx")) { |
| 31 | + # Get certificates |
| 32 | + New-Item -ItemType Directory -Force -Path .\.build\certificates |
| 33 | + Set-Content -Path ".\.build\certificates\codesign.txt" -Value $env:SM_CLIENT_CERT_FILE_B64 |
| 34 | + & certutil -decode ".\.build\certificates\codesign.txt" ".\.build\certificates\codesign.pfx" |
| 35 | + } else { |
| 36 | + Write-Output "Certificate already exists" |
| 37 | + } |
| 38 | + # Configure environment for next step |
| 39 | + "SM_CLIENT_CERT_FILE=.\.build\certificates\codesign.pfx" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 40 | + Write-Output "::endgroup::" |
| 41 | +
|
| 42 | + - name: Install SMCTL |
| 43 | + shell: pwsh |
| 44 | + run: | |
| 45 | + Write-Output "::group::Install smctl if needed" |
| 46 | + if (!(Get-Command smctl -ErrorAction SilentlyContinue)) { |
| 47 | + curl -o smtools-windows-x64.msi "https://rstudio-buildtools.s3.amazonaws.com/posit-dev/smtools-windows-x64.msi" |
| 48 | + msiexec /i smtools-windows-x64.msi /quiet /qn /log smtools-windows-x64.log |
| 49 | + "C:/Program Files/DigiCert/DigiCert One Signing Manager Tools" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 50 | + Write-Output "SMCTL installed and added on PATH" |
| 51 | + } else { |
| 52 | + Write-Output "SMCTL already installed and on PATH" |
| 53 | + } |
| 54 | + Write-Output "::endgroup::" |
| 55 | + Write-Output "::group::Add signtools in PATH" |
| 56 | + if (!(Get-Command signtool -ErrorAction SilentlyContinue)) { |
| 57 | + "C:/Program Files (x86)/Windows Kits/10/App Certification Kit" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 58 | + Write-Output "signtool added on PATH" |
| 59 | + } else { |
| 60 | + Write-Output "signtool already installed and on PATH" |
| 61 | + } |
| 62 | + Write-Output "::endgroup::" |
| 63 | +
|
| 64 | + - name: Sign files with signtool |
| 65 | + shell: pwsh |
| 66 | + env: |
| 67 | + SM_CLIENT_CERT_FILE: ${{ steps.setup-cert.outputs.SM_CLIENT_CERT_FILE }} |
| 68 | + run: | |
| 69 | + Write-Output "::group::Check for required environment variables" |
| 70 | + $requiredEnvVars = @('SM_HOST', 'SM_API_KEY', 'SM_CLIENT_CERT_FILE', 'SM_CLIENT_CERT_PASSWORD', 'CERT_FINGERPRINT') |
| 71 | + foreach ($envVar in $requiredEnvVars) { |
| 72 | + if (-not $(Get-Item -Path "Env:$envVar" -ErrorAction SilentlyContinue)) { |
| 73 | + Write-Output "::error title=Missing environment variable::Environment variable $envVar is not set." |
| 74 | + exit 1 |
| 75 | + } |
| 76 | + Write-Output "All env var correctly set." |
| 77 | + } |
| 78 | + Write-Output "::endgroup::" |
| 79 | + Write-Output "::group::Sync certificates" |
| 80 | + smctl windows certsync |
| 81 | + Write-Output "::endgroup::" |
| 82 | + # Sign each file that will be bundled in the installer |
| 83 | + $paths = "${{ inputs.paths }}" -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" } |
| 84 | + foreach ($path in $paths) { |
| 85 | + Write-Output "::group::Signing ${path}" |
| 86 | + signtool.exe sign /sha1 $env:CERT_FINGERPRINT /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 ${{ inputs.signtools-extra-args }} $path |
| 87 | + if ($LASTEXITCODE -ne 0) { |
| 88 | + Write-Output "::error title=Signing error::Error while signing ${path}" |
| 89 | + exit 1 |
| 90 | + } |
| 91 | + signtool.exe verify /v /pa $path |
| 92 | + if ($LASTEXITCODE -ne 0) { |
| 93 | + Write-Output "::error title=Verify signature error::Error while verifying ${path}" |
| 94 | + exit 1 |
| 95 | + } |
| 96 | + Write-Output "::endgroup::" |
| 97 | + } |
0 commit comments