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
+
1
14
jobs :
2
15
build :
3
16
runs-on : ubuntu-latest
8
21
- name : Set up DotNET Core
9
22
uses : actions/setup-dotnet@v1
10
23
with :
11
- dotnet-version : 3.1.402
24
+ dotnet-version : |-
25
+ 3.1.x
26
+ 5.0.x
27
+ 6.0.x
12
28
- name : Install GitVersion
13
- uses : gittools/actions/gitversion/setup@v0.9.14
29
+ uses : gittools/actions/gitversion/setup@v0.9.7
14
30
with :
15
31
versionSpec : 5.x
16
32
- id : determine_version
17
33
name : Determine Version
18
- uses : gittools/actions/gitversion/execute@v0.9.14
34
+ uses : gittools/actions/gitversion/execute@v0.9.7
19
35
with :
20
36
additionalArguments : /overrideconfig mode=Mainline
21
37
- name : Install Octopus Deploy CLI
25
41
- name : Install Dependencies
26
42
run : dotnet restore
27
43
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
28
60
- name : Test
29
61
run : dotnet test -l:trx
30
62
shell : bash
@@ -41,19 +73,22 @@ jobs:
41
73
- id : package
42
74
name : Package
43
75
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.
45
79
shopt -s globstar
46
80
paths=()
47
81
for i in **/publish/*.dll; do
48
82
dir=${i%/*}
49
83
echo ${dir}
50
84
paths=(${paths[@]} ${dir})
51
85
done
86
+ # Find the unique set of directories holding the dll files.
52
87
eval uniquepaths=($(printf "%s\n" "${paths[@]}" | sort -u))
53
88
for i in "${uniquepaths[@]}"; do
54
89
echo $i
55
90
done
56
- # For each publish dir, create a package
91
+ # For each publish dir, create a package.
57
92
packages=()
58
93
versions=()
59
94
for path in "${uniquepaths[@]}"; do
62
97
dir=${path}/../../../..
63
98
parentdir=$(builtin cd $dir; pwd)
64
99
projectname=${parentdir##*/}
65
- # Package the published files
100
+ # Package the published files.
66
101
octo pack \
67
102
--basePath ${path} \
68
103
--id ${projectname} \
@@ -72,27 +107,65 @@ jobs:
72
107
packages=(${packages[@]} "${projectname}.${{ steps.determine_version.outputs.semVer }}.zip")
73
108
versions=(${versions[@]} "${projectname}:${{ steps.determine_version.outputs.semVer }}")
74
109
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.
76
113
printf -v joined "%s," "${packages[@]}"
77
114
# Save the list of packages as an output variable
78
115
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[@]}"
80
118
# 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.
82
124
printf -v versionsjoinednewline "%s\n" "${versions[@]}"
83
125
versionsjoinednewline="${versionsjoinednewline//'%'/'%25'}"
84
126
versionsjoinednewline="${versionsjoinednewline//$'\n'/'%0A'}"
85
127
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}"
87
130
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
89
148
uses : OctopusDeploy/push-package-action@v2
90
- env :
149
+ with :
150
+ packages : ${{ steps.package.outputs.artifacts }}
151
+ overwrite_mode : OverwriteExisting
152
+ - env :
91
153
OCTOPUS_API_KEY : ${{ secrets.OCTOPUS_API_TOKEN }}
92
154
OCTOPUS_HOST : ${{ secrets.OCTOPUS_SERVER_URL }}
155
+ name : Generate Octopus Deploy build information
156
+ uses : OctopusDeploy/push-build-information-action@v1
93
157
with :
158
+ version : ${{ steps.determine_version.outputs.semVer }}
159
+ packages : RandomQuotes
94
160
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 }}
96
169
name : DotNET Core Build
97
170
' on ' :
98
171
workflow_dispatch : {}
0 commit comments