travis-ci / dpl

Dpl (dee-pee-ell) is a deploy tool made for continuous deployment.
MIT License
1.29k stars 367 forks source link

Netlify: add --json flag for deploy and save to environment variable #1206

Closed JakubKoralewski closed 3 years ago

JakubKoralewski commented 4 years ago

Feature request

I propose to add to the existing netlify deploy configuration the boolean field json:

deploy:
  - provider: netlify
    cleanup: false
    dir: <PATH_TO_OUT>
    site: <SITE_ID>
    message: Travis-CI $TRAVIS_JOB_NUMBER $TRAVIS_JOB_WEB_URL
    edge: true
    json: true

With this json field set to true the netlify deploy command should add a --json flag, which returns the following data:

$ netlify deploy --json
{
  "site_id": "SITE_ID",
  "site_name": "SITE_NAME",
  "deploy_id": "DEPLOY_ID",
  "deploy_url": "DEPLOY_URL",
  "logs": "LOGS_URL"
}

The output of the above command should be saved to an environment variable that should be accessible in the after_deploy step. Given there could be multiple Netlify website deploys in a single run I propose for the environment variable to be tied to the site_id, so that multiple deploys can be accessed independently without one overwriting the other.

For example, given the Netlify site_id of 1234 the environment variable should be called NETLIFY_DEPLOY_ID_1234.

This will work, because for the deploy to even happen one has to either set the NETLIFY_SITE environment variable, or set it in .travis.yml or in .netlify/state.json in the siteId property; therefore, the site_id is always known to the user.

The output could be parsed and be output as multiple environment variables, e.g.: NETLIFY_DEPLOY_ID_1234_SITE_ID, but I would be against this approach, and instead I'd let the user parse the output themselves using jq. This would be easier to implement, and would be one thing less that would have to be updated with each change of the command's output.

Motivation

This would allow not setting the --prod flag during Netlify deployment, and instead I could access the deploy_id inside the after_deploy step, then send a notification (whether it would be an email, push notification or slack message) for the admin to confirm the deployment (by using the API restore functionality), view the deployment (using the deploy_url property) etc.

I like to take a try to implement things myself when I can, but unfortunately I do not know Ruby.

stale[bot] commented 4 years ago

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please do feel free to either reopen this issue or open a new one. We'll gladly take a look again! You can read more here: https://blog.travis-ci.com/2018-03-09-closing-old-issues