name: Symlink CI

on:
  workflow_dispatch:
  push:
    paths:
      - 'cmd/tools/vsymlink/**.v'
      - '.github/workflows/symlink_ci.yml'
  pull_request:
    paths:
      - 'cmd/tools/vsymlink/**.v'
      - '.github/workflows/symlink_ci.yml'

concurrency:
  group: symlink-${{ github.workflow }}-${{ github.ref_name == 'master' && github.sha || github.ref_name }}
  cancel-in-progress: true

jobs:
  symlink-unix:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-24.04, macos-13]
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Build V
        run: make -j4
      - name: Symlink
        run: |
          ./v symlink
          cd /tmp/ && v version
          cd ~ && v version
          echo 'println(123)' > hi.v
          v run hi.v
      - name: Unlink
        run: |
          rm "$(which v)"
          v --version && exit 1 || exit 0
      - name: Symlink (sudo)
        run: |
          sudo ./v symlink
          cd /tmp/ && v version
          cd ~ && v version
          echo 'println(123)' > hi.v
          v run hi.v
      - name: Unlink
        run: |
          rm "$(which v)"
          v --version && exit 1 || exit 0
      - name: Symlink (-githubci)
        run: ./v symlink -githubci
      - name: Test after symlink with -githubci (in a separate script)
        run: |
          cd /tmp/ && v version
          cd ~ && v version
          echo 'println(123)' > hi.v
          v run hi.v

  symlink-windows:
    runs-on: windows-2025
    strategy:
      matrix:
        flags: ['', '-githubci']
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Build V
        run: ./make.bat
      - name: Symlink
        run: ./v symlink ${{ matrix.flags }}
      - name: Check if V is usable
        run: |
          cd $RUNNER_TEMP && pwd && v version
          cd ~ && pwd && v version
          echo 'println(123)' > hi.v
          v run hi.v
