|
| 1 | +name: Azure Trusted Signing |
| 2 | +description: Signs files in a GitHub Actions artifact using Azure Trusted Signing |
| 3 | + |
| 4 | +inputs: |
| 5 | + application-description: |
| 6 | + description: "The description of the application to sign the file(s) for." |
| 7 | + required: true |
| 8 | + application-url: |
| 9 | + description: "The optional URL of the application to sign the file(s) for. Defaults to the current GitHub repository URL." |
| 10 | + required: false |
| 11 | + default: ${{ format('{0}/{1}', github.server_url, github.repository) }} |
| 12 | + artifact-to-sign: |
| 13 | + description: "The name of the GitHub Actions workflow artifact from the current workflow run to sign the contents of." |
| 14 | + required: true |
| 15 | + azure-client-id: |
| 16 | + description: "The client ID to use to authenticate with Azure." |
| 17 | + required: true |
| 18 | + azure-subscription-id: |
| 19 | + description: "The subscription ID to use to authenticate with Azure." |
| 20 | + required: true |
| 21 | + azure-tenant-id: |
| 22 | + description: "The tenant ID to use to authenticate with Azure." |
| 23 | + required: true |
| 24 | + file-filter: |
| 25 | + description: "The optional path filter of which files to sign from the artifact. Defaults to all files." |
| 26 | + required: false |
| 27 | + default: "**/*" |
| 28 | + file-list: |
| 29 | + description: "The optional path to a file containing paths of files to sign or to exclude from signing." |
| 30 | + required: false |
| 31 | + publisher-name: |
| 32 | + description: 'The optional name of the publisher of the application the signed file(s) belong to. Defaults to "Grafana Labs".' |
| 33 | + required: false |
| 34 | + default: "Grafana Labs" |
| 35 | + signed-artifact-name: |
| 36 | + description: "The name of the GitHub Actions workflow artifact to upload the signed files to." |
| 37 | + required: true |
| 38 | + trusted-signing-account: |
| 39 | + description: "The optional name of the Azure Trusted Signing account to use." |
| 40 | + required: false |
| 41 | + default: "grafana-premium-eastus" |
| 42 | + trusted-signing-endpoint: |
| 43 | + description: "The optional endpoint URL of the Azure Trusted Signing service to use." |
| 44 | + required: false |
| 45 | + default: "https://eus.codesigning.azure.net/" |
| 46 | + trusted-signing-profile: |
| 47 | + description: "The optional name of the Azure Trusted Signing profile to use." |
| 48 | + required: false |
| 49 | + default: "grafana-production" |
| 50 | +outputs: |
| 51 | + artifact-name: |
| 52 | + description: "The name of the GitHub Actions workflow artifact containing the signed file(s)." |
| 53 | + value: ${{ inputs.signed-artifact-name }} |
| 54 | + |
| 55 | +runs: |
| 56 | + using: composite |
| 57 | + steps: |
| 58 | + - name: Verify runner operating system |
| 59 | + shell: pwsh |
| 60 | + run: | |
| 61 | + if (${env:RUNNER_OS} -ne "Windows") { |
| 62 | + Write-Output "::error::This action can only be used on Windows runners." |
| 63 | + exit 1 |
| 64 | + } |
| 65 | +
|
| 66 | + - name: Get staging path |
| 67 | + id: get-staging-path |
| 68 | + shell: pwsh |
| 69 | + run: | |
| 70 | + $stagingPath = Join-Path -Path ${env:RUNNER_TEMP} -ChildPath (New-Guid).ToString() |
| 71 | + "staging-path=$stagingPath" >> ${env:GITHUB_OUTPUT} |
| 72 | +
|
| 73 | + - name: Download artifact |
| 74 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 75 | + with: |
| 76 | + name: ${{ inputs.artifact-to-sign }} |
| 77 | + path: ${{ steps.get-staging-path.outputs.staging-path }} |
| 78 | + |
| 79 | + - name: Setup .NET SDK |
| 80 | + uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1 |
| 81 | + with: |
| 82 | + # renovate: datasource=dotnet-version depName=dotnet-sdk |
| 83 | + dotnet-version: "8.0.413" |
| 84 | + |
| 85 | + - name: Install Sign CLI tool |
| 86 | + id: install-sign-tool |
| 87 | + shell: pwsh |
| 88 | + env: |
| 89 | + # renovate: datasource=nuget depName=sign |
| 90 | + DOTNET_SIGN_VERSION: "0.9.1-beta.25379.1" |
| 91 | + run: | |
| 92 | + $toolPath = Join-Path -Path ${env:RUNNER_TEMP} -ChildPath (New-Guid).ToString() |
| 93 | + New-Item -ItemType Directory -Path $toolPath | Out-Null |
| 94 | +
|
| 95 | + dotnet tool install --tool-path $toolPath sign --version ${env:DOTNET_SIGN_VERSION} |
| 96 | +
|
| 97 | + if ($LASTEXITCODE -ne 0) { |
| 98 | + Write-Output "::error::Failed to install Sign CLI tool" |
| 99 | + exit 1 |
| 100 | + } |
| 101 | +
|
| 102 | + "sign-tool=$toolPath" >> ${env:GITHUB_OUTPUT} |
| 103 | +
|
| 104 | + - name: Azure log in |
| 105 | + uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0 |
| 106 | + with: |
| 107 | + client-id: ${{ inputs.azure-client-id }} |
| 108 | + subscription-id: ${{ inputs.azure-subscription-id }} |
| 109 | + tenant-id: ${{ inputs.azure-tenant-id }} |
| 110 | + |
| 111 | + - name: Sign files |
| 112 | + shell: pwsh |
| 113 | + env: |
| 114 | + APPLICATION_DESCRIPTION: ${{ inputs.application-description }} |
| 115 | + APPLICATION_URL: ${{ inputs.application-url }} |
| 116 | + BASE_DIRECTORY: ${{ steps.get-staging-path.outputs.staging-path }} |
| 117 | + FILE_FILTER: ${{ inputs.file-filter }} |
| 118 | + FILE_LIST: ${{ inputs.file-list }} |
| 119 | + PUBLISHER_NAME: ${{ inputs.publisher-name }} |
| 120 | + SIGN_CLI_PATH: ${{ steps.install-sign-tool.outputs.sign-tool }} |
| 121 | + TRUSTED_SIGNING_ACCOUNT: ${{ inputs.trusted-signing-account }} |
| 122 | + TRUSTED_SIGNING_ENDPOINT: ${{ inputs.trusted-signing-endpoint }} |
| 123 | + TRUSTED_SIGNING_PROFILE: ${{ inputs.trusted-signing-profile }} |
| 124 | + VERBOSITY: ${{ runner.debug == '1' && 'Debug' || 'Error' }} |
| 125 | + run: | |
| 126 | + $signArgs = @( |
| 127 | + ${env:FILE_FILTER}, |
| 128 | + "--base-directory", ${env:BASE_DIRECTORY}, |
| 129 | + "--application-name", ${env:APPLICATION_DESCRIPTION}, |
| 130 | + "--publisher-name", ${env:PUBLISHER_NAME}, |
| 131 | + "--description", ${env:APPLICATION_DESCRIPTION}, |
| 132 | + "--description-url", ${env:APPLICATION_URL}, |
| 133 | + "--trusted-signing-account", ${env:TRUSTED_SIGNING_ACCOUNT}, |
| 134 | + "--trusted-signing-certificate-profile", ${env:TRUSTED_SIGNING_PROFILE}, |
| 135 | + "--trusted-signing-endpoint", ${env:TRUSTED_SIGNING_ENDPOINT}, |
| 136 | + "--verbosity", ${env:VERBOSITY} |
| 137 | + ) |
| 138 | +
|
| 139 | + if (-Not [string]::IsNullOrEmpty(${env:FILE_LIST})) { |
| 140 | + $signArgs += "--file-list" |
| 141 | + $signArgs += ${env:FILE_LIST} |
| 142 | + } |
| 143 | +
|
| 144 | + $signTool = Join-Path -Path ${env:SIGN_CLI_PATH} -ChildPath "sign" |
| 145 | +
|
| 146 | + & $signTool code trusted-signing $signArgs |
| 147 | +
|
| 148 | + if ($LASTEXITCODE -ne 0) { |
| 149 | + Write-Output "::error::Failed to sign files with Azure Trusted Signing" |
| 150 | + exit 1 |
| 151 | + } |
| 152 | +
|
| 153 | + - name: Upload signed artifacts |
| 154 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 155 | + with: |
| 156 | + name: ${{ inputs.signed-artifact-name }} |
| 157 | + path: ${{ steps.get-staging-path.outputs.staging-path }} |
| 158 | + if-no-files-found: error |
0 commit comments