fork/numbat

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

David PeterFix copyright year9800cc2

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