|
| 1 | +parameters: |
| 2 | + Artifact: dist |
| 3 | + pythons: [] |
| 4 | + Signed: false |
| 5 | + SigningKeyCode: '' |
| 6 | + |
| 7 | +jobs: |
| 8 | +- job: Build |
| 9 | + |
| 10 | + variables: |
| 11 | + - ${{ if eq(parameters.Signed, 'true') }}: |
| 12 | + - group: ESRPClient |
| 13 | + - name: DistDir |
| 14 | + value: $(Build.ArtifactStagingDirectory)/dist |
| 15 | + - name: TempDir |
| 16 | + value: $(Build.BinariesDirectory)/tmp |
| 17 | + - name: LayoutDir |
| 18 | + value: $(Build.BinariesDirectory)/layout |
| 19 | + |
| 20 | + steps: |
| 21 | + - checkout: dlltracer |
| 22 | + |
| 23 | + - task: UsePythonVersion@0 |
| 24 | + inputs: |
| 25 | + versionSpec: '>=3.10' |
| 26 | + architecture: 'x64' |
| 27 | + displayName: 'Use latest Python by default' |
| 28 | + |
| 29 | + # Acquire a copy of each Python version, specifically for its Include and libs directories. |
| 30 | + - ${{ each py in parameters.pythons }}: |
| 31 | + - task: UsePythonVersion@0 |
| 32 | + name: 'py${{ py.id }}' |
| 33 | + displayName: 'Download ${{ py.wheeltag }}' |
| 34 | + inputs: |
| 35 | + versionSpec: '${{ py.version }}' |
| 36 | + architecture: '${{ py.arch }}' |
| 37 | + addToPath: false |
| 38 | + |
| 39 | + - task: PipAuthenticate@1 |
| 40 | + inputs: |
| 41 | + artifactFeeds: Python |
| 42 | + displayName: 'Authenticate pip for internal feed' |
| 43 | + |
| 44 | + - powershell: | |
| 45 | + python -m pip install pymsbuild Cython |
| 46 | + displayName: 'Install dependencies' |
| 47 | +
|
| 48 | + - powershell: | |
| 49 | + Write-Output "##vso[task.setvariable variable=GITHUB_REF]$(REF)" |
| 50 | + displayName: 'Update build reference' |
| 51 | + condition: and(succeeded(), startswith(variables['REF'], 'refs/tags/')) |
| 52 | +
|
| 53 | + ############################################################################## |
| 54 | + # BUILD SDIST and EXTENSION MODULES |
| 55 | + ############################################################################## |
| 56 | + |
| 57 | + # sdist requires no signing/SBOM or special handling, so just build it |
| 58 | + - powershell: | |
| 59 | + python -m pymsbuild sdist -d $(DistDir) |
| 60 | + displayName: 'Build sdist' |
| 61 | +
|
| 62 | + # Build the extension modules for this Python version, but do not |
| 63 | + # pack the wheel yet (the '--layout' option achieves this) |
| 64 | + - ${{ each py in parameters.pythons }}: |
| 65 | + - powershell: | |
| 66 | + $env:PYTHON_INCLUDES = Join-Path $env:PREFIX "Include" |
| 67 | + $env:PYTHON_LIBS = Join-Path $env:PREFIX "libs" |
| 68 | + python -m pymsbuild wheel -d $(DistDir) --layout "$(LayoutDir)/${{ py.id }}" |
| 69 | + "" | Out-File -Encoding ascii "$(LayoutDir)/${{ py.id }}-extras.txt" |
| 70 | + displayName: 'Build ${{ py.wheeltag }}' |
| 71 | + env: |
| 72 | + PREFIX: $(py${{ py.id }}.pythonLocation) |
| 73 | + PYMSBUILD_WHEEL_TAG: ${{ py.wheeltag }} |
| 74 | +
|
| 75 | + ############################################################################## |
| 76 | + # CODE SIGN EXTENSION MODULES |
| 77 | + ############################################################################## |
| 78 | + |
| 79 | + - ${{ if eq(parameters.Signed, 'true') }}: |
| 80 | + - task: 1ES.Signing@1 |
| 81 | + displayName: 'Codesign modules' |
| 82 | + inputs: |
| 83 | + ClientID: $(ESRP.ClientID) |
| 84 | + TenantID: $(ESRP.TenantID) |
| 85 | + Directory: '$(LayoutDir)' |
| 86 | + Pattern: | |
| 87 | + **/*.pyd |
| 88 | + Operations: | |
| 89 | + [ |
| 90 | + { |
| 91 | + "KeyCode" : "${{parameters.SigningKeyCode}}", |
| 92 | + "OperationCode" : "SigntoolSign", |
| 93 | + "Parameters" : { |
| 94 | + "OpusName" : "dlltracer-python $(REF)", |
| 95 | + "OpusInfo" : "https://github.com/microsoft/dlltracer-python/", |
| 96 | + "Append" : "/as", |
| 97 | + "FileDigest" : "/fd \"SHA256\"", |
| 98 | + "PageHash" : "/NPH", |
| 99 | + "TimeStamp" : "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" |
| 100 | + }, |
| 101 | + "ToolName" : "sign", |
| 102 | + "ToolVersion" : "1.0" |
| 103 | + }, |
| 104 | + { |
| 105 | + "KeyCode" : "${{parameters.SigningKeyCode}}", |
| 106 | + "OperationCode" : "SigntoolVerify", |
| 107 | + "Parameters" : {}, |
| 108 | + "ToolName" : "sign", |
| 109 | + "ToolVersion" : "1.0" |
| 110 | + } |
| 111 | + ] |
| 112 | +
|
| 113 | + ############################################################################## |
| 114 | + # GENERATE SBOM (only when signing) |
| 115 | + ############################################################################## |
| 116 | + |
| 117 | + - ${{ if eq(parameters.Signed, 'true') }}: |
| 118 | + - ${{ each py in parameters.pythons }}: |
| 119 | + - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 |
| 120 | + displayName: 'Generate SBOM for Python ${{ py.wheeltag }}' |
| 121 | + inputs: |
| 122 | + BuildDropPath: "$(LayoutDir)/${{ py.id }}" |
| 123 | + |
| 124 | + # Move the SBOM manifest directory into the dist-info directory |
| 125 | + # and add its content to the list of files to include. |
| 126 | + - powershell: | |
| 127 | + $m = gi "*.dist-info" | select -first 1 |
| 128 | + mv _manifest $m -Force |
| 129 | + $new_files = (gci "$m\_manifest" -File -Recurse).FullName |
| 130 | + $new_files | Out-File "$(LayoutDir)\${{ py.id }}-extras.txt" -Encoding ascii |
| 131 | + workingDirectory: '$(LayoutDir)/${{ py.id }}' |
| 132 | + displayName: 'Add SBOM into ${{ py.wheeltag }} wheel' |
| 133 | +
|
| 134 | + ############################################################################## |
| 135 | + # PACK WHEELS |
| 136 | + ############################################################################## |
| 137 | + |
| 138 | + - ${{ each py in parameters.pythons }}: |
| 139 | + - powershell: > |
| 140 | + python -m pymsbuild |
| 141 | + pack |
| 142 | + --layout-dir "$(LayoutDir)/${{ py.id }}" |
| 143 | + --add "@$(LayoutDir)/${{ py.id }}-extras.txt" |
| 144 | + displayName: 'Pack ${{ py.wheeltag }} wheel' |
| 145 | +
|
| 146 | + ############################################################################## |
| 147 | + # SMOKE TESTS |
| 148 | + ############################################################################## |
| 149 | + |
| 150 | + - powershell: | |
| 151 | + python -m pip wheel (gi "$(DistDir)\*.tar.gz") -w $(TempDir) |
| 152 | + displayName: 'Test that SDist will build' |
| 153 | +
|
| 154 | + - powershell: | |
| 155 | + python -m pip install dlltracer |
| 156 | + if ($?) { python -c "import dlltracer, dlltracer._native" } |
| 157 | + displayName: 'Check that built module will import' |
| 158 | + env: |
| 159 | + PIP_NO_DEPS: 1 |
| 160 | + PIP_NO_INDEX: 1 |
| 161 | + PIP_FIND_LINKS: $(TempDir) |
| 162 | + PIP_ONLY_BINARY: ':all:' |
| 163 | +
|
| 164 | + templateContext: |
| 165 | + outputs: |
| 166 | + - output: pipelineArtifact |
| 167 | + path: $(DistDir) |
| 168 | + artifact: ${{ parameters.Artifact }} |
| 169 | + displayName: 'Publish build to ${{ parameters.Artifact }}' |
| 170 | + |
0 commit comments