-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (123 loc) · 4.77 KB
/
dotnet.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Restore, build and publish .NET Core application.
name: ♻ dotnet
on:
workflow_call:
inputs:
runs_on:
description: The label of the runner (GitHub- or self-hosted) to run this workflow on. Defaults to `ubuntu-24.04`.
type: string
required: false
default: ubuntu-24.04
dotnet_version:
description: The version of .NET to install.
type: string
required: true
node_version:
description: A specific version of Node.js to install. Use to override pre-installed version on GitHub-hosted runners.
type: string
required: false
npm_version:
description: A specific version of npm to install. Use to override pre-installed version on GitHub-hosted runners.
type: string
required: false
project:
description: Specify the path of the project or solution file, or the path of the directory containing the project or solution file.
type: string
required: false
default: "."
runtime:
description: Which runtime to publish the application for.
type: string
required: false
default: ""
self_contained:
description: Publish the .NET runtime with your application so the runtime doesn't need to be installed on the target machine?
type: boolean
required: false
default: false
test_project:
description: Specify the path of a test project or solution file, or the path of a directory containing a test project or solution file. Pass a newline-separated string to specify multiple test projects.
type: string
required: false
default: ""
test_collect:
description: Enables data collector for the test run.
type: string
required: false
default: ""
artifact_name:
description: The name of the build artifact to upload.
type: string
required: false
default: dotnet-app
outputs:
artifact_name:
description: The name of the uploaded artifact containing the application.
value: ${{ inputs.artifact_name }}
permissions: {}
jobs:
dotnet:
name: .NET
runs-on: ${{ inputs.runs_on }}
permissions:
contents: read # Required to checkout the repository
env:
PROJECT: ${{ inputs.project }}
CONFIGURATION: Release
RUNTIME: ${{ inputs.runtime }}
SELF_CONTAINED: ${{ inputs.self_contained }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup .NET
uses: actions/setup-dotnet@87b7050bc53ea08284295505d98d2aa94301e852
with:
dotnet-version: ${{ inputs.dotnet_version }}
- name: Setup Node.js
if: inputs.node_version != ''
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
with:
node-version: ${{ inputs.node_version }}
- name: Update npm
if: inputs.npm_version != ''
env:
NPM_VERSION: ${{ inputs.npm_version }}
run: npm install -g "npm@$NPM_VERSION"
# Restore dependencies for the application and runtime.
- name: Dotnet restore
run: dotnet restore "$PROJECT" --runtime "$RUNTIME"
# Build the application for release/deployment.
- name: Dotnet build
run: dotnet build "$PROJECT" --configuration "$CONFIGURATION" --runtime "$RUNTIME" --self-contained "$SELF_CONTAINED" --no-restore
# Execute unit tests.
- name: Dotnet test
if: inputs.test_project != ''
env:
PROJECT: ${{ inputs.test_project }}
COLLECT: ${{ inputs.test_collect }}
run: |
while read -r proj; do
dotnet test "$proj" --configuration "$CONFIGURATION" --collect "$COLLECT"
done <<< "$PROJECT"
# Publish the application and its dependencies to a folder for deployment.
- name: Dotnet publish
id: publish
env:
OUTPUT: ${{ runner.temp }}/${{ inputs.artifact_name }}
run: |
dotnet publish "$PROJECT" --configuration "$CONFIGURATION" --runtime "$RUNTIME" --self-contained "$SELF_CONTAINED" --output "$OUTPUT" --no-build
echo "publish_path=$OUTPUT" >> "$GITHUB_OUTPUT"
- name: Create tarball
id: tar
working-directory: ${{ steps.publish.outputs.publish_path }}
env:
ARTIFACT_NAME: ${{ inputs.artifact_name }}
run: |
tarball="$RUNNER_TEMP/$ARTIFACT_NAME.tar"
tar -cvf "$tarball" .
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b
with:
name: ${{ inputs.artifact_name }}
path: ${{ steps.tar.outputs.tarball }}