bookstack-exporter 0.1.0

Export a BookStack instance as a hierarchy of files
Documentation
name: Build and Release

on:
  push:
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    strategy:
      matrix:
        include:
        - os: ubuntu-latest
          target: x86_64-unknown-linux-gnu
          bin: bookstack-exporter
        # Cross compiling takes less time twice the time as compiling on Windows, therefore cheaper
        - os: ubuntu-latest
          target: x86_64-pc-windows-msvc
          bin: bookstack-exporter.exe
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3

      - name: Install cargo-xwin (cross compile for x86_64-pc-windows-msvc)
        if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-pc-windows-msvc'
        run: |

          cargo install cargo-xwin
          rustup target add x86_64-pc-windows-msvc

      - name: Build for x86_64-pc-windows-msvc
        if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-pc-windows-msvc'
        run: |

          cargo xwin build --release --target x86_64-pc-windows-msvc

      - name: Build for x86_64-unknown-linux-gnu
        if: matrix.target == 'x86_64-unknown-linux-gnu'
        run: cargo build --release --verbose --target ${{ matrix.target }}

      - name: Run tests
        run: cargo test --verbose

      - name: Set env
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
        if: startsWith(github.ref, 'refs/tags/')

      - name: Determine archive name
        shell: bash
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "ARCHIVE=bookstack-exporter-$RELEASE_VERSION-${{ matrix.target }}" >> $GITHUB_ENV

      - name: Creating directory for archive
        shell: bash
        if: startsWith(github.ref, 'refs/tags/')
        run: |

          mkdir -p "$ARCHIVE"/
          cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "$ARCHIVE"/

      - name: Build archive (Unix)
        shell: bash
        if: startsWith(github.ref, 'refs/tags/') &&  matrix.target == 'x86_64-unknown-linux-gnu'
        run: |

          tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
          shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
          echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV
          echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV

      - name: Build archive (Windows)
        shell: bash
        if: startsWith(github.ref, 'refs/tags/') && matrix.target == 'x86_64-pc-windows-msvc'
        run: |

          7z a "$ARCHIVE.zip" "$ARCHIVE"
          shasum -a 256 "$ARCHIVE.zip" > "$ARCHIVE.zip.sha256"
          echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV
          echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> $GITHUB_ENV

      - name: Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |

            bookstack-exporter*.zip
            bookstack-exporter*.tar.gz
            bookstack-exporter*.sha256
          token: ${{ secrets.ACCESS_TOKEN }}