<commit_before># How to Contribute

## Test Cloud Run Button's Underlying Command Locally with Local Go

1. Download Go 1.14.x
1. Run the tests:
    ```
    go test ./cmd/cloudshell_open
    ```
1. Build the command:
    ```
    go build -o /tmp/cloudshell_open ./cmd/cloudshell_open
    ```
1. To test the command:
    1. [Enable the cloudresourcemanager API](https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview)
    1. [Enable the billing API](https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview)
    1. Create a Service Account with the *Cloud Run Admin*, *Service Usage Consumer*, *Service Account User*, and *Storage Admin* roles
    1. Download the JSON key
    1. Authenticate gcloud as the service account:
        ```
        export GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_YOUR_SERVICE_ACCOUNT_KEY_FILE
        gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
        export TRUSTED_ENVIRONMENT=true
        export SKIP_CLONE_REPORTING=true
        ```
    1. Run the button:
        ```
        (cd /tmp; rm -rf cloud-run-hello; ./cloudshell_open --repo_url=https://github.com/GoogleCloudPlatform/cloud-run-hello.git; rm -rf cloud-run-hello)
        ```
        Other `cloudshell_open` flags: `--git_branch`, `--dir`, `--context`

        Env vars you can set to avoid STDIN questions: `GOOGLE_CLOUD_PROJECT` `GOOGLE_CLOUD_REGION`

## Test Cloud Run Button's Underlying Command Locally in a Container

1. [Create a Service Account in a test account](https://console.cloud.google.com/iam-admin/serviceaccounts)
1. Download the key json file for the new service account
1. Build the Container

    ```
    docker build -f Dockerfile -t cloud-run-button .
    ```

1. Set an env var pointing to the Service Account's JSON file:

    ```
    export KEY_FILE=PATH_TO_YOUR_SERVICE_ACCOUNT_KEY_FILE
    ```

1. Run Cloud Run Button via Docker:
    ```<commit_msg>Update CONTIRBUTING.md based on troubleshooting (#229)<commit_after># How to Contribute

## Test Cloud Run Button's Underlying Command Locally with Local Go

1. Download Go 1.14 (see [`Dockerfile`](Dockerfile) for the exact version used)
1. Run the tests:
    ```
    go test ./cmd/cloudshell_open
    ```
1. Build the command:
    ```
    go build -o /tmp/cloudshell_open ./cmd/cloudshell_open
    ```
1. To test the command:
    1. [Enable the cloudresourcemanager API](https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview)
    1. [Enable the billing API](https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview)
    1. Create a Service Account with the following roles:
        * Cloud Run Admin (`roles/run.admin`), 
        * Service Usage Admin (`roles/serviceusage.serviceUsageAdmin`), 
        * Service Account User (`roles/iam.serviceAccountUser`), and
        * Storage Admin (`roles/storage.admin`).
    1. [Download the Service Account key as a JSON file](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating)
    1. Authenticate gcloud as the service account:
        ```
        export GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_YOUR_SERVICE_ACCOUNT_KEY_FILE
        gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
        export TRUSTED_ENVIRONMENT=true
        export SKIP_CLONE_REPORTING=true
        ```
    1. Run the button:
        ```
        (cd /tmp; rm -rf cloud-run-hello; ./cloudshell_open --repo_url=https://github.com/GoogleCloudPlatform/cloud-run-hello.git; rm -rf cloud-run-hello)
        ```
        Other `cloudshell_open` flags: `--git_branch`, `--dir`, `--context`

        Optionally, you can set to `GOOGLE_CLOUD_PROJECT` `GOOGLE_CLOUD_REGION` to avoid being prompted for these.

## Test Cloud Run Button's Underlying Command Locally in a Container

⚠️ This will download very large Docker images to your system.

1. [Create a Service Account in a test account](https://console.cloud.google.com/iam-admin/serviceaccounts)
1. Download the key json file for the new service account
1. Build the Container

    ```
    docker build -f Dockerfile -t cloud-run-button .
    ```

1. Set an env var pointing to the Service Account's JSON file:

    ```
    export KEY_FILE=PATH_TO_YOUR_SERVICE_ACCOUNT_KEY_FILE
    ```

1. Run Cloud Run Button via Docker:
    ```
{'fraction_non_alphanumeric': 0.10487916096671226, 'fraction_numerical': 0.008891928864569083, 'mean_word_length': 3.296767874632713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4636975', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1329, 'n_words': 401}