-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (182 loc) · 6.43 KB
/
ci.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: ci
on:
push:
branches: [main]
paths-ignore:
- '**.md'
pull_request:
branches: [main]
paths-ignore:
- '**.md'
release:
branches: [main]
types: [published]
jobs:
version:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
ref: main
fetch-depth: '0'
- name: Get tag if tagged/released and set TAG env var
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG=$(echo $GITHUB_REF | cut -d '/' -f3)
echo "TAG: $TAG"
if [[ $TAG == "v"* ]]; then
TAG="${TAG:1}"
fi
echo "TAG: $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Set TAG env var from tag if tagged/released and update VERSION in version file
if: startsWith(github.ref, 'refs/tags/v')
run: |
VERSION_FILE="./src/version.hpp"
OLD_TAG=$(grep VERSION $VERSION_FILE | cut -d ' ' -f3 | tr -d '"' | tr -d '\n')
echo "OLD_TAG: $OLD_TAG"
NEW_TAG="$TAG"
echo "NEW_TAG: $NEW_TAG"
if [[ "$NEW_TAG" == "$OLD_TAG" ]]; then
echo "Old and new tags are the same! No update required!"
else
echo "Updating VERSION in version file [$OLD_TAG => $NEW_TAG]"
sed -i -e "s|VERSION .*|VERSION \"$NEW_TAG\"|" $VERSION_FILE
git config --global user.name 'Azeem Sajid'
git config --global user.email '[email protected]'
git diff "$VERSION_FILE"
git add "$VERSION_FILE"
git commit -m "Automatic version update from $OLD_TAG to $NEW_TAG."
git push
echo "Version updated successfully!"
fi
ci:
needs: version
strategy:
fail-fast: true
matrix:
os: [ubuntu-20.04, macos-11]
runs-on: ${{ matrix.os }}
env:
ARTIFACT_RETENTION_DAYS: 5
steps:
- name: Checkout
uses: actions/checkout@v3
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
- name: Checkout on tag/release
uses: actions/checkout@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
ref: main
fetch-depth: '0'
- name: Set TAG env var from VERSION in version file
run: |
VERSION_FILE="./src/version.hpp"
TAG=$(grep VERSION $VERSION_FILE | cut -d ' ' -f3 | tr -d '"' | tr -d '\n')
echo "TAG: $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Set up env vars
env:
TAG: ${{ env.TAG }}
run: |
AMD64_LINUX="spancopy-$TAG-amd64-linux"
ARM64_LINUX="spancopy-$TAG-arm64-linux"
AMD64_WINDOWS="spancopy-$TAG-amd64-windows"
AMD64_MACOSX="spancopy-$TAG-amd64-macosx"
PREFIXES=(AMD64_LINUX ARM64_LINUX AMD64_WINDOWS AMD64_MACOSX)
for PREFIX in ${PREFIXES[*]}; do
PREFIX_KEY="${PREFIX}_PREFIX"
PREFIX_VAL="${!PREFIX}"
PREFIX_TAR_KEY="${PREFIX_KEY}_TAR"
PREFIX_TAR_VAL="${PREFIX_VAL}.tar.gz"
echo "$PREFIX_KEY: $PREFIX_VAL"
echo "$PREFIX_TAR_KEY: $PREFIX_TAR_VAL"
echo "$PREFIX_KEY=$PREFIX_VAL" >> $GITHUB_ENV
echo "$PREFIX_TAR_KEY=$PREFIX_TAR_VAL" >> $GITHUB_ENV
done
# --- Build ---
- name: Install Dependencies
if: runner.os == 'Linux'
run: |
sudo apt install -y tree g++-mingw-w64 g++-aarch64-linux-gnu
- name: Build (${{ env.AMD64_LINUX_PREFIX }})
if: runner.os == 'Linux'
env:
CXX: g++
STRIP: strip
BUILD_DIR: ${{ env.AMD64_LINUX_PREFIX }}
TAR: ${{ env.AMD64_LINUX_PREFIX_TAR }}
run: |
./scripts/ci-build.sh
./tests/test.sh
- name: Build (${{ env.ARM64_LINUX_PREFIX }})
if: runner.os == 'Linux'
env:
CXX: aarch64-linux-gnu-g++
STRIP: aarch64-linux-gnu-strip
BUILD_DIR: ${{ env.ARM64_LINUX_PREFIX }}
TAR: ${{ env.ARM64_LINUX_PREFIX_TAR }}
run: ./scripts/ci-build.sh
- name: Build (${{ env.AMD64_WINDOWS_PREFIX }})
if: runner.os == 'Linux'
env:
CXX: x86_64-w64-mingw32-g++
STRIP: x86_64-w64-mingw32-strip
BUILD_DIR: ${{ env.AMD64_WINDOWS_PREFIX }}
TAR: ${{ env.AMD64_WINDOWS_PREFIX_TAR }}
run: ./scripts/ci-build.sh
- name: Build (${{ env.AMD64_MACOSX_PREFIX }})
if: runner.os == 'macOS'
env:
CXX: clang++
STRIP: strip
BUILD_DIR: ${{ env.AMD64_MACOSX_PREFIX }}
TAR: ${{ env.AMD64_MACOSX_PREFIX_TAR }}
run: |
./scripts/ci-build.sh
./tests/test.sh
# --- Upload ---
- name: Upload (${{ env.AMD64_LINUX_PREFIX_TAR }})
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: ${{ env.AMD64_LINUX_PREFIX_TAR }}
path: ${{ env.AMD64_LINUX_PREFIX }}/${{ env.AMD64_LINUX_PREFIX_TAR }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error
- name: Upload (${{ env.ARM64_LINUX_PREFIX_TAR }})
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARM64_LINUX_PREFIX_TAR }}
path: ${{ env.ARM64_LINUX_PREFIX }}/${{ env.ARM64_LINUX_PREFIX_TAR }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error
- name: Upload (${{ env.AMD64_WINDOWS_PREFIX_TAR }})
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: ${{ env.AMD64_WINDOWS_PREFIX_TAR }}
path: ${{ env.AMD64_WINDOWS_PREFIX }}/${{ env.AMD64_WINDOWS_PREFIX_TAR }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error
- name: Upload (${{ env.AMD64_MACOSX_PREFIX_TAR }})
if: runner.os == 'macOS'
uses: actions/upload-artifact@v3
with:
name: ${{ env.AMD64_MACOSX_PREFIX_TAR }}
path: ${{ env.AMD64_MACOSX_PREFIX }}/${{ env.AMD64_MACOSX_PREFIX_TAR }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: error
# --- Upload on tag/release ---
- name: Upload release artifacts
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
files: |
${{ env.AMD64_LINUX_PREFIX }}/${{ env.AMD64_LINUX_PREFIX_TAR }}
${{ env.ARM64_LINUX_PREFIX }}/${{ env.ARM64_LINUX_PREFIX_TAR }}
${{ env.AMD64_WINDOWS_PREFIX }}/${{ env.AMD64_WINDOWS_PREFIX_TAR }}
${{ env.AMD64_MACOSX_PREFIX }}/${{ env.AMD64_MACOSX_PREFIX_TAR }}