If‑and‑Needs Example #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ${{ ls -l }} | ||
Check failure on line 38 in .github/workflows/if_test.yml
|
||
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' |