forked from drogue-iot/drg
-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (187 loc) · 6.65 KB
/
build.yaml
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Formating and build
on:
push:
pull_request:
jobs:
check:
runs-on: ubuntu-latest
outputs:
do-publish: ${{steps.state.outputs.do-publish}}
release: ${{steps.state.outputs.release}}
version: ${{steps.version.outputs.version}}
prerelease: ${{steps.state.outputs.prerelease}}
steps:
- name: Evaluate state
id: state
shell: bash
run: |
test -z "${{github.head_ref}}" && echo '::set-output name=do-publish::true'
if [[ "${{ github.event.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ::set-output name=release::true
echo ::set-output name=release::true
elif [[ "${{ github.event.ref }}" =~ ^refs/tags/v.*$ ]]; then
echo ::set-output name=release::true
echo ::set-output name=prerelease::true
fi
- name: Set version
id: version
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest # main branch
[ "$VERSION" == "merge" ] && VERSION=latest # PR
echo VERSION=$VERSION
echo "::set-output name=version::$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Dump state
run: |
echo "Tag/version: ${VERSION} / ${{needs.check.outputs.version}}"
echo "Should we publish artifacts? - do-publish = ${{needs.check.outputs.do-publish}}"
echo "Release? - release = ${{needs.check.outputs.release}}"
echo "Pre-release? - prerelease = ${{needs.check.outputs.prerelease}}"
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
- run: rustup component add clippy
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
- name: Run Rustfmt
run: cargo fmt -- --check
- name: Cargo test
run: cargo test
- name: Cargo check
run: cargo check
build:
needs:
- check
strategy:
matrix:
os: [ubuntu-18.04, macos-10.15, windows-2019]
include:
- os: ubuntu-18.04
suffix: "linux-amd64"
pkg: "tar.gz"
- os: macos-10.15
suffix: "macos-amd64"
pkg: "tar.gz"
- os: windows-2019
suffix: "windows-amd64"
exe: ".exe"
pkg: "zip"
runs-on: ${{ matrix.os }}
env:
VERSION: ${{needs.check.outputs.version}}
steps:
- name: Install build tools
if: ${{ matrix.os == 'ubuntu-18.04' }}
run: |
sudo apt-get update; DEBIAN_FRONTEND="noninteractive" sudo apt-get -y install build-essential curl tzdata
sudo apt install -y libssl-dev pkg-config
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Prepare release asset
shell: bash
run: .github/scripts/package_release.sh "${{matrix.suffix}}" "${{matrix.exe}}" "${{matrix.pkg}}" "${VERSION}"
- name: Build Windows Installer
if: ${{ matrix.os == 'windows-2019' }}
shell: cmd
#
# In the following command we add '.0' to the version, as MSI expects a version in the format 'a.b.c.d'.
# We also switch the version to '0.0.0.0' if it is 'latest'
#
run: |
cd
dir target\release
nuget install WiX -version 3.11.2
set VERSION=%VERSION:latest=0.0.0%
D:\a\drg\drg\WiX.3.11.2\tools\candle -v -dVersion=%VERSION%.0 -arch x64 dist\wix\drg.wxs
D:\a\drg\drg\WiX.3.11.2\tools\light drg.wixobj -o drg-%VERSION%.0-${{matrix.suffix}}.msi
- uses: actions/upload-artifact@v2
with:
name: package-${{ matrix.os }}
if-no-files-found: error
path: |
drg-*.tar.gz
drg-*.zip
- uses: actions/upload-artifact@v2
if: ${{ matrix.os == 'windows-2019' }}
with:
name: installer-${{ matrix.os }}
if-no-files-found: error
path: |
drg-*.msi
publish:
#
# The publish job will on all branches and tags, except PRs. However, it does only create a release when a
# tag of the right format is pushed.
#
if: ${{needs.check.outputs.do-publish}}
needs:
- check
- build
runs-on: ubuntu-latest
env:
VERSION: ${{needs.check.outputs.version}}
steps:
- name: Dump state
run: |
echo "Tag/version: ${VERSION} / ${{needs.check.outputs.version}}"
echo "Should we publish artifacts? - do-publish = ${{needs.check.outputs.do-publish}}"
echo "Release? - release = ${{needs.check.outputs.release}}"
echo "Pre-release? - prerelease = ${{needs.check.outputs.prerelease}}"
# we need the checkout for the "hub" tool later on
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
path: downloads
- name: Prepare upload area
run: |
mkdir uploads
mv downloads/package-* uploads/
mv downloads/installer-* uploads/
- name: Check staging content
run: |
find uploads
- name: Create Release
id: create-release
if: ${{ needs.check.outputs.release }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check.outputs.version }}
release_name: ${{ needs.check.outputs.version }}
draft: true
prerelease: ${{ needs.check.outputs.prerelease }}
- name: Upload release assets
if: ${{ needs.check.outputs.release }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: v${{ needs.check.outputs.version }}
run: |
# add packages
for pkg in tar.gz zip; do
hub release edit -m "" $(find uploads/ -type f -name "drg-*.${pkg}" -printf "-a %p ") $TAG
done
# finally, remove the draft status
hub release edit -m "" --draft=false $TAG