gitnu 0.6.7

gitnu indexes your git status so you can use numbers instead of filenames.
Documentation
name: ci

on:
  push:
    branches:
      - main
      - dev
      - major
      - minor
      - patch
      - prerelease

jobs:
  pre:
    name: Preprocessing
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.matrix.outputs.matrix }}
      version: ${{ steps.version.outputs.version }}
      increment: ${{ steps.increment.outputs.increment }}
    steps:
      - uses: actions/checkout@v3
      - run: git fetch --tags

      # Sets the increment: how much to push the version number
      - run: |
          case ${{ github.ref_name }} in
            main) echo "increment=patch" >> $GITHUB_OUTPUT;;
            dev) echo "increment=prerelease" >> $GITHUB_OUTPUT;;
            *) echo "increment=${{ github.ref_name }}" >> $GITHUB_OUTPUT;;
          esac
        id: increment

      # Obtains the matrix strategy from `./matrix.json` to use for
      # building, testing, and releasing artifacts on GitHub Releases
      - run: echo "matrix=$(jq -rc . .github/workflows/matrix.json)" >> $GITHUB_OUTPUT
        id: matrix

      # Checks that the version on Cargo.toml matches the latest git
      # tag, and sets the `version` variable to the next version.
      - run: echo "version=$(ARG=next-${{ steps.increment.outputs.increment }}-version make py)" >> $GITHUB_OUTPUT
        id: version

  build-and-test:
    name: Build & Test
    needs: [pre]
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

    steps:
      - uses: actions/checkout@v3

      # required for tests
      - run: make ci-git-user

      - name: Run tests
        run: make ci-test

  increment:
    name: Increment ${{ needs.pre.outputs.increment }} version
    needs: [pre, build-and-test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: git fetch --tags
      - run: make ci-git-user

      - name: Increment ${{ needs.pre.outputs.increment }} version
        run: make py
        env:
          ARG: increment-${{ needs.pre.outputs.increment }}

  # publish patch-level updates and above only
  publish-crates-io:
    name: Publish to Crates.io
    if: needs.pre.outputs.increment != 'prerelease'
    needs: [pre, increment]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          ref: v${{ needs.pre.outputs.version }}

      - uses: katyo/publish-crates@v2
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  release-github:
    name: Release on GitHub
    needs: [pre, increment]
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

    steps:
      - uses: actions/checkout@v3
        with:
          ref: v${{ needs.pre.outputs.version }}

      - run: |
          TARGET_DIR=./target/${{ matrix.target }}
          echo "TARGET_DIR=$TARGET_DIR" >> $GITHUB_ENV
          echo "BINFILE=$TARGET_DIR/release/git-nu" >> $GITHUB_ENV

      - name: Build binary
        run: make ci-build
        env:
          CARGO_BUILD_TARGET_DIR: ${{ env.TARGET_DIR }}

      - name: Strip release binary
        if: >-
          (matrix.build == 'linux' || matrix.build == 'linux-arm' || matrix.build == 'macos')
        run: strip ${{ env.BINFILE }}

      - name: Build archive
        run: |
          STAGING="git-nu-v${{ needs.pre.outputs.version }}-${{ matrix.target }}"
          mkdir -p "$STAGING"
          cp ${{ env.BINFILE }} "$STAGING"
          tar czf "$STAGING.tar.gz" "$STAGING"
          echo "ASSET=$STAGING.tar.gz" >> $GITHUB_ENV

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: v${{ needs.pre.outputs.version }}
          files: ${{ env.ASSET }}