import { Step } from "https://deno.land/x/actionify@0.3.0/mod.ts";
You can use the if
conditional to prevent a job from running unless a
condition is met. You can use any supported context and expression to
create a conditional.
When you use expressions in an if conditional, you may omit the expression syntax (${{ }}) because GitHub automatically evaluates the if conditional as an expression. For more information, see "Expressions."
Using contexts
This step only runs when the event type is a pull_request and the event action is unassigned.
import { Step, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';
const step = Step
.untyped()
.name('My first step')
.if(ctx => e.op(
e.op(ctx.github.event_name, '==', 'pull_request'),
'&&',
e.op(ctx.github.action, '==', 'unassigned')
))
.run('echo This event is a pull request that had an assignee removed');
Using status check functions
The my backup step only runs when the previous step of a job fails.
import { Job, e, Step } from 'https://deno.land/x/actionify@0.3.0/mod.ts';
const usesStep = Step
.create()
.uses('octo-org/action-name');
const conditionalStep = Step
.create()
.if(e.failure())
.uses('actions/heroku@1.0.0');
const job = Job
.create()
.step(usesStep)
.step(conditionalStep);
Using secrets
Secrets cannot be directly referenced in if: conditionals. Instead, consider setting secrets as job-level environment variables, then referencing the environment variables to conditionally run steps in the job.
If a secret has not been set, the return value of an expression referencing the secret (such as ${{ secrets.SuperSecret }} in the example) will be an empty string.
import { Workflow, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';
const workflow = Workflow
.create({ name: "ci", fileName: "ci" })
.on('push')
.job('myJobName', job => job
.env({ SUPER_SECRET: e.expr(e.ctx.secrets.SUPER_SECRET) })
.step(step => step
.if(ctx => e.op(ctx.env.SUPER_SECRET, '!=', ''))
.run('echo "This step will only run if the secret has a value set."')
)
.step(step => step
.if(ctx => e.op(ctx.env.SUPER_SECRET, '==', ''))
.run('echo "This step will only run if the secret does not have a value set."')
)
);