Use the new CLI #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| permissions: | |
| id-token: write | |
| checks: write | |
| contents: write | |
| packages: write | |
| name: DotNET Core Build | |
| 'on': | |
| workflow_dispatch: {} | |
| push: {} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: '0' | |
| - name: Set up DotNET Core | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: |- | |
| 8.0.x | |
| - name: Install GitVersion | |
| uses: gittools/actions/gitversion/setup@v4.1.0 | |
| with: | |
| versionSpec: '6.3.x' | |
| - id: determine_version | |
| name: Determine Version | |
| uses: gittools/actions/gitversion/execute@v4.1.0 | |
| - name: Install Dependencies | |
| run: dotnet restore | |
| shell: bash | |
| - name: List Dependencies | |
| run: dotnet list package > dependencies.txt | |
| shell: bash | |
| - name: Collect Dependencies | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Dependencies | |
| path: dependencies.txt | |
| - name: List Dependency Updates | |
| run: dotnet list package --outdated > dependencyUpdates.txt | |
| shell: bash | |
| - name: Collect Dependency Updates | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Dependencies Updates | |
| path: dependencyUpdates.txt | |
| - name: Test | |
| run: dotnet test -l:trx | |
| shell: bash | |
| - if: always() | |
| name: Report | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| name: DotNET Tests | |
| path: '**/*.trx' | |
| reporter: dotnet-trx | |
| fail-on-error: 'false' | |
| - name: Publish | |
| run: dotnet publish --configuration Release /p:AssemblyVersion=${{ steps.determine_version.outputs.assemblySemVer }} | |
| - name: Install Octopus CLI 🐙 | |
| uses: OctopusDeploy/install-octopus-cli-action@v3 | |
| with: | |
| version: 'latest' | |
| - id: package | |
| name: Package | |
| run: | | |
| # "dotnet publish" generates binary files in a specific directory called ./bin/<BUILD-CONFIGURATION>/<TFM>/publish/. | |
| # See https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli for more details. | |
| # We start by finding the publish directories, which we assume hold dll files. | |
| shopt -s globstar | |
| paths=() | |
| for i in **/publish/*.dll; do | |
| dir=${i%/*} | |
| echo ${dir} | |
| paths=(${paths[@]} ${dir}) | |
| done | |
| # Find the unique set of directories holding the dll files. | |
| eval uniquepaths=($(printf "%s\n" "${paths[@]}" | sort -u)) | |
| for i in "${uniquepaths[@]}"; do | |
| echo $i | |
| done | |
| # For each publish dir, create a package. | |
| packages=() | |
| versions=() | |
| for path in "${uniquepaths[@]}"; do | |
| # Get the directory name four deep, which is typically the project folder. | |
| # The directory name is used to name the package. | |
| dir=${path}/../../../.. | |
| parentdir=$(builtin cd $dir; pwd) | |
| projectname=${parentdir##*/} | |
| # Package the published files. | |
| octopus package zip create \ | |
| --base-path ${path} \ | |
| --id ${projectname} \ | |
| --version ${{ steps.determine_version.outputs.semVer }} \ | |
| --overwrite | |
| packages=(${packages[@]} "${projectname}.${{ steps.determine_version.outputs.semVer }}.zip") | |
| versions=(${versions[@]} "${projectname}:${{ steps.determine_version.outputs.semVer }}") | |
| done | |
| # We now need to output the list of generated packages so subsequent steps can access them. | |
| # We create multiple output variables with line and comma separated vales to support the inputs of subsequent steps. | |
| # Join the array with commas. | |
| printf -v joined "%s," "${packages[@]}" | |
| # Save the list of packages as an output variable | |
| echo "::set-output name=artifacts::${joined%,}" | |
| # Do the same again, but use new lines as the separator. These will be used when uploading packages to the GitHub release. | |
| printf -v joinednewline "%s\n" "${packages[@]}" | |
| # https://trstringer.com/github-actions-multiline-strings/ | |
| # Multiline strings require some care in a workflow. | |
| joinednewline="${joinednewline//'%'/'%25'}" | |
| joinednewline="${joinednewline//$'\n'/'%0A'}" | |
| joinednewline="${joinednewline//$'\r'/'%0D'}" | |
| # Now build a new line separated list of versions. These will be used when creating an Octopus release. | |
| printf -v versionsjoinednewline "%s\n" "${versions[@]}" | |
| versionsjoinednewline="${versionsjoinednewline//'%'/'%25'}" | |
| versionsjoinednewline="${versionsjoinednewline//$'\n'/'%0A'}" | |
| versionsjoinednewline="${versionsjoinednewline//$'\r'/'%0D'}" | |
| # Save the list of packages newline separated as an output variable. | |
| echo "::set-output name=artifacts_new_line::${joinednewline%\n}" | |
| echo "::set-output name=versions_new_line::${versionsjoinednewline%\n}" | |
| - name: Tag Release | |
| uses: mathieudutour/github-tag-action@v6.0 | |
| with: | |
| custom_tag: ${{ steps.determine_version.outputs.semVer }} | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: ${{ steps.package.outputs.artifacts_new_line }} | |
| tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }} | |
| draft: 'false' | |
| prerelease: 'false' | |
| target_commitish: ${{ github.sha }} |