# Code generated internal/ci/base/write.cue; DO NOT EDIT.

name: TryBot
"on":
  push:
    branches:
      - ci/test
      - master
      - release-branch.*
    tags-ignore:
      - v*
  pull_request: {}
  schedule:
    - cron: 0 2 * * *
  workflow_dispatch: {}
jobs:
  test:
    defaults:
      run:
        shell: bash --noprofile --norc -euo pipefail {0}
    permissions:
      contents: read
      id-token: write
    strategy:
      fail-fast: false
      matrix:
        runner:
          - namespace-profile-linux-amd64-large
          - ns-macos-arm64
          - ns-windows-amd64
        go-version:
          - 1.25.x
          - 1.26.x
    runs-on: ${{ matrix.runner }}
    if: |-
      (contains(github.event.head_commit.message, '
      Dispatch-Trailer: {"type":"trybot"')) || ! (contains(github.event.head_commit.message, '
      Dispatch-Trailer: {"type":"'))
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 0
          persist-credentials: false
      - name: Reset git directory modification times
        run: touch -t 202211302355 $(find * -type d)
      - name: Restore git file modification times
        uses: chetan/git-restore-mtime-action@cbf8161ddb4e9b162409104954fb540e8a38c1da
      - id: DispatchTrailer
        name: Try to extract Dispatch-Trailer
        run: |-
          x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')"
          if [[ "$x" == "" ]]
          then
             # Some steps rely on the presence or otherwise of the Dispatch-Trailer.
             # We know that we don't have a Dispatch-Trailer in this situation,
             # hence we use the JSON value null in order to represent that state.
             # This means that GitHub expressions can determine whether a Dispatch-Trailer
             # is present or not by checking whether the fromJSON() result of the
             # output from this step is the JSON value null or not.
             x=null
          fi
          echo "value<<EOD" >> $GITHUB_OUTPUT
          echo "$x" >> $GITHUB_OUTPUT
          echo "EOD" >> $GITHUB_OUTPUT
      - if: |-
          ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"'))
        name: Check we don't have Dispatch-Trailer on a protected branch
        run: |-
          echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch"
          false
      - name: Install Go
        uses: actions/setup-go@v6
        with:
          cache: false
          go-version: ${{ matrix.go-version }}
      - name: Set common go env vars
        run: |-
          case $(go env GOARCH) in
          amd64) go env -w GOAMD64=v3 ;;   # 2013 and later; makes `go test -race` 15% faster
          arm64) go env -w GOARM64=v8.6 ;; # Apple M2 and later
          esac

          # Otherwise `go test -race` sleeps for 1s on every package;
          # see https://go.dev/issues/20364.
          echo "GORACE=atexit_sleep_ms=10" >> $GITHUB_ENV

          # Dump env for good measure
          go env
      - if: github.event_name != 'schedule' && matrix.runner != 'ns-windows-amd64'
        uses: namespacelabs/nscloud-cache-action@v1
        with:
          cache: go
      - if: |-
          github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test'))
        run: go env -w GOFLAGS=-count=1
      - name: Login to CUE registry
        uses: cue-labs/registry-login-action@v1
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Early git and code sanity checks
        run: go run ./internal/ci/checks
      - if: |-
          ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || !(matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Test
        run: go test ./...
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Test with -race
        run: go test -race ./...
      - if: |-
          (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Test on 32 bits
        env:
          GOARCH: "386"
        run: go test -short ./...
      - name: Test with -tags=cuewasm
        run: go test -tags cuewasm ./cmd/cue/cmd ./cue/inject/wasm
      - id: auth
        if: |-
          github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: gcloud auth for end-to-end tests
        uses: google-github-actions/auth@v3
        with:
          credentials_json: ${{ secrets.E2E_GCLOUD_KEY }}
      - if: |-
          github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: gcloud setup for end-to-end tests
        uses: google-github-actions/setup-gcloud@v3
      - if: |-
          github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: End-to-end test
        env:
          CUE_TEST_TOKEN: inherit
        run: |-
          cd internal/_e2e
          go test -race
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        run: |-
          go mod tidy -diff
          go vet ./...
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Verify the end-to-end tests still build
        working-directory: ./internal/_e2e
        run: go test -run=-
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        env:
          STATICCHECK_CACHE: /cache/staticcheck
        run: go tool -modfile=internal/tools.mod staticcheck ./...
      - if: |-
          (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
          Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Check all git tags are available
        run: |-
          cd $(mktemp -d)

          git ls-remote --tags https://github.com/cue-lang/cue >github.txt
          echo "GitHub tags:"
          sed 's/^/    /' github.txt

          git ls-remote --tags https://cue.gerrithub.io/cue-lang/cue >gerrit.txt

          if ! diff -u github.txt gerrit.txt; then
          	echo "GitHub and Gerrit do not agree on the list of tags!"
          	echo "Did you forget about refs/attic branches? https://github.com/cue-lang/cue/wiki/Notes-for-project-maintainers"
          	exit 1
          fi
      - if: (matrix.go-version == '1.26.x' && matrix.runner == 'namespace-profile-linux-amd64-large')
        name: Generate
        run: go generate ./...
      - if: always()
        name: Check that git is clean at the end of the job
        run: test -z "$(git status --porcelain)" || (git status; git diff; false)
