Skip to content

Commit 2bf55e6

Browse files
authored
Update dotnetcore.yml
1 parent fe1ce67 commit 2bf55e6

File tree

1 file changed

+86
-13
lines changed

1 file changed

+86
-13
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# The following workflow provides an opinionated template you can customize for your own needs.
2+
#
3+
# If you are not an Octopus user, the "Push to Octopus", "Generate Octopus Deploy build information",
4+
# and "Create Octopus Release" steps can be safely deleted.
5+
#
6+
# To configure Octopus, set the OCTOPUS_API_TOKEN secret to the Octopus API key, and
7+
# set the OCTOPUS_SERVER_URL secret to the Octopus URL.
8+
#
9+
# Double check the "project" and "deploy_to" properties in the "Create Octopus Release" step
10+
# match your Octopus projects and environments.
11+
#
12+
# Get a trial Octopus instance from https://octopus.com/start
13+
114
jobs:
215
build:
316
runs-on: ubuntu-latest
@@ -8,14 +21,17 @@ jobs:
821
- name: Set up DotNET Core
922
uses: actions/setup-dotnet@v1
1023
with:
11-
dotnet-version: 3.1.402
24+
dotnet-version: |-
25+
3.1.x
26+
5.0.x
27+
6.0.x
1228
- name: Install GitVersion
13-
uses: gittools/actions/gitversion/setup@v0.9.14
29+
uses: gittools/actions/gitversion/setup@v0.9.7
1430
with:
1531
versionSpec: 5.x
1632
- id: determine_version
1733
name: Determine Version
18-
uses: gittools/actions/gitversion/execute@v0.9.14
34+
uses: gittools/actions/gitversion/execute@v0.9.7
1935
with:
2036
additionalArguments: /overrideconfig mode=Mainline
2137
- name: Install Octopus Deploy CLI
@@ -25,6 +41,22 @@ jobs:
2541
- name: Install Dependencies
2642
run: dotnet restore
2743
shell: bash
44+
- name: List Dependencies
45+
run: dotnet list package > dependencies.txt
46+
shell: bash
47+
- name: Collect Dependencies
48+
uses: actions/upload-artifact@v2
49+
with:
50+
name: Dependencies
51+
path: dependencies.txt
52+
- name: List Dependency Updates
53+
run: dotnet list package --outdated > dependencyUpdates.txt
54+
shell: bash
55+
- name: Collect Dependency Updates
56+
uses: actions/upload-artifact@v2
57+
with:
58+
name: Dependencies Updates
59+
path: dependencyUpdates.txt
2860
- name: Test
2961
run: dotnet test -l:trx
3062
shell: bash
@@ -41,19 +73,22 @@ jobs:
4173
- id: package
4274
name: Package
4375
run: |
44-
# Find the publish directories
76+
# "dotnet publish" generates binary files in a specific directory called ./bin/<BUILD-CONFIGURATION>/<TFM>/publish/.
77+
# See https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli for more details.
78+
# We start by finding the publish directories, which we assume hold dll files.
4579
shopt -s globstar
4680
paths=()
4781
for i in **/publish/*.dll; do
4882
dir=${i%/*}
4983
echo ${dir}
5084
paths=(${paths[@]} ${dir})
5185
done
86+
# Find the unique set of directories holding the dll files.
5287
eval uniquepaths=($(printf "%s\n" "${paths[@]}" | sort -u))
5388
for i in "${uniquepaths[@]}"; do
5489
echo $i
5590
done
56-
# For each publish dir, create a package
91+
# For each publish dir, create a package.
5792
packages=()
5893
versions=()
5994
for path in "${uniquepaths[@]}"; do
@@ -62,7 +97,7 @@ jobs:
6297
dir=${path}/../../../..
6398
parentdir=$(builtin cd $dir; pwd)
6499
projectname=${parentdir##*/}
65-
# Package the published files
100+
# Package the published files.
66101
octo pack \
67102
--basePath ${path} \
68103
--id ${projectname} \
@@ -72,27 +107,65 @@ jobs:
72107
packages=(${packages[@]} "${projectname}.${{ steps.determine_version.outputs.semVer }}.zip")
73108
versions=(${versions[@]} "${projectname}:${{ steps.determine_version.outputs.semVer }}")
74109
done
75-
# Join the array with commas
110+
# We now need to output the list of generated packages so subsequent steps can access them.
111+
# We create multiple output variables with line and comma separated vales to support the inputs of subsequent steps.
112+
# Join the array with commas.
76113
printf -v joined "%s," "${packages[@]}"
77114
# Save the list of packages as an output variable
78115
echo "::set-output name=artifacts::${joined%,}"
79-
# Do the same again, but use new lines as the separator
116+
# Do the same again, but use new lines as the separator. These will be used when uploading packages to the GitHub release.
117+
printf -v joinednewline "%s\n" "${packages[@]}"
80118
# https://trstringer.com/github-actions-multiline-strings/
81-
# Multiline strings require some care in a workflow
119+
# Multiline strings require some care in a workflow.
120+
joinednewline="${joinednewline//'%'/'%25'}"
121+
joinednewline="${joinednewline//$'\n'/'%0A'}"
122+
joinednewline="${joinednewline//$'\r'/'%0D'}"
123+
# Now build a new line separated list of versions. These will be used when creating an Octopus release.
82124
printf -v versionsjoinednewline "%s\n" "${versions[@]}"
83125
versionsjoinednewline="${versionsjoinednewline//'%'/'%25'}"
84126
versionsjoinednewline="${versionsjoinednewline//$'\n'/'%0A'}"
85127
versionsjoinednewline="${versionsjoinednewline//$'\r'/'%0D'}"
86-
# Save the list of packages newline separated as an output variable
128+
# Save the list of packages newline separated as an output variable.
129+
echo "::set-output name=artifacts_new_line::${joinednewline%\n}"
87130
echo "::set-output name=versions_new_line::${versionsjoinednewline%\n}"
88-
- name: Push packages to Octopus Deploy 🐙
131+
- name: Tag Release
132+
uses: mathieudutour/github-tag-action@v6.0
133+
with:
134+
custom_tag: ${{ steps.determine_version.outputs.semVer }}
135+
github_token: ${{ secrets.GITHUB_TOKEN }}
136+
- name: Create Release
137+
uses: softprops/action-gh-release@v1
138+
with:
139+
files: ${{ steps.package.outputs.artifacts_new_line }}
140+
tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }}
141+
draft: 'false'
142+
prerelease: 'false'
143+
target_commitish: ${{ github.sha }}
144+
- env:
145+
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_TOKEN }}
146+
OCTOPUS_HOST: ${{ secrets.OCTOPUS_SERVER_URL }}
147+
name: Push packages to Octopus Deploy
89148
uses: OctopusDeploy/push-package-action@v2
90-
env:
149+
with:
150+
packages: ${{ steps.package.outputs.artifacts }}
151+
overwrite_mode: OverwriteExisting
152+
- env:
91153
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_TOKEN }}
92154
OCTOPUS_HOST: ${{ secrets.OCTOPUS_SERVER_URL }}
155+
name: Generate Octopus Deploy build information
156+
uses: OctopusDeploy/push-build-information-action@v1
93157
with:
158+
version: ${{ steps.determine_version.outputs.semVer }}
159+
packages: RandomQuotes
94160
overwrite_mode: OverwriteExisting
95-
packages: ${{ steps.package.outputs.artifacts }}
161+
- name: Create Octopus Release
162+
uses: OctopusDeploy/create-release-action@v1.1.1
163+
with:
164+
api_key: ${{ secrets.OCTOPUS_API_TOKEN }}
165+
project: RandomQuotes
166+
server: ${{ secrets.OCTOPUS_SERVER_URL }}
167+
deploy_to: Development
168+
packages: ${{ steps.package.outputs.versions_new_line }}
96169
name: DotNET Core Build
97170
'on':
98171
workflow_dispatch: {}

0 commit comments

Comments
 (0)