Skip to content

Instantly share code, notes, and snippets.

@shedd
Last active October 30, 2018 16:59
Show Gist options
  • Save shedd/7af44db05044aa41694b0b5c60bbe886 to your computer and use it in GitHub Desktop.
Save shedd/7af44db05044aa41694b0b5c60bbe886 to your computer and use it in GitHub Desktop.
A simple pattern for pushing production builds live on Netlify when your CI build passes.

Pre-reqs

====

CI Pattern

< run tests >

< if fail, do nothing - site remains locked on working version >

< if pass && branch==master, run the following: >

    # capture latest deploy id from successful builds of the master branch
    deploy_id=`curl -s https://api.netlify.com/api/v1/sites/<PRODUCTION SITE ID>/deploys/deploys?page=1&per_page=15&branch=master&match=true -H "Authorization: Bearer <TOKEN>" | ./node_modules/node-jq/bin/jq -r 'map(select(.state | contains("ready"))) | .[0].id'`

    # publish the latest deploy
    curl -s "https://api.netlify.com/api/v1/sites/<production site id>/deploys/$deploy_id/restore" -X POST -d "" -H "Authorization: Bearer <TOKEN>"

    # lock the latest deploy
    curl -s "https://api.netlify.com/api/v1/deploys/$deploy_id/lock" -X POST -d "" -H "Authorization: Bearer <TOKEN>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment