Got some static files? Travis CI can deploy your static files to Surge.sh after a successful build. Builds triggered from Pull Requests will never trigger a deploy, let’s see how we can make this happen.
There will be to
env vars you will need to add to Travis:
SURGE_LOGIN: Set it to the email address you use with Surge
SURGE_TOKEN: Set it to your login token (get it by doing a surge token)
You’ll want to add surge as deployment provider in
.travis.yml. If your project folder is not the repo root you can set the deploy option project to define a path relative to repo root to deploy. If you do not have a CNAME file with the name of the domain to publish to you can set the deploy option domain with the domain to deploy to, so for example:
deploy: provider: surge project: ./static/ domain: example.surge.sh
It is suggested that you generate your files during the script step or the before_deploy step.
When generating files during the script step, an error results in a failed build, or when generating files during the before_deploy step, an error does not result in a failed build.
By default, Travis CI will only deploy from your master branch. You can specify what branch to deploy from with the deploy option on:
deploy: on: branch: myProductionBranch
To deploy from all branches set the deploy->on option all_branches to true:
deploy: on: all_branches: true
That’s it you now know how to deploy to Surge using Travis. As always if you have any questions please reach out to me at [email protected] and I’ll help you through this if you need it.