-
Notifications
You must be signed in to change notification settings - Fork 5
184 lines (172 loc) · 5.72 KB
/
publish.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: publish
on:
push:
paths:
- "Directory.Build.props"
- "Dockerfile*"
- "src/**"
- ".github/workflows/publish.yml"
branches:
- main
pull_request:
paths:
- "Directory.Build.props"
- "Dockerfile*"
- "src/**"
- ".github/workflows/publish.yml"
workflow_dispatch:
inputs:
release_tag:
required: true
description: "Tag for the new release"
prerelease:
description: "If true, the release will be set as a prerelease and not impact the latest tag"
type: boolean
required: true
default: false
jobs:
create_release:
if: github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || github.event.inputs.prerelease == 'true')
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create.outputs.release_id }}
steps:
- name: Create release
id: create
env:
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
PRERELEASE: ${{ github.event.inputs.prerelease }}
GH_TOKEN: ${{ github.token }}
shell: pwsh
run: |
if ( -Not ( $env:RELEASE_TAG -match '^v3\.[0-9]+\.[0-9]+(-preview)*' ) ){
Throw "Tag name format incorrect"
}
if ($env:PRERELEASE -eq 'true') {
$releaseUrl = gh release create "$env:RELEASE_TAG" --repo Brightspace/bmx --draft --prerelease --generate-notes --title "Release $env:RELEASE_TAG"
} else {
$releaseUrl = gh release create "$env:RELEASE_TAG" --repo Brightspace/bmx --draft --generate-notes --title "Release $env:RELEASE_TAG"
}
if ( $LASTEXITCODE -ne 0 ) { throw "Failed to create draft release" }
$releaseId = $releaseUrl -split '/' | Select-Object -Last 1
"release_id=$releaseId" >> $env:GITHUB_OUTPUT
build:
needs: create_release
if: ${{ !failure() }}
strategy:
matrix:
include:
- machine: windows-latest
platform: win
file_name: bmx.exe
- machine: macos-latest
platform: osx
file_name: bmx
runs-on: ${{ matrix.machine }}
timeout-minutes: 10
env:
PLATFORM: ${{ matrix.platform }}
steps:
- name: checkout
uses: Brightspace/third-party-actions@actions/checkout
- name: set up .NET
uses: Brightspace/third-party-actions@actions/setup-dotnet
with:
dotnet-version: 8.0.x
- name: publish
shell: pwsh
env:
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
working-directory: src/D2L.Bmx
run: |
$version = "$env:RELEASE_TAG"
if ( -not $version ){
$version = "v3.0.0"
}
$versionWithoutv = "$version".TrimStart("v")
dotnet publish `
/p:Version="$versionWithoutv" `
/p:InformationalVersion="$version" `
/p:IncludeSourceRevisionInInformationalVersion=false `
-r $env:PLATFORM-x64 `
-o build
- name: check size
shell: pwsh
working-directory: src/D2L.Bmx
run: Get-ChildItem build
- name: upload build
if: github.event_name == 'workflow_dispatch'
shell: pwsh
env:
RELEASE_ID: ${{ needs.create_release.outputs.release_id }}
PLATFORM: ${{ matrix.platform }}
FILE_NAME: ${{ matrix.file_name }}
GH_TOKEN: ${{ github.token }}
working-directory: src/D2L.Bmx/build
run: |
if ($env:PLATFORM -eq 'win') {
Compress-Archive -Path "bmx.exe" -DestinationPath "bmx-win-x64.zip"
gh release upload "$env:RELEASE_ID" "bmx-win-x64.zip"
} elseif ($env:PLATFORM -eq 'osx') {
chmod +x "bmx"
tar -czvf "bmx-osx-x64.tar.gz" "bmx"
gh release upload "$env:RELEASE_ID" "bmx-osx-x64.tar.gz"
}
build_docker:
needs: create_release
if: ${{ !failure() }}
strategy:
matrix:
include:
- file: Dockerfile.al2
platform: linux
- file: Dockerfile.alpine
platform: linux.alpine
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: checkout
uses: Brightspace/third-party-actions@actions/checkout
- name: setup docker buildx
uses: docker/setup-buildx-action@v2
- name: publish
shell: pwsh
env:
DOCKERFILE: ${{ matrix.file }}
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
run: |
$version = "$env:RELEASE_TAG"
if ( -not $version ){
$version = "v3.0.0"
}
$versionWithoutv = "$version".TrimStart("v")
docker buildx build `
-f $env:DOCKERFILE `
--build-arg version=$versionWithoutv `
--build-arg information_version=$version `
-o build .
- name: check size
run: ls -l build
- name: upload build
if: github.event_name == 'workflow_dispatch'
shell: bash
env:
RELEASE_ID: ${{ needs.create_release.outputs.release_id }}
PLATFORM: ${{ matrix.platform }}
GH_TOKEN: ${{ github.token }}
working-directory: build
run: |
chmod +x "bmx"
tar -czvf "bmx-$PLATFORM-x64.tar.gz" "bmx"
gh release upload "$RELEASE_ID" "bmx-$PLATFORM-x64.tar.gz"
publish_release:
needs: [create_release, build, build_docker]
runs-on: ubuntu-latest
timeout-minutes: 5
env:
RELEASE_ID: ${{ needs.create_release.outputs.release_id }}
GH_TOKEN: ${{ github.token }}
steps:
- name: finalize release
run: |
gh release edit "$RELEASE_ID" --draft=false --repo Brightspace/bmx