]> git.sesse.net Git - stockfish/blob - .github/workflows/stockfish_binaries.yml
Build and test more binaries in CI
[stockfish] / .github / workflows / stockfish_binaries.yml
1 name: Stockfish
2 on:
3   workflow_call:
4 jobs:
5   Stockfish:
6     name: ${{ matrix.config.name }} ${{ matrix.binaries }}
7     runs-on: ${{ matrix.config.os }}
8     env:
9       COMPILER: ${{ matrix.config.compiler }}
10       COMP: ${{ matrix.config.comp }}
11       EXT: ${{ matrix.config.ext }}
12       SDE: ${{ matrix.config.sde }}
13       NAME: ${{ matrix.config.simple_name }}
14       BINARY: ${{ matrix.binaries }}
15     strategy:
16       matrix:
17         config:
18           - name: Ubuntu 20.04 GCC
19             os: ubuntu-20.04
20             simple_name: ubuntu
21             compiler: g++
22             comp: gcc
23             shell: bash
24             archive_ext: tar
25             sde: /home/runner/work/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.14.0-2022-10-25-lin/sde -future --
26           - name: MacOS 12 Apple Clang
27             os: macos-12
28             simple_name: macos
29             compiler: clang++
30             comp: clang
31             shell: bash
32             archive_ext: tar
33           - name: Windows 2022 Mingw-w64 GCC x86_64
34             os: windows-2022
35             simple_name: windows
36             compiler: g++
37             comp: mingw
38             msys_sys: mingw64
39             msys_env: x86_64-gcc
40             shell: msys2 {0}
41             ext: .exe
42             sde: /d/a/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.14.0-2022-10-25-win/sde.exe -future --
43             archive_ext: zip
44         binaries:
45           - x86-32
46           - x86-64
47           - x86-64-modern
48           - x86-64-avx2
49           - x86-64-bmi2
50           - x86-64-avxvnni
51           - x86-64-avx512
52           - x86-64-vnni256
53           - x86-64-vnni512
54         exclude:
55           - binaries: x86-32
56             config: { os: macos-12 }
57           - binaries: x86-64-avx2
58             config: { os: macos-12 }
59           - binaries: x86-64-bmi2
60             config: { os: macos-12 }
61           - binaries: x86-64-avxvnni
62             config: { os: macos-12 }
63           - binaries: x86-64-avxvnni
64             config: { ubuntu-20.04 }
65           - binaries: x86-64-avx512
66             config: { os: macos-12 }
67           - binaries: x86-64-vnni256
68             config: { os: macos-12 }
69           - binaries: x86-64-vnni512
70             config: { os: macos-12 }
71     defaults:
72       run:
73         working-directory: src
74         shell: ${{ matrix.config.shell }}
75     steps:
76       - uses: actions/checkout@v3
77         with:
78           fetch-depth: 0
79
80       - name: Download required Linux packages
81         if: runner.os == 'Linux'
82         run: |
83           sudo apt update
84           sudo apt install g++-multilib g++-11-multilib
85
86       - name: Install fixed GCC on Linux
87         if: runner.os == 'Linux'
88         uses: egor-tensin/setup-gcc@v1
89         with:
90           version: 11
91
92       - name: Setup msys and install required packages
93         if: runner.os == 'Windows'
94         uses: msys2/setup-msys2@v2
95         with:
96           msystem: ${{ matrix.config.msys_sys }}
97           install: mingw-w64-${{ matrix.config.msys_env }} make git zip
98
99       - name: Install fixed GCC on Windows
100         if: runner.os == 'Windows'
101         run: |
102           wget https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc-11.3.0-2-any.pkg.tar.zst
103           pacman -U mingw-w64-x86_64-gcc-11.3.0-2-any.pkg.tar.zst --noconfirm
104
105       - name: Download SDE package
106         if: runner.os == 'Linux' || runner.os == 'Windows'
107         uses: petarpetrovt/setup-sde@v2.1
108         with:
109           environmentVariableName: SDE_DIR
110           sdeVersion: 9.14.0
111
112       - name: Download the used network from the fishtest framework
113         run: make net
114
115       - name: Extract the bench number from the commit history
116         run: |
117           for hash in $(git rev-list -100 HEAD); do
118             benchref=$(git show -s $hash | tac | grep -m 1 -o -x '[[:space:]]*\b[Bb]ench[ :]\+[1-9][0-9]\{5,7\}\b[[:space:]]*' | sed 's/[^0-9]//g') && break || true
119           done
120           [[ -n "$benchref" ]] && echo "benchref=$benchref" >> $GITHUB_ENV && echo "From commit: $hash" && echo "Reference bench: $benchref" || echo "No bench found"
121
122       - name: Check compiler
123         run: $COMPILER -v
124
125       - name: Test help target
126         run: make help
127
128       - name: Check git
129         run: git --version
130
131       # Compile profile guided builds
132
133       - name: Compile ${{ matrix.binaries }} build
134         run: |
135           make -j2 profile-build ARCH=$BINARY COMP=$COMP WINE_PATH="$SDE"
136           make strip ARCH=$BINARY COMP=$COMP
137           WINE_PATH="$SDE" ../tests/signature.sh $benchref
138           mv ./stockfish$EXT ../stockfish-$NAME-$BINARY$EXT
139
140       - name: Remove non src files
141         run: git clean -fx
142
143       - name: Download wiki
144         run: |
145           git clone https://github.com/official-stockfish/Stockfish.wiki.git ../wiki
146           rm -rf ../wiki/.git
147
148       - name: Create directory.
149         run: |
150           cd ..
151           mkdir stockfish
152           cp -r wiki stockfish/
153           cp -r src stockfish/
154           cp stockfish-$NAME-$BINARY$EXT stockfish/
155           cp "Top CPU Contributors.txt" stockfish/
156           cp Copying.txt stockfish/
157           cp AUTHORS stockfish/
158           cp CITATION.cff stockfish/
159           cp README.md stockfish/
160
161       - name: Create tar
162         if: runner.os != 'Windows'
163         run: |
164           cd ..
165           tar -cvf stockfish-$NAME-$BINARY.tar stockfish
166
167       - name: Create zip
168         if: runner.os == 'Windows'
169         run: |
170           cd ..
171           zip -r stockfish-$NAME-$BINARY.zip stockfish
172
173       - name: Upload binaries
174         if: runner.os != 'Windows'
175         uses: actions/upload-artifact@v3
176         with:
177           name: stockfish-${{ matrix.config.os }}-${{ matrix.binaries }}
178           path: stockfish-${{ matrix.config.simple_name }}-${{ matrix.binaries }}.tar
179
180       # Artifacts automatically get zipped
181       # to avoid double zipping, we use the unzipped directory
182       - name: Upload binaries
183         if: runner.os == 'Windows'
184         uses: actions/upload-artifact@v3
185         with:
186           name: stockfish-${{ matrix.config.os }}-${{ matrix.binaries }}
187           path: stockfish
188
189       - name: Release
190         if: startsWith(github.ref_name, 'sf_') && github.ref_type == 'tag'
191         uses: softprops/action-gh-release@v1
192         with:
193           files: stockfish-${{ matrix.config.simple_name }}-${{ matrix.binaries }}.${{ matrix.config.archive_ext }}
194
195       - name: Get last commit sha
196         id: last_commit
197         run: echo "COMMIT_SHA=$(git rev-parse HEAD | cut -c 1-8)" >> $GITHUB_ENV
198
199       - name: Get commit date
200         id: commit_date
201         run: echo "COMMIT_DATE=$(git show -s --date=format:'%Y%m%d' --format=%cd HEAD)" >> $GITHUB_ENV
202
203       # Make sure that an old ci which still runs on master doesn't recreate a prerelease
204       - name: Check Pullable Commits
205         id: check_commits
206         run: |
207           git fetch
208           CHANGES=$(git rev-list HEAD..origin/master --count)
209           echo "CHANGES=$CHANGES" >> $GITHUB_ENV
210
211       - name: Prerelease
212         if: github.ref_name == 'master' && env.CHANGES == '0'
213         continue-on-error: true
214         uses: softprops/action-gh-release@v1
215         with:
216           name: Stockfish dev-${{ env.COMMIT_DATE }}-${{ env.COMMIT_SHA }}
217           tag_name: stockfish-dev-${{ env.COMMIT_DATE }}-${{ env.COMMIT_SHA }}
218           prerelease: true
219           files: stockfish-${{ matrix.config.simple_name }}-${{ matrix.binaries }}.${{ matrix.config.archive_ext }}