name: Test and (maybe) Release
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-go@v2
        with:
          go-version: '1.16'
      - name: install needed dependencies
        run: |
          scripts/bootstrap
          echo "$HOME/bin" >> $GITHUB_PATH
      - name: install git-duet for testing
        run: scripts/install
      - name: Setup tmate session
        uses: mxschmitt/action-tmate@v3
      - name: test
        run: scripts/test

  # I had wanted to separate this workflow, but it doesn't seem possible to do
  # that _and_ check for tags, yet
  # https://stackoverflow.com/a/68078768
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    needs: [test]
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/setup-go@v2
        with:
          go-version: '1.16'
      - name: Build release assets
        run: scripts/dist
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: 'dist/*.tar.gz'

name: Test and (maybe) Release
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # for PRs, checkout head commit rather than detached commit to pass
          # version tests
          ref: ${{ github.event.pull_request.head.sha }}
          fetch_depth: 0
        if: ${{ github.event_name == "pull_request" }}
      - uses: actions/checkout@v2
        with:
          fetch_depth: 0
        if: ${{ github.event_name != "pull_request" }}
      - uses: actions/setup-go@v2
        with:
          go-version: '1.16'
      - name: install needed dependencies
        run: |
          scripts/bootstrap
          echo "$HOME/bin" >> $GITHUB_PATH
      - name: install git-duet for testing
        run: scripts/install
      - name: test
        run: scripts/test

  # I had wanted to separate this workflow, but it doesn't seem possible to do
  # that _and_ check for tags, yet
  # https://stackoverflow.com/a/68078768
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    needs: [test]
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/setup-go@v2
        with:
          go-version: '1.16'
      - name: Build release assets
        run: scripts/dist
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: 'dist/*.tar.gz'

Update checkouts to pull tags
Update checkouts to pull tags

So that calculating the version works correctly

Signed-off-by: Jesse Szwedko <719fcfb5cfbe2d227592ba0489e86dc2a3b7e15f@gmail.com>
