-
Notifications
You must be signed in to change notification settings - Fork 10
172 lines (170 loc) · 6.66 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
name: GitHub CI
on:
workflow_call:
outputs:
do-release:
value: ${{ jobs.semver.outputs.do-build == 'true' && jobs.semver.outputs.do-release == 'true' }}
ver-cur:
value: ${{ jobs.semver.outputs.ver-cur }}
workflow_dispatch:
push:
paths-ignore:
- '.github/*'
- '.github/*TEMPLATE/**'
branches:
- '**'
pull_request:
paths-ignore:
- '*.md'
- '.github/*'
- '.github/*TEMPLATE/**'
env:
is_pr: ${{ startsWith(github.ref, 'refs/pull/') }}
repo_default: 'Cxbx-Reloaded/XbSymbolDatabase'
jobs:
semver:
name: Generate Semver
runs-on: ubuntu-latest
outputs:
ver-prev: ${{ steps.semver-output.outputs.version_previous }}
ver-cur: ${{ steps.semver-output.outputs.version_current }}
# Hack method to generate true or false for jobs.
# Since job's "if" doesn't support env context.
do-build: ${{ steps.build-cond.outputs.do-build }}
do-release: ${{ github.repository == env.repo_default }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: RadWolfie/Semantic-Version-Action@main
id: semver-output
with:
repository: ${{ env.repo_default }}
version_major_init: 3
version_minor_init: 0
- name: Run Build Conditional
id: build-cond
run: |
if [ "true" == "${{ (github.event_name != 'schedule' && github.event_name != 'workflow_dispatch') || steps.semver-output.outputs.version_previous != steps.semver-output.outputs.version_current }}" ]
then
echo "do-build=true" >> $GITHUB_OUTPUT
else
echo "do-build=false" >> $GITHUB_OUTPUT
fi
- name: Generate Changelog
if: steps.build-cond.outputs.do-build == 'true'
run: |
if [ "true" == "${{ env.is_pr }}" ]
then
git log --pretty=format:"%h: %s%n%w(0,11)%-b%n" ${{ steps.semver-output.outputs.version_previous }}..HEAD > changelog
else
git log --first-parent --pretty=format:"%h: %s%n%w(0,11)%-b%n" ${{ steps.semver-output.outputs.version_previous }}..HEAD > changelog
fi
# NOTE: Require to reduce workload from CI service from fetch whole git content.
- name: Upload Changelog
if: steps.build-cond.outputs.do-build == 'true'
uses: actions/upload-artifact@v4
with:
name: changelog
path: changelog
matrix_setup:
name: Setup Builders
runs-on: ubuntu-latest
outputs:
builder: ${{steps.set-builder.outputs.result}}
steps:
- uses: actions/github-script@v7
id: set-builder
with:
script: |
const platforms = [
{"platform": "Windows", "folder": "win", "cmake-build-param": "-j $env:NUMBER_OF_PROCESSORS"},
{"platform": "Linux", "folder": "linux", "cmake-build-param": "-j $(nproc --all)", "cmake-generator": "-G \"Unix Makefiles\""},
{"platform": "macOS", "folder": "macos", "cmake-build-param": "-j $(sysctl -n hw.ncpu)"}
];
let builder = [];
for (let build of platforms.values()) {
if (build.platform === "Windows") {
// always use the latest os
build["os"] = "windows-latest";
// create x86 build
build["arch"] = "x86";
build["cmake-generator"] = "-A Win32";
builder.push(Object.assign({}, build));
// create x64 build
build["arch"] = "x64";
build["cmake-generator"] = "-A x64";
builder.push(Object.assign({}, build));
}
if (build.platform === "Linux") {
// no other variant needed at this time
build["os"] = "ubuntu-latest";
build["arch"] = "x64";
builder.push(Object.assign({}, build));
}
if (build.platform === "macOS") {
// always use the latest os
build["os"] = "macos-latest";
// create x64 build
build["arch"] = "x64";
build["cmake-generator"] = "-G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64";
builder.push(Object.assign({}, build));
// create arm64 build
build["arch"] = "arm64";
build["cmake-generator"] = "-G Xcode -DCMAKE_OSX_ARCHITECTURES=arm64";
builder.push(Object.assign({}, build));
}
}
console.log(builder);
return builder;
build:
name: ${{ matrix.builder.platform }} (${{ matrix.builder.arch }}, ${{ matrix.configuration }})
runs-on: ${{ matrix.builder.os }}
needs: [semver, matrix_setup]
if: needs.semver.outputs.do-build == 'true'
strategy:
fail-fast: false
matrix:
configuration: [Debug, Release]
builder: ${{fromJSON(needs.matrix_setup.outputs.builder)}}
steps:
- uses: actions/checkout@v4
- name: Generate CMake Files
# NOTES:
# -Werror=dev is used to validate CMakeLists.txt for any faults.
run: cmake -B build -Werror=dev ${{ matrix.builder.cmake-generator }}
- name: Build
run: cmake --build build --config ${{ matrix.configuration }} ${{ matrix.builder.cmake-build-param }}
- name: CTests
run: ctest --test-dir build --build-config ${{ matrix.configuration }} --verbose
- name: Copy Files
if: matrix.configuration == 'Release'
run: cmake --install build --config ${{ matrix.configuration }} --prefix upload/${{ matrix.builder.folder }}_${{ matrix.builder.arch }}
- name: Upload Build Artifact
if: matrix.configuration == 'Release'
uses: actions/upload-artifact@v4
with:
name: XbSymbolDatabase-${{ matrix.builder.folder }}_${{ matrix.builder.arch }}
# roughly translate to upload/<platform_arch>/<bin | lib | include>/<anything in here and after>
path: upload/*/*/*
if-no-files-found: error
- name: Upload Misc Artifact
if: matrix.builder.cmake-generator == '-G "Unix Makefiles"' && matrix.configuration == 'Release'
uses: actions/upload-artifact@v4
with:
name: XbSymbolDatabase-misc
path: |
README.md
LICENSE
if-no-files-found: error
merge:
name: Merge Artifacts
runs-on: ubuntu-latest
needs: [semver, build]
if: ${{ !cancelled() && needs.semver.outputs.do-build == 'true' }}
steps:
- uses: actions/upload-artifact/merge@v4
with:
name: XbSymbolDatabase
pattern: XbSymbolDatabase-*
delete-merged: true