clasp: Clasp deploy doesn't update the deployed version with Google Apps Script Web App

Expected Behavior

Perhaps I’m misunderstanding, but from the readme I’d thought that clasp deploy would allow me to publish a new version of a Web App (in this case bound to a google sheet).

I’d expected the workflow to be as follows:

  1. clasp version “My new version”

Created version xx.

  1. clasp deploy xx

yyyyyyyyyyyyyyyyy @xx

  1. clasp open browser opens to newly published version “xx”

Actual Behaviour

The version is created as expected, but the web app Project Version remains at the last deployed version not the version used with clasp deploy. To actually deploy it I have to go into the Script Editor then Publish > Deploy as Web App and then select the version “xx”

Related Issues

This seems related to https://github.com/google/clasp/issues/43, however that issue specifically relates to Chrome store apps and this is a Web App which the comments on that issue suggest should be supported.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 14
  • Comments: 40 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Summarizing:

  1. There is a difference between version and deployment. A version is similar to a git tag, while a deployment is actual code available for execution and accessible at https://script.google.com/macros/s/{deploymentID}/exec
  2. list of available deployments can be obtained by running clasp deployments
  3. there is always only one published deployment which is available for end-users. The published deployment is is flagged as web app meta-version in the list of deployments.
  4. clasp deploy creates new deployment if no deploymentId is specified and creates new version if no version is specified
  5. new deployments are useful for testing before making them default (using link mentioned in point 1)
  6. in order to make version available for end-users you have to publish it by deploying it into published deployment by running
    clasp --deploymentId {published_deployment_id} --version {selected_version_here}

So the process:

  1. use clasp deployments and
    1. select one deployment you will use for testing => test_deployment_id
    2. get published deployment (one having web app meta-version flag) => pub_deployment_id
  2. modify your code
  3. clasp push
  4. clasp deploy --deploymentId $test_deployment_id creates version => new_version
  5. test your version at
    https://script.google.com/macros/s/{test_deployment_id}/exec
  6. if satisfied, deploy your version into published deployment
    clasp deploy --deploymentId $pub_deployment_id --versionNumber $new_version

So, in the end it looks that clasp deploy works as designed. What’s missing is the documentation 😃

I found this trick working for deploy a new version of webapp.

clasp deployments

  • Select the version (if exists ) where there is web app meta-version attribute
  • I attribute is not found, use the last deployment id
LAST_DEPLOYMENT_ID=$( clasp deployments | pcregrep -o1 '\- ([A-Za-z0-9\-\_]+) @\d+ - web app meta-version' )
	if [ -z "$LAST_DEPLOYMENT_ID" ]
	then
		LAST_DEPLOYMENT_ID=$( clasp deployments | tail -1 | pcregrep -o1 '\- ([A-Za-z0-9\-\_]+)' ) 
	fi

After selecting deploment ID, proceed with

clasp deploy --deploymentId $LAST_DEPLOYMENT_ID

I found that web app meta-version attribute only appaers when web-app application is update from AppsScript code editor, so we need to consider the deploymentIDs order to get the proper version. Also the webapp should remain published to last existing version or the “select last row” trick will not work.

I tried a couple of times and seems to work, you can try and test as well.

I’m developing an API executable, and encountered a similar issue.

I can create deployments via clasp, but I can’t run these deployed API until I manually update the version via web console.

image

(new deployments exist, but not selected.)

image

Are there ways to update the published version via clasp?

It looks like the script.google.com UI updates the manifest file (appsscript.json) file when you use the UI to publish a web app.

When you use the UI to deploy a web app, it adds this bit of code to appsscript.json:

  "webapp": {
    "access": "MYSELF",
    "executeAs": "USER_DEPLOYING"
  }

This is really important, as it’s the configuration details of the web app.

So if you are using clasp, and expect to deploy a web app, you must manually update the manifest file.

Repro

