Today, we are excited to announce the release of Activity Scripts.
Activity Scripts are custom pieces of JavaScript code that are added to your Platform.sh project via a single API call or CLI command.
Activity Scripts allow your Platform.sh projects to:
- Interact with third-party services (Slack, Twilio, PagerDuty, Jira, you-name-it)
- Automate complex tasks when an activity is triggered or has completed
- Set up custom notifications, alerts, or reminders
- Be compliant across your fleet of sites by ensuring that all your projects are using the latest supported services and runtimes
- And so much more. The only limit is your imagination.
Behind the scenes
Platform.sh is built around the concept of “activities.” Any action or event will trigger one or more "activities," which you can then use to trigger your custom Activity Scripts.
For example, pushing code to a branch will trigger an environment.push
activity, followed by an environment.redeploy
activity. You can write an activity script that is prompted by these triggers to post a Slack notification that the environment was successfully deployed. (You can find a ready-to-use example of this activity script on our documentation site. Use it as a starting point for developing your own!)
Activity Scripts generate activities as well, which makes it extremely easy to troubleshoot when debugging your script or to extend the capabilities of your script.
Activity Scripts live within your Platform.sh project, so there is no need to host it or run it anywhere else.
Decision-making activities
Every time your script gets fired, it has in its context the activity
object. This object carries a wealth of information that you can use to make decisions.
For example, on a deployment you could inspect activity.payload.deployment.environment_info.is_production
and define behaviours that vary based on the environment type. Or you could look at activity.payload.deployment.environment_info.http_access
and send a nastygram to anyone that turned off authentication on a development environment.
Read more about Activity API and about how to use Activity Scripts on our documentation site.
Share your scripts
Now that they’re available, what activity scripts will you build? One that sends a PagerDuty notification when a deployment fails on your master environment? Or tweets every time you deploy to production on Friday? Or even updates your CDN configuration when the domain information on your project changes?
Whatever you’re inspired to build, we hope you’ll share it with the Platform.sh community. Upload your scripts, ideas, recipes, and other utilities to the activity script section of our community site.
We can’t wait to see what you come up with!