|
| 1 | +name: Build and Sign |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main", "test" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + # Build steps |
| 16 | + - name: Setup .NET |
| 17 | + uses: actions/setup-dotnet@v4 |
| 18 | + with: |
| 19 | + dotnet-version: 9.x |
| 20 | + |
| 21 | + - name: Build Package |
| 22 | + run: dotnet pack --configuration Release src/BootstrapBlazor/BootstrapBlazor.csproj |
| 23 | + |
| 24 | + # Publish the artifacts to sign and the file list, if any, as artifacts for the signing stage |
| 25 | + - name: Upload signing file list |
| 26 | + uses: actions/upload-artifact@v3 |
| 27 | + with: |
| 28 | + name: config |
| 29 | + path: config |
| 30 | + |
| 31 | + - name: Upload build artifacts |
| 32 | + uses: actions/upload-artifact@v3 |
| 33 | + with: |
| 34 | + name: BuildArtifacts |
| 35 | + path: src/BootstrapBlazor/bin/Release/**/*.nupkg |
| 36 | + |
| 37 | + sign: |
| 38 | + needs: build |
| 39 | + runs-on: windows-latest # Code signing must run on a Windows agent for Authenticode signing (dll/exe) |
| 40 | + if: ${{ github.ref == 'refs/heads/main' }} # Only run this job on pushes to the main branch |
| 41 | + permissions: |
| 42 | + id-token: write # Required for requesting the JWT |
| 43 | + |
| 44 | + steps: |
| 45 | + |
| 46 | + # Download signing configuration and artifacts |
| 47 | + - name: Download signing config |
| 48 | + uses: actions/download-artifact@v4 |
| 49 | + with: |
| 50 | + name: config |
| 51 | + path: config |
| 52 | + |
| 53 | + - name: Download build artifacts |
| 54 | + uses: actions/download-artifact@v4 |
| 55 | + with: |
| 56 | + name: BuildArtifacts |
| 57 | + path: BuildArtifacts |
| 58 | + |
| 59 | + # .NET is required on the agent for the tool to run |
| 60 | + - name: Setup .NET |
| 61 | + uses: actions/setup-dotnet@v4 |
| 62 | + with: |
| 63 | + dotnet-version: 9.x |
| 64 | + |
| 65 | + # Install the code signing tool |
| 66 | + - name: Install Sign CLI tool |
| 67 | + run: dotnet tool install --tool-path . sign |
| 68 | + |
| 69 | + # Login to Azure using a ServicePrincipal configured to authenticate agaist a GitHub Action |
| 70 | + - name: 'Az CLI login' |
| 71 | + uses: azure/login@v2 |
| 72 | + with: |
| 73 | + allow-no-subscriptions: true |
| 74 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 75 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 76 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 77 | + |
| 78 | + # Run the signing command |
| 79 | + - name: Sign artifacts |
| 80 | + shell: pwsh |
| 81 | + run: > |
| 82 | + ./sign code azure-key-vault |
| 83 | + **/*.nupkg |
| 84 | + --base-directory "${{ github.workspace }}/BuildArtifacts" |
| 85 | + --file-list "${{ github.workspace }}/config/filelist.txt" |
| 86 | + --publisher-name "Contoso" |
| 87 | + --description "One Sign CLI demo" |
| 88 | + --description-url "https://github.com/dotnet/sign" |
| 89 | + --azure-key-vault-managed-identity true |
| 90 | + --azure-key-vault-url "${{ secrets.KEY_VAULT_URL }}" |
| 91 | + --azure-key-vault-certificate "${{ secrets.KEY_VAULT_CERTIFICATE_ID }}" |
| 92 | + |
| 93 | + # Publish the signed packages |
| 94 | + - name: Upload build artifacts |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: SignedArtifacts |
| 98 | + path: BuildArtifacts |
0 commit comments