fork/numbat

git clone https://git.julia.blue/fork/numbat

Mohammed AnasCorrect instruction to rebuild docs in CI workflow794da79

master
13.9 KiB371 linesraw
1name: CICD
2
3env:
4  CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
5  MSRV_FEATURES: ""
6
7on:
8  workflow_dispatch:
9  pull_request:
10  push:
11    branches:
12      - master
13    tags:
14      - '*'
15
16jobs:
17  crate_metadata:
18    name: Extract crate metadata
19    runs-on: ubuntu-latest
20    steps:
21    - uses: actions/checkout@v4
22    - name: Extract crate information
23      id: crate_metadata
24      run: |
25        cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
26        cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
27        cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
28        cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
29        cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
30    outputs:
31      name: ${{ steps.crate_metadata.outputs.name }}
32      version: ${{ steps.crate_metadata.outputs.version }}
33      maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
34      homepage: ${{ steps.crate_metadata.outputs.homepage }}
35      msrv: ${{ steps.crate_metadata.outputs.msrv }}
36
37  ensure_cargo_fmt:
38    name: Ensure 'cargo fmt' has been run
39    runs-on: ubuntu-20.04
40    steps:
41    - uses: dtolnay/rust-toolchain@stable
42      with:
43        components: rustfmt
44    - uses: actions/checkout@v4
45    - run: cargo fmt -- --check
46
47  documentation_checks:
48    name: Documentation checks
49    runs-on: ubuntu-20.04
50    steps:
51    - uses: dtolnay/rust-toolchain@stable
52    - uses: actions/checkout@v3
53    - name: Install mdbook
54      run: |
55        cargo install mdbook
56        cargo install mdbook-linkcheck
57    - name: Build documentation
58      run: |
59        cd book
60        bash build.sh
61        if [ -n "$(git status --porcelain)" ]; then
62          echo "Documentation not up to date."
63          echo "Make sure to run 'build.sh' in the book/ folder"
64          exit 1
65        fi
66
67  wasm:
68    name: WASM version
69    runs-on: ubuntu-20.04
70    steps:
71    - uses: dtolnay/rust-toolchain@stable
72    - uses: actions/checkout@v3
73    - name: Install wasm-pack
74      run: |
75        curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
76    - name: Build WASM version
77      run: |
78        cd numbat-wasm
79        bash build.sh
80    - name: Test WASM version
81      run: |
82        cd numbat-wasm
83        bash test.sh
84
85  min_version:
86    name: Minimum supported rust version
87    runs-on: ubuntu-20.04
88    needs: crate_metadata
89    steps:
90    - name: Checkout source code
91      uses: actions/checkout@v4
92
93    - name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
94      uses: dtolnay/rust-toolchain@master
95      with:
96        toolchain: ${{ needs.crate_metadata.outputs.msrv }}
97        components: clippy
98    - name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
99      run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
100    - name: Run tests
101      run: cargo test --locked ${{ env.MSRV_FEATURES }}
102
103  build:
104    name: ${{ matrix.job.target }} (${{ matrix.job.os }})
105    runs-on: ${{ matrix.job.os }}
106    needs: crate_metadata
107    strategy:
108      fail-fast: false
109      matrix:
110        job:
111          - { target: aarch64-unknown-linux-gnu   , os: ubuntu-20.04, use-cross: true }
112          - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true }
113          - { target: arm-unknown-linux-musleabihf, os: ubuntu-20.04, use-cross: true }
114          - { target: i686-pc-windows-msvc        , os: windows-2019                  }
115          - { target: i686-unknown-linux-gnu      , os: ubuntu-20.04, use-cross: true }
116          - { target: i686-unknown-linux-musl     , os: ubuntu-20.04, use-cross: true }
117          - { target: x86_64-apple-darwin         , os: macos-12                      }
118          #- { target: x86_64-pc-windows-gnu       , os: windows-2019                  }
119          - { target: x86_64-pc-windows-msvc      , os: windows-2019                  }
120          - { target: x86_64-unknown-linux-gnu    , os: ubuntu-20.04, use-cross: true }
121          - { target: x86_64-unknown-linux-musl   , os: ubuntu-20.04, use-cross: true }
122    env:
123      BUILD_CMD: cargo
124    steps:
125    - name: Checkout source code
126      uses: actions/checkout@v4
127
128    - name: Install prerequisites
129      shell: bash
130      run: |
131        case ${{ matrix.job.target }} in
132          arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
133          aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
134        esac
135
136    - name: Install Rust toolchain
137      uses: dtolnay/rust-toolchain@stable
138      with:
139        targets: ${{ matrix.job.target }}
140
141    - name: Install cross
142      if: matrix.job.use-cross
143      uses: taiki-e/install-action@v2
144      with:
145        tool: cross
146
147    - name: Overwrite build command env variable
148      if: matrix.job.use-cross
149      shell: bash
150      run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
151
152    - name: Show version information (Rust, cargo, GCC)
153      shell: bash
154      run: |
155        gcc --version || true
156        rustup -V
157        rustup toolchain list
158        rustup default
159        cargo -V
160        rustc -V
161
162    - name: Build
163      shell: bash
164      run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
165
166    - name: Set binary name & path
167      id: bin
168      shell: bash
169      run: |
170        # Figure out suffix of binary
171        EXE_suffix=""
172        case ${{ matrix.job.target }} in
173          *-pc-windows-*) EXE_suffix=".exe" ;;
174        esac;
175
176        # Setup paths
177        BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
178        BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
179
180        # Let subsequent steps know where to find the binary
181        echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
182        echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
183
184    - name: Set testing options
185      id: test-options
186      shell: bash
187      run: |
188        # test only library unit tests and binary for arm-type targets
189        unset CARGO_TEST_OPTIONS
190        unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${{ needs.crate_metadata.outputs.name }}" ;; esac;
191        echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
192
193    - name: Run tests
194      shell: bash
195      run: $BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
196
197    - name: Create tarball
198      id: package
199      shell: bash
200      run: |
201        PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
202        PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
203        PKG_NAME=${PKG_BASENAME}${PKG_suffix}
204        echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
205
206        PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
207        ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
208        mkdir -p "${ARCHIVE_DIR}"
209
210        # Binary
211        cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
212
213        # README and LICENSE files
214        cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "$ARCHIVE_DIR"
215
216        # Desktop file and icons
217        mkdir "$ARCHIVE_DIR/assets"
218        cp "assets/numbat.desktop" assets/numbat-*x*.png "assets/numbat.svg" "$ARCHIVE_DIR/assets"
219
220        # Numbat prelude
221        cp -r numbat/modules "$ARCHIVE_DIR"
222
223        # base compressed package
224        pushd "${PKG_STAGING}/" >/dev/null
225        case ${{ matrix.job.target }} in
226          *-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
227          *) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
228        esac;
229        popd >/dev/null
230
231        # Let subsequent steps know where to find the compressed package
232        echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
233
234    - name: Create Debian package
235      id: debian-package
236      shell: bash
237      if: startsWith(matrix.job.os, 'ubuntu')
238      run: |
239        COPYRIGHT_YEARS="2022 - "$(date "+%Y")
240        DPKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/debian-package"
241        DPKG_DIR="${DPKG_STAGING}/dpkg"
242        mkdir -p "${DPKG_DIR}"
243
244        DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}
245        DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }}-musl
246        case ${{ matrix.job.target }} in *-musl*) DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-musl ; DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }} ;; esac;
247        DPKG_VERSION=${{ needs.crate_metadata.outputs.version }}
248
249        unset DPKG_ARCH
250        case ${{ matrix.job.target }} in
251          aarch64-*-linux-*) DPKG_ARCH=arm64 ;;
252          arm-*-linux-*hf) DPKG_ARCH=armhf ;;
253          i686-*-linux-*) DPKG_ARCH=i686 ;;
254          x86_64-*-linux-*) DPKG_ARCH=amd64 ;;
255          *) DPKG_ARCH=notset ;;
256        esac;
257
258        DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb"
259        echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT
260
261        # Binary
262        install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
263
264        # README and LICENSE
265        install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
266        install -Dm644 "LICENSE-MIT" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-MIT"
267        install -Dm644 "LICENSE-APACHE" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-APACHE"
268
269        # Desktop file and icons
270        install -Dm644 "assets/numbat.desktop" "${DPKG_DIR}/usr/share/applications/numbat.desktop"
271        install -Dm644 "assets/numbat.svg" "${DPKG_DIR}/usr/share/icons/hicolor/scalable/apps/numbat.svg"
272
273        for s in 16 22 24 32 48 64 128 256 512; do
274          install -Dm644 "assets/numbat-${s}x${s}.png" "${DPKG_DIR}/usr/share/icons/hicolor/${s}x${s}/apps/numbat.png"
275        done
276
277        # Numbat prelude
278        mkdir -p "${DPKG_DIR}/usr/share/${DPKG_BASENAME}"
279        cp -r numbat/modules "${DPKG_DIR}/usr/share/${DPKG_BASENAME}"
280
281        cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <<EOF
282        Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
283        Upstream-Name: ${{ needs.crate_metadata.outputs.name }}
284        Source: ${{ needs.crate_metadata.outputs.homepage }}
285
286        Files: *
287        Copyright: ${{ needs.crate_metadata.outputs.maintainer }}
288        Copyright: $COPYRIGHT_YEARS ${{ needs.crate_metadata.outputs.maintainer }}
289        License: Apache-2.0 or MIT
290
291        License: Apache-2.0
292          On Debian systems, the complete text of the Apache-2.0 can be found in the
293          file /usr/share/common-licenses/Apache-2.0.
294
295        License: MIT
296          Permission is hereby granted, free of charge, to any
297          person obtaining a copy of this software and associated
298          documentation files (the "Software"), to deal in the
299          Software without restriction, including without
300          limitation the rights to use, copy, modify, merge,
301          publish, distribute, sublicense, and/or sell copies of
302          the Software, and to permit persons to whom the Software
303          is furnished to do so, subject to the following
304          conditions:
305          .
306          The above copyright notice and this permission notice
307          shall be included in all copies or substantial portions
308          of the Software.
309          .
310          THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
311          ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
312          TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
313          PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
314          SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
315          CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
316          OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
317          IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
318          DEALINGS IN THE SOFTWARE.
319        EOF
320          chmod 644 "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright"
321
322          # control file
323          mkdir -p "${DPKG_DIR}/DEBIAN"
324          cat > "${DPKG_DIR}/DEBIAN/control" <<EOF
325        Package: ${DPKG_BASENAME}
326        Version: ${DPKG_VERSION}
327        Section: utils
328        Priority: optional
329        Maintainer: ${{ needs.crate_metadata.outputs.maintainer }}
330        Homepage: ${{ needs.crate_metadata.outputs.homepage }}
331        Architecture: ${DPKG_ARCH}
332        Provides: ${{ needs.crate_metadata.outputs.name }}
333        Conflicts: ${DPKG_CONFLICTS}
334        Description:  Statically typed programming language for scientific computations with first class support for physical dimensions and units
335        EOF
336
337        DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}"
338        echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT
339
340        # build dpkg
341        fakeroot dpkg-deb --build "${DPKG_DIR}" "${DPKG_PATH}"
342
343    - name: "Artifact upload: tarball"
344      uses: actions/upload-artifact@master
345      with:
346        name: ${{ steps.package.outputs.PKG_NAME }}
347        path: ${{ steps.package.outputs.PKG_PATH }}
348
349    - name: "Artifact upload: Debian package"
350      uses: actions/upload-artifact@master
351      if: steps.debian-package.outputs.DPKG_NAME
352      with:
353        name: ${{ steps.debian-package.outputs.DPKG_NAME }}
354        path: ${{ steps.debian-package.outputs.DPKG_PATH }}
355
356    - name: Check for release
357      id: is-release
358      shell: bash
359      run: |
360        unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
361        echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
362
363    - name: Publish archives and packages
364      uses: softprops/action-gh-release@v1
365      if: steps.is-release.outputs.IS_RELEASE
366      with:
367        files: |
368          ${{ steps.package.outputs.PKG_PATH }}
369          ${{ steps.debian-package.outputs.DPKG_PATH }}
370      env:
371        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}