Skip to content

If‑and‑Needs Example #8

If‑and‑Needs Example

If‑and‑Needs Example #8

Workflow file for this run

name: If‑and‑Needs Example
# Trigger on both pushes and PRs
on:
workflow_dispatch:
env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
jobs:
build:
# ─────────── Server‑side job IF ───────────
# Only queue 'build' when on 'main' branch
if: github.ref == 'refs/heads/master'
runs-on: self-hosted
steps:
- name: sleep
run: sleep 60
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
# ───────── Runner‑side step IF ─────────
# Only run tests when the actor is 'octocat'
- id: run-tests
name: Run tests
run: npm test
if: github.actor == 'octocat'
# Always upload logs, even if tests fail or are skipped
- name: Upload logs
if: exec('ls -l')

Check failure on line 38 in .github/workflows/if_test.yml

View workflow run for this annotation

GitHub Actions / If‑and‑Needs Example

Invalid workflow file

The workflow is not valid. .github/workflows/if_test.yml (Line: 38, Col: 13): Unrecognized function: 'exec'. Located at position 1 within expression: exec('ls -l')
run: echo "Uploading build logs..."
deploy:
# ─────────── Job dependency (needs) ───────────
needs: build
# Server‑side IF: only deploy when 'build' succeeded
if: needs.build.result == 'success'
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
# Runner‑side step IF: only on push events (not PRs)
- name: Deploy to Production
run: echo "Deploying to production environment..."
if: github.event_name == 'push'