apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  generateName: step-script-
spec:
  taskSpec:
    inputs:
      params:
      - name: PARAM
        default: param-value

    steps:
    - name: noshebang
      image: public.ecr.aws/ubuntu/ubuntu:latest
      script: echo "no shebang"
    - name: bash
      image: public.ecr.aws/ubuntu/ubuntu:latest
      env:
      - name: FOO
        value: foooooooo
      # Test that Pods with containers run as different UIDs
      # are able to run scripts regardless of any specific
      # Step's UID.
      securityContext:
        runAsUser: 2000
      script: |
        #!/usr/bin/env bash
        set -euxo pipefail
        echo "Hello from Bash!"
        echo FOO is ${FOO}
        echo substring is ${FOO:2:4}
        for i in {1..10}; do
          echo line $i
        done

    - name: place-file
      image: public.ecr.aws/ubuntu/ubuntu:latest
      securityContext:
        runAsUser: 8000
      script: |
        #!/usr/bin/env bash
        echo "echo Hello from script file" > /workspace/hello
        chmod +x /workspace/hello
    - name: run-file
      image: public.ecr.aws/ubuntu/ubuntu:latest
      script: |
        #!/usr/bin/env bash
        /workspace/hello

    - name: contains-eof
      image: public.ecr.aws/ubuntu/ubuntu:latest
      securityContext:
        runAsUser: 16000
      workingDir: /workspace
      script: |
        #!/usr/bin/env bash
        cat > file << EOF
        this file has some contents
        EOF
        cat file

    - name: node
      image: node
      script: |
        #!/usr/bin/env node
        console.log("Hello from Node!")

    - name: python
      image: python
      script: |
        #!/usr/bin/env python3
        print("Hello from Python!")

    - name: perl
      image: perl
      script: |
        #!/usr/bin/perl
        print "Hello from Perl!"

    # Test that param values are replaced.
    - name: params-applied
      image: python
      script: |
        #!/usr/bin/env python3
        v = '$(inputs.params.PARAM)'
        if v != 'param-value':
          print('Param values not applied')
          print('Got: ', v)
          exit(1)

    # Test that args are allowed and passed to the script as expected.
    - name: args-allowed
      image: public.ecr.aws/ubuntu/ubuntu:latest
      args: ['hello', 'world']
      script: |
        #!/usr/bin/env bash
        [[ $# == 2 ]]
        [[ $1 == "hello" ]]
        [[ $2 == "world" ]]
