|  | 
|  | 1 | +# Schema: https://json.schemastore.org/github-action.json | 
|  | 2 | + | 
|  | 3 | +name: Test Runner | 
|  | 4 | +description: Prepare and run tests for this repository | 
|  | 5 | + | 
|  | 6 | +inputs: | 
|  | 7 | +  crdb: | 
|  | 8 | +    description: "CockroachDB version" | 
|  | 9 | +    required: true | 
|  | 10 | +  ruby: | 
|  | 11 | +    description: "Ruby version" | 
|  | 12 | +    required: true | 
|  | 13 | +  TESTOPTS: | 
|  | 14 | +    description: "Rails Minitest options" | 
|  | 15 | +    default: "--profile=5" | 
|  | 16 | +runs: | 
|  | 17 | +  using: composite | 
|  | 18 | +  steps: | 
|  | 19 | +    - name: Install GEOS | 
|  | 20 | +      shell: bash | 
|  | 21 | +      run: sudo apt-get install -yqq libgeos-dev | 
|  | 22 | +    - name: Set Up Ruby | 
|  | 23 | +      uses: ruby/setup-ruby@v1 | 
|  | 24 | +      with: | 
|  | 25 | +        ruby-version: ${{ inputs.ruby }} | 
|  | 26 | +        bundler-cache: true | 
|  | 27 | +    - name: Show Rails version | 
|  | 28 | +      shell: bash | 
|  | 29 | +      run: bundle info rails | 
|  | 30 | +    - name: Install and Start Cockroachdb | 
|  | 31 | +      shell: bash | 
|  | 32 | +      run: | | 
|  | 33 | +        # Download CockroachDB | 
|  | 34 | +        readonly full_version=$(ruby -rnet/http -ruri -ryaml -e ' | 
|  | 35 | +          link = "https://raw.githubusercontent.com/cockroachdb/docs/main/src/current/_data/releases.yml" | 
|  | 36 | +          puts YAML.safe_load(Net::HTTP.get(URI(link))).reverse.find { | 
|  | 37 | +            _1["major_version"] == "${{ inputs.crdb }}" && | 
|  | 38 | +              _1["release_type"] == "Production" && | 
|  | 39 | +              !_1["cloud_only"] && | 
|  | 40 | +              !_1["withdrawn"] && | 
|  | 41 | +              !_1["release_name"].include?("-") # Pre-release | 
|  | 42 | +          }["release_name"] | 
|  | 43 | +        ') | 
|  | 44 | +
 | 
|  | 45 | +        echo "Downloading $full_version..." | 
|  | 46 | +        wget -qO- "https://binaries.cockroachdb.com/cockroach-$full_version.linux-amd64.tgz" | tar xvz | 
|  | 47 | +
 | 
|  | 48 | +        export PATH=./cockroach-$full_version.linux-amd64/:$PATH | 
|  | 49 | +        readonly urlfile=cockroach-url | 
|  | 50 | +
 | 
|  | 51 | +        # Start a CockroachDB server and wait for it to become ready. | 
|  | 52 | +        rm -f "$urlfile" | 
|  | 53 | +        rm -rf cockroach-data | 
|  | 54 | +        # Start CockroachDB. | 
|  | 55 | +        cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-$full_version.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 & | 
|  | 56 | +        # Ensure CockroachDB is stopped on script exit. | 
|  | 57 | +        # Wait until CockroachDB has started. | 
|  | 58 | +        for i in {0..3}; do | 
|  | 59 | +          [[ -f "$urlfile" ]] && break | 
|  | 60 | +          backoff=$((2 ** i)) | 
|  | 61 | +          echo "server not yet available; sleeping for $backoff seconds" | 
|  | 62 | +          sleep $backoff | 
|  | 63 | +        done | 
|  | 64 | +        cat ${{ github.workspace }}/setup.sql | cockroach sql --insecure | 
|  | 65 | +    - name: Test | 
|  | 66 | +      shell: bash | 
|  | 67 | +      run: bundle exec rake test | 
|  | 68 | +      env: | 
|  | 69 | +        TESTOPTS: "${{ inputs.TESTOPTS }}" # Fail fast allows us to find easy local reproduction by isolating quickly failing jobs. | 
|  | 70 | +        RAILS_MINITEST_PLUGIN: "1" # Make sure that we use the minitest plugin for profiling. | 
0 commit comments