-
Notifications
You must be signed in to change notification settings - Fork 5
153 lines (135 loc) · 5.33 KB
/
main-build.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
148
149
150
151
152
153
name: Main Build
on:
workflow_dispatch:
inputs:
single-runner:
description: specify if it has to run on a single runner only (ubuntu-latest)
required: true
default: 'true'
run-test:
description: specify if test has to be run
required: true
default: 'true'
create-packages:
description: specify if packages have to be built
required: true
default: 'true'
publish-prerelease:
description: specify if nuget packages has to be published on github feed
required: true
default: 'true'
pull_request:
paths-ignore:
- 'docs/*' # Don't run workflow when files are only in the /Documentation directory
- '.github/workflows/*' # Don't run workflow when only workflow files updated
- 'mkdocs.yml'
push:
branches:
- master
paths-ignore:
- 'docs/*' # Don't run workflow when files are only in the /Documentation directory
- '.github/workflows/*' # Don't run workflow when only workflow files updated
- 'mkdocs.yml'
env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# GitHub Packages Feed settings
GITHUB_FEED: https://nuget.pkg.github.com/MithrilMan/
GITHUB_USER: MithrilMan
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Official NuGet Feed settings
NUGET_FEED: https://api.nuget.org/v3/index.json
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
jobs:
set_variables:
runs-on: 'ubuntu-latest'
env:
DEFAULT_DO_TEST: 'true'
DEFAULT_DO_PACK: 'true'
outputs:
DO_TEST: ${{ steps.DO_TEST.outputs.value }}
DO_PACK: ${{ steps.DO_PACK.outputs.value }}
RUNNERS: ${{ steps.RUNNERS.outputs.matrix }}
steps:
- name: Set DO_TEST
uses: haya14busa/action-cond@v1
id: DO_TEST
with:
cond: ${{ github.event_name == 'workflow_dispatch' }}
if_true: ${{ github.event.inputs.run-test }}
if_false: ${{ env.DEFAULT_DO_TEST }}
- name: Set DO_PACK
uses: haya14busa/action-cond@v1
id: DO_PACK
with:
cond: ${{ github.event_name == 'workflow_dispatch' }}
if_true: ${{ github.event.inputs.create-packages }}
if_false: ${{ env.DEFAULT_DO_PACK }}
- name: Set Runners OS Matrix
id: RUNNERS
run: |
if [ "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.single-runner == 'true' }}" = "true" ]
then
echo "matrix={\"os\":[\"ubuntu-latest\"]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"os\":[\"ubuntu-latest\",\"windows-latest\",\"macos-latest\"]}" >> $GITHUB_OUTPUT
fi
- name: Dump Variables # for debug purpose
run: |
echo "DO_TEST = ${{ steps.DO_TEST.outputs.value }}"
echo "DO_PACK = ${{ steps.DO_PACK.outputs.value }}"
echo "RUNNERS = ${{ steps.RUNNERS.outputs.matrix }}"
build:
needs: set_variables
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJSON(needs.set_variables.outputs.RUNNERS)}}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: dotnet Restore
run: dotnet restore -s "https://api.nuget.org/v3/index.json" -s "https://f.feedz.io/davidfowl/bedrockframework/nuget/index.json"
- name: Build with dotnet
run: dotnet build --configuration Release --no-restore /p:CI=true
- name: Perform Tests
if: needs.set_variables.outputs.DO_TEST == 'true'
run: dotnet test -c Release --no-build --logger GitHubActions /p:CI=true
- name: .NET Lib Pack
if: matrix.os == 'ubuntu-latest' && needs.set_variables.outputs.DO_PACK == 'true'
run: dotnet pack --no-build -c Release /p:PackageOutputPath=${{ github.workspace }}\.nupkgs /p:CI=true
- name: Upload Artifacts
if: matrix.os == 'ubuntu-latest' && needs.set_variables.outputs.DO_PACK == 'true'
uses: actions/upload-artifact@v4
with:
name: mithril-shards-nuget-package
path: ${{ github.workspace }}/.nupkgs
if-no-files-found: error
prerelease:
needs: build
if: needs.set_variables.outputs.DO_PACK && (github.ref == 'refs/heads/master' || github.event.inputs.publish-prerelease)
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: mithril-shards-nuget-package
- name: Push to GitHub Feed
# The github token is automatically being pulled from the workflow
run: dotnet nuget push './mithril-shards-nuget-package/*.nupkg' --source $GITHUB_FEED --skip-duplicate --api-key $GITHUB_TOKEN
#run: dotnet nuget push ./mithril-shards-nuget-package/*.nupkg --no-symbols --skip-duplicate --source "github"
#dotnet nuget push "bin/Release/OctocatApp.1.0.0.nupkg" --api-key YOUR_GITHUB_PAT --source "github"
#run: |
# for f in ./mithril-shards-nuget-package/*.nupkg
# do
# curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
# done
# - name: Push to NuGet Feed
# run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY