|
| 1 | +name: 'CD' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + flavor: |
| 7 | + description: 'The release flavor (either ''stack'' or ''serverless'')' |
| 8 | + type: 'string' |
| 9 | + required: true |
| 10 | + solution: |
| 11 | + description: 'The filename of the .NET solution file' |
| 12 | + type: 'string' |
| 13 | + required: true |
| 14 | + release_tag: |
| 15 | + description: 'The release tag (release version)' |
| 16 | + type: 'string' |
| 17 | + required: true |
| 18 | + release_body: |
| 19 | + description: 'The release body (release notes)' |
| 20 | + type: 'string' |
| 21 | + required: true |
| 22 | + secrets: |
| 23 | + NUGET_API_KEY: |
| 24 | + required: true |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: 'release-${{ inputs.flavor }}' |
| 28 | + cancel-in-progress: false |
| 29 | + |
| 30 | +env: |
| 31 | + # Configuration |
| 32 | + BUILD_CONFIG: 'Release' |
| 33 | + GLOBAL_JSON_FILE: 'global.json' |
| 34 | + LOCKFILE_PATTERN: '**/packages.lock.json' |
| 35 | + PACKAGE_PATH: 'nupkg' |
| 36 | + # .NET SDK related environment variables |
| 37 | + DOTNET_NOLOGO: 1 |
| 38 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 |
| 39 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 40 | + DOTNET_GENERATE_ASPNET_CERTIFICATE: 0 |
| 41 | + |
| 42 | +jobs: |
| 43 | + build: |
| 44 | + name: 'Build' |
| 45 | + runs-on: 'ubuntu-latest' |
| 46 | + steps: |
| 47 | + - name: 'Parse Version' |
| 48 | + id: 'version' |
| 49 | + uses: 'zyactions/semver@v1' |
| 50 | + with: |
| 51 | + version: ${{ inputs.release_tag }} |
| 52 | + prefixes: 'serverless-' |
| 53 | + |
| 54 | + - name: 'Checkout' |
| 55 | + uses: 'actions/checkout@v4' |
| 56 | + |
| 57 | + - name: '.NET Setup' |
| 58 | + uses: 'actions/setup-dotnet@v4' |
| 59 | + with: |
| 60 | + global-json-file: '${{ github.workspace }}/${{ env.GLOBAL_JSON_FILE }}' |
| 61 | + |
| 62 | + - name: '.NET Cache Packages' |
| 63 | + uses: 'actions/cache@v4' |
| 64 | + with: |
| 65 | + path: '~/.nuget/packages' |
| 66 | + key: '${{ runner.os }}-nuget-${{ inputs.flavor }}-${{ hashFiles(env.LOCKFILE_PATTERN) }}' |
| 67 | + restore-keys: '${{ runner.os }}-nuget-${{ inputs.flavor }}-' |
| 68 | + |
| 69 | + - name: '.NET Restore' |
| 70 | + run: >- |
| 71 | + dotnet restore "${{ github.workspace }}/${{ inputs.solution }}" |
| 72 | +
|
| 73 | + - name: '.NET Pack' |
| 74 | + env: |
| 75 | + # The complete semver version string |
| 76 | + CURRENT_VERSION: ${{ steps.version.outputs.version }} |
| 77 | + # Assembly version is sticky to MAJOR.0.0.0 to avoid binding redirects because we strong name our assemblies |
| 78 | + CURRENT_ASSEMBLY_VERSION: '${{ steps.version.outputs.major }}.0.0.0' |
| 79 | + # File version reflects actual version number without prelease and build since these are not allowed in its struct |
| 80 | + CURRENT_ASSEMBLY_FILE_VERSION: '${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }}' |
| 81 | + run: >- |
| 82 | + dotnet pack |
| 83 | + "${{ github.workspace }}/${{ inputs.solution }}" |
| 84 | + --no-restore |
| 85 | + --configuration "${{ env.BUILD_CONFIG }}" |
| 86 | + -p:ContinuousIntegrationBuild=true |
| 87 | + -p:CurrentVersion=${{ env.CURRENT_VERSION }} |
| 88 | + -p:CurrentAssemblyVersion=${{ env.CURRENT_ASSEMBLY_VERSION }} |
| 89 | + -p:CurrentAssemblyFileVersion=${{ env.CURRENT_ASSEMBLY_FILE_VERSION }} |
| 90 | + -o "${{ github.workspace }}/${{ env.PACKAGE_PATH }}" |
| 91 | +
|
| 92 | + - name: 'Upload Artifacts' |
| 93 | + uses: 'actions/upload-artifact@v4' |
| 94 | + with: |
| 95 | + name: 'packages' |
| 96 | + path: '${{ github.workspace }}/${{ env.PACKAGE_PATH }}' |
| 97 | + if-no-files-found: 'error' |
| 98 | + retention-days: 1 |
| 99 | + |
| 100 | + publish: |
| 101 | + name: Publish to ${{ matrix.feed.name }} |
| 102 | + needs: build |
| 103 | + runs-on: ubuntu-latest |
| 104 | + strategy: |
| 105 | + fail-fast: false |
| 106 | + matrix: |
| 107 | + feed: |
| 108 | + - { name: 'NuGet' , source: 'https://api.nuget.org/v3/index.json' , key: 'NUGET_API_KEY' } |
| 109 | + # - { name: 'GitHub', source: 'https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json', key: 'GITHUB_TOKEN' } |
| 110 | + steps: |
| 111 | + - name: 'Checkout' |
| 112 | + uses: 'actions/checkout@v4' |
| 113 | + |
| 114 | + - name: '.NET Setup' |
| 115 | + uses: 'actions/setup-dotnet@v4' |
| 116 | + with: |
| 117 | + global-json-file: '${{ github.workspace }}/${{ env.GLOBAL_JSON_FILE }}' |
| 118 | + |
| 119 | + - name: 'Download Artifacts' |
| 120 | + uses: actions/download-artifact@v4 |
| 121 | + with: |
| 122 | + name: 'packages' |
| 123 | + path: '${{ github.workspace }}/${{ env.PACKAGE_PATH }}' |
| 124 | + |
| 125 | + - name: '.NET NuGet Push' |
| 126 | + run: >- |
| 127 | + dotnet nuget push ${{ format('{0}/{1}/*.nupkg', github.workspace, env.PACKAGE_PATH) }} |
| 128 | + --source ${{ matrix.feed.source }} |
| 129 | + --api-key ${{ secrets[matrix.feed.key] }} |
| 130 | + --skip-duplicate |
0 commit comments