-
Notifications
You must be signed in to change notification settings - Fork 1
157 lines (152 loc) · 5.21 KB
/
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
154
155
156
157
name: Build
on:
push:
branches:
- main
pull_request:
release:
types:
- published
workflow_dispatch:
env:
# Disable the .NET logo in the console output.
DOTNET_NOLOGO: true
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending .NET CLI telemetry to Microsoft.
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Set the build number in MinVer.
# MINVERBUILDMETADATA: build.${{github.run_number}}
jobs:
build:
name: Build-${{matrix.os}}
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest] # windows-latest, macOS-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: "Install .NET Core SDK"
uses: actions/setup-dotnet@v3.0.3
- name: "Dotnet Tool Restore"
run: dotnet tool restore
shell: pwsh
- name: "Dotnet Cake Build"
run: dotnet cake --target=Build
shell: pwsh
- name: "Dotnet Cake Test"
run: dotnet cake --target=Test
shell: pwsh
- name: "Dotnet Cake Publish"
run: dotnet cake --target=Publish
- name: "Dotnet Cake Pack"
run: dotnet cake --target=Pack
shell: pwsh
- name: "Publish Artifacts"
uses: actions/upload-artifact@v3
with:
name: ${{matrix.os}}
path: "./Artifacts"
docker:
name: Docker-${{matrix.os}}
env:
DOCKER_IMAGE_NAME: web-scheduler-api
DOCKER_REGISTRY: registry.digitalocean.com
DOCKER_USERNAME: ${{secrets.DOCR_USER}}
DOCKER_PASSWORD: ${{secrets.DOCR_PASSWORD}}
DOCKER_REPOSITORY_NAME: web-scheduler
environment:
name: "DOCR registry.digitalocean.com/web-scheduler"
url: https://registry.digitalocean.com/web-scheduler/web-scheduler-api
permissions:
packages: write
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: "Checkout"
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: "Install .NET Core SDK"
uses: actions/setup-dotnet@v3.0.3
- name: "Dotnet Tool Restore"
run: dotnet tool restore
shell: pwsh
- name: "Install QEMU"
id: qemu
uses: docker/setup-qemu-action@v2
- name: "Available platforms"
run: echo ${{steps.qemu.outputs.platforms}}
- name: "Install Docker BuildX"
uses: docker/setup-buildx-action@v2
- name: "Docker Login"
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
run: echo ${{env.DOCKER_PASSWORD}} | docker login ${{env.DOCKER_REGISTRY}} --username ${{env.DOCKER_USERNAME}} --password-stdin
shell: pwsh
- name: "Dotnet Cake DockerBuild"
run: dotnet cake --target=DockerBuild --tag=${{env.DOCKER_REGISTRY}}/${{env.DOCKER_REPOSITORY_NAME}}/${{env.DOCKER_IMAGE_NAME}} --push=${{ github.event_name == 'release'}}
shell: pwsh
- name: Read file contents from DOCKER_TAG
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
id: read_file
uses: andstor/file-reader-action@v1
with:
path: "./Artifacts/DOCKER_TAG"
- name: DigitalOcean App Platform deployment
if: github.event_name == 'release'
uses: digitalocean/app_action@main
with:
app_name: web-scheduler
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
images: '[
{
"name": "web-scheduler-api",
"repository": "${{env.DOCKER_REGISTRY}}/${{env.DOCKER_REPOSITORY_NAME}}/${{env.DOCKER_IMAGE_NAME}}",
"tag": "${{ steps.read_file.outputs.contents }}"
}]'
push-github-packages:
name: "Push GitHub Packages"
needs: build
environment:
name: "GitHub Packages"
url: https://github.com/web-scheduler/web-scheduler-api/packages
permissions:
packages: write
runs-on: windows-latest
steps:
- name: "Download Artifact"
uses: actions/download-artifact@v3
with:
name: "ubuntu-latest"
- name: "Dotnet NuGet Add Source"
run: dotnet nuget add source https://nuget.pkg.github.com/web-scheduler/index.json --name GitHub --username web-scheduler-api --password ${{secrets.GITHUB_TOKEN}}
shell: pwsh
- name: "Dotnet NuGet Push"
run: dotnet nuget push .\**\*.nupkg --api-key ${{ github.token }} --source GitHub --skip-duplicate
shell: pwsh
push-nuget:
name: "Push NuGet Packages"
needs: build
if: github.event_name == 'release'
environment:
name: "NuGet"
url: https://www.nuget.org
runs-on: ubuntu-latest
steps:
- name: "Download Artifact"
uses: actions/download-artifact@v3
with:
name: "ubuntu-latest"
- name: "Dotnet NuGet Push"
run: |
Get-ChildItem -Recurse .\ -Filter *.nupkg |
Where-Object { !$_.Name.Contains('preview') } |
ForEach-Object { dotnet nuget push $_ --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{secrets.NUGET_API_KEY}} }
shell: pwsh