|
1 | 1 | name: Biohazrd
|
2 | 2 | on:
|
3 | 3 | push:
|
| 4 | + # This prevents tag pushes from triggering this workflow |
| 5 | + branches: ['*'] |
4 | 6 | pull_request:
|
| 7 | + release: |
| 8 | + types: [published] |
5 | 9 | workflow_dispatch:
|
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: "Version" |
| 13 | + default: "" |
| 14 | + will_publish_packages: |
| 15 | + description: "Publish packages?" |
| 16 | + default: "false" |
6 | 17 | env:
|
7 | 18 | DOTNET_NOLOGO: true
|
8 | 19 | DOTNET_CLI_TELEMETRY_OPTOUT: true
|
9 | 20 | DOTNET_GENERATE_ASPNET_CERTIFICATE: false
|
10 | 21 | ContinuousIntegrationBuild: true
|
| 22 | + # This URL will be added to the restore sources if it isn't the official NuGet.org |
| 23 | + # (This is mainly intended to allow using the NuGet.org test servers to test CI in forks.) |
| 24 | + CiNuGetApiUrl: ${{secrets.NUGET_API_URL}} |
11 | 25 | jobs:
|
12 | 26 | build-and-test:
|
13 | 27 | strategy:
|
14 | 28 | fail-fast: false
|
15 | 29 | matrix:
|
16 |
| - os: ['windows-latest', 'ubuntu-latest'] |
| 30 | + platform: |
| 31 | + - name: Windows |
| 32 | + architecture: x64 |
| 33 | + runs-on: windows-latest |
| 34 | + - name: Linux |
| 35 | + architecture: x64 |
| 36 | + runs-on: ubuntu-latest |
17 | 37 | configuration: ['Debug', 'Release']
|
18 |
| - name: Build and Test ${{matrix.configuration}} ${{matrix.os}} |
19 |
| - runs-on: ${{matrix.os}} |
| 38 | + include: |
| 39 | + # Linux Release x64 builds create packages (if applicable) |
| 40 | + - platform: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + configuration: Release |
| 43 | + create-packages: true |
| 44 | + name: Build and Test ${{matrix.platform.name}} ${{matrix.platform.architecture}} ${{matrix.configuration}} |
| 45 | + runs-on: ${{matrix.platform.runs-on}} |
20 | 46 | steps:
|
21 | 47 | # ----------------------------------------------------------------------- Checkout
|
22 | 48 | - name: Checkout
|
23 | 49 | uses: actions/checkout@v2
|
24 | 50 | with:
|
25 | 51 | submodules: recursive
|
26 | 52 |
|
| 53 | + # ----------------------------------------------------------------------- Setup Python |
| 54 | + - name: Setup Python 3.8 |
| 55 | + uses: actions/setup-python@v2 |
| 56 | + with: |
| 57 | + python-version: '3.8' |
| 58 | + |
27 | 59 | # ----------------------------------------------------------------------- Setup .NET
|
28 | 60 | - name: Setup .NET
|
29 | 61 | uses: actions/setup-dotnet@v1
|
30 | 62 | with:
|
31 | 63 | dotnet-version: 5.0.x
|
32 | 64 |
|
| 65 | + # ----------------------------------------------------------------------- Configure versioning |
| 66 | + - name: Configure build |
| 67 | + id: configuration |
| 68 | + run: python .github/workflows/configure-build.py |
| 69 | + env: |
| 70 | + github_event_name: ${{github.event_name}} |
| 71 | + github_ref: ${{github.ref}} |
| 72 | + github_run_number: ${{github.run_number}} |
| 73 | + release_version: ${{github.event.release.tag_name}} |
| 74 | + workflow_dispatch_version: ${{github.event.inputs.version}} |
| 75 | + workflow_dispatch_will_publish_packages: ${{github.event.inputs.will_publish_packages}} |
| 76 | + |
33 | 77 | # ----------------------------------------------------------------------- Build
|
34 | 78 | - name: Restore
|
35 | 79 | run: dotnet restore
|
36 | 80 |
|
37 | 81 | - name: Build
|
38 | 82 | run: dotnet build --no-restore --configuration ${{matrix.configuration}}
|
| 83 | + |
| 84 | + - name: Pack |
| 85 | + id: pack |
| 86 | + if: matrix.create-packages |
| 87 | + run: dotnet pack --no-build --configuration ${{matrix.configuration}} |
39 | 88 |
|
40 | 89 | # ----------------------------------------------------------------------- Test
|
41 | 90 | - name: Test
|
42 | 91 | run: dotnet test --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal
|
| 92 | + |
| 93 | + # ----------------------------------------------------------------------- Collect Artifacts |
| 94 | + - name: Collect NuGet Packages |
| 95 | + uses: actions/upload-artifact@v2 |
| 96 | + # We always want to collect packages when they were produced |
| 97 | + if: steps.pack.outcome == 'success' && always() |
| 98 | + with: |
| 99 | + name: Packages |
| 100 | + if-no-files-found: error |
| 101 | + path: packages/** |
| 102 | + |
| 103 | + publish-packages-github: |
| 104 | + name: Publish to GitHub |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: build-and-test |
| 107 | + # Pushes always publish CI packages (configure-build.py will add the branch name to the version string for branches besides main) |
| 108 | + # Published releases always publish packages |
| 109 | + # A manual workflow only publishes packages if explicitly enabled |
| 110 | + if: github.event_name == 'push' || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true') |
| 111 | + steps: |
| 112 | + # ----------------------------------------------------------------------- Setup .NET |
| 113 | + - name: Setup .NET |
| 114 | + uses: actions/setup-dotnet@v1 |
| 115 | + with: |
| 116 | + dotnet-version: 5.0.x |
| 117 | + |
| 118 | + # ----------------------------------------------------------------------- Download built packages |
| 119 | + - name: Download built packages |
| 120 | + uses: actions/download-artifact@v2 |
| 121 | + with: |
| 122 | + name: Packages |
| 123 | + |
| 124 | + # ----------------------------------------------------------------------- Upload release assets |
| 125 | + - name: Upload release assets |
| 126 | + if: github.event_name == 'release' |
| 127 | + uses: actions/github-script@v4 |
| 128 | + with: |
| 129 | + user-agent: actions/github-script for ${{github.repository}} |
| 130 | + script: | |
| 131 | + const fs = require('fs').promises; |
| 132 | + const path = require('path'); |
| 133 | + const upload_url = context.payload.release.upload_url; |
| 134 | +
|
| 135 | + if (!upload_url) { |
| 136 | + throw "Missing release asset upload URL!"; |
| 137 | + } |
| 138 | +
|
| 139 | + for (let filePath of await fs.readdir('.')) { |
| 140 | + const fileExtension = path.extname(filePath); |
| 141 | + if (fileExtension != '.nupkg' && fileExtension != '.snupkg') { |
| 142 | + continue; |
| 143 | + } |
| 144 | +
|
| 145 | + console.log(`Uploading '${filePath}'`); |
| 146 | + const contentLength = (await fs.stat(filePath)).size; |
| 147 | + const fileContents = await fs.readFile(filePath); |
| 148 | + await github.repos.uploadReleaseAsset({ |
| 149 | + url: upload_url, |
| 150 | + headers: { |
| 151 | + 'content-type': 'application/octet-stream', |
| 152 | + 'content-length': contentLength |
| 153 | + }, |
| 154 | + name: path.basename(filePath), |
| 155 | + data: fileContents |
| 156 | + }); |
| 157 | + } |
| 158 | +
|
| 159 | + # ----------------------------------------------------------------------- Push to GitHub Packages |
| 160 | + - name: Push to GitHub Packages |
| 161 | + run: dotnet nuget push "*.nupkg" --skip-duplicate --no-symbols true --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/${{github.repository_owner}} |
| 162 | + env: |
| 163 | + # This is a workaround for https://github.com/NuGet/Home/issues/9775 |
| 164 | + DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0 |
| 165 | + |
| 166 | + publish-packages-nuget-org: |
| 167 | + name: Publish to NuGet.org |
| 168 | + runs-on: ubuntu-latest |
| 169 | + needs: build-and-test |
| 170 | + environment: NuGet.org |
| 171 | + # Release builds always publish packages to NuGet.org |
| 172 | + # Workflow dispatch builds will only publish packages if enabled and an explicit version number is given |
| 173 | + # Make sure this logic matches configure-build.py to ensure we don't accidentally depend on sibling CI pre-release packages |
| 174 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true' && github.event.inputs.version != '') |
| 175 | + steps: |
| 176 | + # ----------------------------------------------------------------------- Setup .NET |
| 177 | + - name: Setup .NET |
| 178 | + uses: actions/setup-dotnet@v1 |
| 179 | + with: |
| 180 | + dotnet-version: 5.0.x |
| 181 | + |
| 182 | + # ----------------------------------------------------------------------- Download built packages |
| 183 | + - name: Download built packages |
| 184 | + uses: actions/download-artifact@v2 |
| 185 | + with: |
| 186 | + name: Packages |
| 187 | + |
| 188 | + # ----------------------------------------------------------------------- Push to NuGet.org |
| 189 | + - name: Push to NuGet.org |
| 190 | + run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{secrets.NUGET_API_URL}} |
| 191 | + env: |
| 192 | + # This is a workaround for https://github.com/NuGet/Home/issues/9775 |
| 193 | + DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0 |
43 | 194 |
|
44 | 195 | send-ci-failure-notification:
|
45 | 196 | name: Send CI Failure Notification
|
46 |
| - needs: build-and-test |
| 197 | + needs: [build-and-test, publish-packages-github, publish-packages-nuget-org] |
47 | 198 | if: failure() && github.event_name != 'pull_request'
|
48 | 199 | continue-on-error: true
|
49 | 200 | runs-on: ubuntu-latest
|
|
0 commit comments