gr-bin 0.1.5

Interact with remote repositories like you interact with git
Documentation
name: Test and release

on: push

permissions:
  contents: write

jobs:
  test:
    name: Test if building works correctly
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Test if release is correct
        uses: actions-rs/cargo@v1
        with:
          command: build
      - name: Setup configuration files
        run: |
          git config --global user.email "gr-test@d7gr.net"
          git config --global user.name "Gr Test"
          mkdir -pv ~/.config ~/.ssh
          printf "$GR_CONFIGURATION" > ~/.config/gr.json
          printf "%s\n" "$SSH_KEY" > ~/.ssh/id_rsa
          chmod -R 700 ~/.ssh
          ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts
          ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
        env:
          GR_CONFIGURATION : ${{ secrets.GR_CONFIGURATION }}
          SSH_KEY : ${{ secrets.SSH_KEY }}
      - name: Run integration tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --test '*' -- --nocapture
        env:
          RUST_BACKTRACE: 1
  release:
    name: Release if we are on a tag
    runs-on: ubuntu-latest
    needs: [test]
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - name: Checkout the tag
        uses: actions/checkout@v3
      - name: Add toolchain for Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Restore cached dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: cargo-${{ hashFiles('**/Cargo.lock') }}
      - name: Test if release builds correctly
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target x86_64-unknown-linux-gnu
      - name: Build for Windows
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target x86_64-pc-windows-gnu
          use-cross: true
      # TODO: fix cross compile on MacOS
      # - name: Build for MacOS
      #   uses: actions-rs/cargo@v1
      #   with:
      #     command: build
      #     args: --release --target x86_64-apple-darwin
      #     use-cross: true
      - name: Convert binaries into compressed files
        run: |
          cd target/x86_64-unknown-linux-gnu/release && tar czf gr-bin_x86_64-unknown-linux-gnu.tar.gz gr && cd -
          cd target/x86_64-unknown-linux-gnu/release && zip gr-bin_x86_64-unknown-linux-gnu.zip gr && cd -
          cd target/x86_64-pc-windows-gnu/release && zip gr-bin_x86_64-pc-windows-gnu.zip gr.exe && cd -
      - name: Release on tags
        uses: softprops/action-gh-release@v1
        with:
          files: |
            target/x86_64-unknown-linux-gnu/release/gr-bin_x86_64-unknown-linux-gnu.tar.gz
            target/x86_64-unknown-linux-gnu/release/gr-bin_x86_64-unknown-linux-gnu.zip
            target/x86_64-pc-windows-gnu/release/gr-bin_x86_64-pc-windows-gnu.zip
      - uses: katyo/publish-crates@v2
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          ignore-unpublished-changes: true
      - name: Copy README before NPM npm publish
        run: cp README.md npm/README.md
      - name: Publish to NPM
        uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./npm/package.json