name: On Push
on:
  push:
jobs:
  test:
    runs-on: ubuntu-latest
    # release only on fix/refactor-repo
    if: github.ref == 'refs/heads/fix/refactor-repo'
    name: Release
    steps:
      - uses: actions/checkout@v2
      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: '16.x'
      - name: Setup Rust
        uses: ATiltedTree/setup-rust@v1
        with:
          rust-version: stable
      - name: Install circom 
        run: git clone https://github.com/iden3/circom.git
      - run: cd circom && cargo build --release
      - run: cd circom && cargo install --path circom
      - name: Update .npmrc with auth token
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
      - run: yarn build
      - run: yarn test
      - name: Semantic release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: yarn publish

  release:
    runs-on: ubuntu-latest
    # release only on main
    if: github.ref == 'refs/heads/main'
    name: Release
    steps:
      - uses: actions/checkout@v2
      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: '16.x'
      - name: Update .npmrc with auth token
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
      - run: yarn install
      - run: yarn bootstrap
      - run: yarn build:all
      - name: Semantic release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: yarn release:all