Script
You can use script trigger simply to write a script for a custom trigger logic.
Usage
on:script:run: |const result = await helpers.axios.get("https://jsonplaceholder.typicode.com/posts")return result.datadeduplicationKey: id
Or, you can use a path to run the external script. For example,
on:script:path: ./workflows/script.js
Use a relative path based on your project root directory.
Options
run, optional, the script code, you must providerrunorpathat least. you should use javascript language for the script. The context you can use at the script, see here, for example,let items = [];if (options.param1) {items.push({id: "param1",title: "title1",});}return items;path, optional, you can run script from an external file. For example,path: ./script.js, thescript.jsshould export following function:module.exports = async function ({ helpers }) {const result = await helpers.axios.get("https://jsonplaceholder.typicode.com/posts");return result.data;};The context you can use is the same as
run, see herededuplicationKey, optional. The poll trigger deduplicates the array we see each poll against the id key. If the id key does not exist, you should specify an alternative unique key to deduplicate, you can use path format, like:id,data.id,item.data.key, If neither are supplied, we fallback to looking forkey, if neither are supplied, we will hash the item, and generate a unique key
Context
You can use the following context at your script code:
helpers, The Actionsflow triggers general helpers, which hascache,log, etc... You can see all helpers methods at hereoptions, the options you pass it toscripttriggergithub, Apre-authenticatedoctokit/rest.js client, Note, if use github you must providegithub_tokenparams, for example, `githubon:script:github_token: ${{secrets.GITHUB_TOKEN}}run: |const results = await github.issues.listForRepo({owner:"actionsflow",repo:"actionsflow",});return results.data;require, you can userequireto require thejsmodule. Be care for, you should use an absolute path to require the specific js file.on:script:github_token: ${{secrets.GITHUB_TOKEN}}run: |const script = require(`${process.env.GITHUB_WORKSPACE}/path/xx.js`);const items = await script({helpers,options,});return items;
You can use General Config for Actionsflow Trigger for more customization.
Outputs
Script trigger's outputs will be the item of the script function results.
An outputs example:
{"id": 1,"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"}
You can use the outputs like this:
on:script:run: |const result = await helpers.axios.get("https://jsonplaceholder.typicode.com/posts")return result.datadeduplicationKey: idjobs:print:name: Printruns-on: ubuntu-lateststeps:- name: Print Outputsenv:title: ${{on.script.outputs.title}}run: |echo title: $title