Create the project with clasp

  1. clasp create
  2. clasp open
  3. View > Show manifest file
  4. Observe the manifest is updated
{
  "timeZone": "America/New_York",
  "dependencies": {
  },
  "webapp": {
    "access": "MYSELF",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER"
}

Setup other web app files

index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    hi
  </body>
</html>

test.gs

function doGet() {
    return HtmlService
      .createTemplateFromFile('index')
      .evaluate();
}
  1. clasp push
  2. clasp deploy
    1. Copy the long id
  3. Go to the URL, it should be something like this: https://script.google.com/a/{DOMAIN}/macros/s/{VERSION_ID}/exec
  4. See the successful deployment of a web app.

Follow-up

Good news (if this is correct): clasp isn’t doing anything wrong. Bad news: It’s really not obvious why creating a web app with clasp fails.

I think a good solution would be to enhance the setup experience around starting a new add-on/web app/script. Some ideas were thrown around in #76, but it seemed out of scope for the clasp project.

We should at least give README tips on how to start with creating the 3 types of scripts to prevent this error.

It seems that clasp deploy a new deployment ID when not specified deployment ID with -i parameter. So if your just updating a web app using latest code, just get url from apps script website which like this https://script.google.com/macros/s/{deploymentID}/exec and specify -i parameter with deploymentID when new code deploy example command: clasp push && clasp deploy -i deploymentID

I don’t think adding more CLI flags to clasp will help. clasp should work out of the box. A type should really be for create.

clasp create
What type of project do you want to create?
x Standalone
- Add-on
- Web App

# Advanced way
clasp create --type standalone
clasp create --type addon --docs
clasp create --type webapp

What we really need is more of the following:

  • Warn when clasp push would override files. This is probably what happened here with the appsscript.json being overwritten.
  • Improve clasp create to provide options for creating an add-on, executable, or web app. See above.
  • Improve the process of creating a manifest. It would be great if there was autocompletion support. This is like package.json for Node modules.

FYI: clasp redeploy has been removed in favor of clasp deploy with -- arguments.

So I’ve just tested that workflow and it does push the deployment up (which was working originally as well) - but it also doesn’t make it active as the published project version.

Meaning that you still need to go to the UI and make the project version the one you just deployed 😦

I added the API support label because it looks like the UI does something different the API cannot do yet.

Is it possible, and/or a good idea to have some sort of flag for clasp deploy like --type (web|api) that adds that to the appsscript.json for the user?

Apparently, when we execute clasp deploy, the command forgets to create an entry point to the webapp. See below:

Entry points after deploying from clasp:

    {
      "deploymentId": "AKfycbwGoFhpo5qekznUEn9z4Crt9BtFz0ubDsjK9sNlcJz0xTroscdU",
      "deploymentConfig": {
        "scriptId": "1jeLVzVdwPdBX5prcwCUeTc4nkQ8XAxFSd7QcuJJ96MB_UozF0iUMShiO",
        "versionNumber": 251,
        "manifestFileName": "appsscript",
        "description": "web app meta-version"
      },
      "updateTime": "2020-06-23T08:08:57.828Z",
      "entryPoints": [
        {
          "entryPointType": "EXECUTION_API",
          "executionApi": {
            "entryPointConfig": {
              "access": "ANYONE"
            }
          }
        }
      ]
    }

Entry points after deploying from the Script Editor:

{
      "deploymentId": "AKfycbwGoFhpo5qekznUEn9z4Crt9BtFz0ubDsjK9sNlcJz0xTroscdU",
      "deploymentConfig": {
        "scriptId": "1jeLVzVdwPdBX5prcwCUeTc4nkQ8XAxFSd7QcuJJ96MB_UozF0iUMShiO",
        "versionNumber": 251,
        "manifestFileName": "appsscript",
        "description": "web app meta-version"
      },
      "updateTime": "2020-06-23T08:10:12.540Z",
      "entryPoints": [
        {
          "entryPointType": "WEB_APP",
          "webApp": {
            "url": "https://script.google.com/macros/s/AKfycbwGoFhpo5qekznUEn9z4Crt9BtFz0ubDsjK9sNlcJz0xTroscdU/exec",
            "entryPointConfig": {
              "access": "ANYONE_ANONYMOUS",
              "executeAs": "USER_DEPLOYING"
            }
          }
        },
        {
          "entryPointType": "EXECUTION_API",
          "executionApi": {
            "entryPointConfig": {
              "access": "ANYONE"
            }
          }
        }
      ]
    }

This is why we get a Drive Error when, after deploy from clasp, we try to enter the /dev page.

referenced here: https://github.com/googleapis/google-api-python-client/issues/866

I think you want to redeploy to update a deployment: clasp redeploy <deploymentId> <version> <description> Is that right?

I think I forgot to add it in the “How To…” section. LMK if that works.

C:\Users\Freddy\Desktop\gmail add-on  (meeting-assistant@1.0.0)
λ clasp redeploy AKfycbzwBPYA5QYbALsLecxp5_OuOxCrbBKzs78D8XDs9m3kDg2DSvCG-fyNG82ssSoOSDM7gg 1 Test
🤔  Unknown command "clasp redeploy"

Forgot clasp commands? Get help:
  clasp --help

Also note that when you manually deploy as a web app your project (using the “Deploy as web app” menu entry), it automatically generates a new deployment (or update the existing deployment if you update your web app). This specific deployment is automatically named by Apps Script “web app meta-version”, you can grab its ID and then reuse it to update this specific deployment with Clasp. This way, the UI will stay in sync, meaning you will be able to deploy either manually (using the “Deploy as web app” menu entry) or programmatically.

I found out the way to update the published web app endpoint by clasp.

We should use redeploy to update exists application ( I think we expect it is “deploy” and confusing ).

The function clasp deploy wraps create deployments API, and it always create new endpoints. https://developers.google.com/apps-script/api/reference/rest/v1/projects.deployments/create

We just need

@grant can you shade some light on where we are with this issue? I would LOVE to be able to deploy a new web-app version when I push my updates. I dislike having to need to go to the WEB UI to deploy that new version of my web-app.

When i use: clasp redeploy <id of deployment> <version> <description> I get “Updated deployment” in my terminal

But, when i refresh the web browser (F5) i get an error message “Se necesita autorización para realizar esta acción” (You need authorization to perform this action) in the browser.

Also, my previous config was: Deploy as a web app Execute the app: As me Who has access to the app: Anyone, even anonymous

How to send this two config options with a command, and how to solve my issue with the authorization?