> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo GitHub Actions

> Overview of GitHub Actions workflows, triggers, and a sample validation job checking for a required file on push and pull request

GitHub Actions is GitHub’s built-in automation platform that runs workflows defined in your repository. Workflows are YAML files that describe when the automation should run (triggers) and what steps to execute (jobs and steps). Typical uses include testing, building, and deploying code whenever something changes in your repo.

Workflows are event-driven: GitHub fires events (pushes, pull requests, scheduled timers, manual triggers, and many others), and your workflows respond to those events.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-events-trigger-workflows-screenshot.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=5879ecf85134d30b0e83a02b93230a51" alt="This is a screenshot of a GitHub documentation page titled &#x22;Events that trigger workflows,&#x22; detailing how workflows can be configured to run on specific activities within GitHub. There is a menu on the right listing various event types." width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-events-trigger-workflows-screenshot.jpg" />
</Frame>

## Common triggers

* `push` — run when commits are pushed to branches or tags.
* `pull_request` — run when a pull request is opened, synchronized, or updated.
* `schedule` — run at regular intervals using cron syntax.
* `workflow_dispatch` — expose a manual run button in the Actions UI.
* Many repository events (assigned, labeled, opened, etc.) can also trigger workflows.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-workflows-push-event-documentation.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=fa5cb22d9225700649c15b747123a9e4" alt="The image shows a GitHub documentation page describing events that trigger workflows, specifically detailing the &#x22;push&#x22; event including its payload and activity types. The sidebar displays a list of various event options." width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-workflows-push-event-documentation.jpg" />
</Frame>

You can combine triggers so a single workflow runs on multiple events. For recurring runs, the `schedule` trigger uses cron syntax. For manual runs from the repository UI, enable `workflow_dispatch`:

```yaml theme={null}
on: workflow_dispatch
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-docs-workflows-pull-requests.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=55d674fe06efdf5088333582f00c0921" alt="The image is a screenshot from GitHub Docs showing the &#x22;Events that trigger workflows&#x22; page, focusing on pull request event payload and activity types such as &#x22;assigned,&#x22; &#x22;unassigned,&#x22; &#x22;labeled,&#x22; etc." width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-docs-workflows-pull-requests.jpg" />
</Frame>

## Example: verify a required file on push and PR

This example creates a lightweight workflow that runs on pushes and pull requests targeting the `main` branch. It performs a simple check: confirm that `index.html` exists at the repository root. If the file is missing, the job fails.

Create a file at `.github/workflows/<name>.yml` with the following content:

```yaml theme={null}
name: Game Quality Check

# Trigger on pushes and pull requests targeting main
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  # Optionally allow manual runs from the UI
  workflow_dispatch:

jobs:
  lint-and-test:
    runs-on: ubuntu-latest
    steps:
      # Step 1: Checkout the repository so the runner has access to files
      - name: Checkout Repository
        uses: actions/checkout@v4

      # Step 2: Simple validation: ensure index.html exists at repo root
      - name: Verify Core Files
        run: |
          if [ -f "index.html" ]; then
            echo "✔ index.html found. Ready for launch!"
          else
            echo "✖ index.html is missing! Game will not load."
            exit 1
          fi
```

<Callout icon="lightbulb" color="#1CB2FE">
  Place this file under `.github/workflows/` and commit to the default branch (for example, `main`). Any push or pull request that targets `main` will trigger the workflow automatically.
</Callout>

When GitHub Pages is enabled for a repository, GitHub itself runs an internal workflow to build and deploy your site. That same Actions framework is what your custom workflows use — you can see build and deployment jobs, logs, and statuses in the Actions UI.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-pages-build-successful.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=298b0ced51bfa2dc2d9bb68a53d4600e" alt="The image shows a GitHub Actions page displaying the status of a workflow run called &#x22;pages build and deployment,&#x22; which is successful." width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-pages-build-successful.jpg" />
</Frame>

You can inspect workflow runs, job decomposition, and logs to troubleshoot or validate behavior. For example, the Pages workflow often runs multiple jobs (build, report status, deploy), which you can expand and view details for.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-pages-build-deployment.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=b98d79b895c4d4f2bbd97cbeacd0afef" alt="The image shows a GitHub Actions workflow summary for &#x22;pages build and deployment.&#x22; The workflow has successfully completed with three jobs: &#x22;build,&#x22; &#x22;report-build-status,&#x22; and &#x22;deploy.&#x22;" width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-pages-build-deployment.jpg" />
</Frame>

Once your workflow file is committed to `main`, the Actions tab will show runs for each push and PR targeting that branch. Click a run to view runner provisioning and logs for each step. Typical checkout-related log lines look like:

```bash theme={null}
/usr/bin/git config --global --add safe.directory /home/runner/work/block-buster/block-buster
/usr/bin/git config --local --unset-all extensions.worktreeConfig
/usr/bin/git log -1 --format=%H
22395540d73abadf9b9e13a991b29aa5988c
```

The shell step that verifies `index.html` will echo success or print an error and exit with a non-zero code to fail the job:

```bash theme={null}
if [ -f "index.html" ]; then
    echo "💻 index.html found. Ready for launch!"
else
    echo "❌ index.html is missing! Game will not load."
    exit 1
fi
# shell: /usr/bin/bash -e {0}
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/1W0Ytfcz_GRwDXc0/images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-block-buster-workflows.jpg?fit=max&auto=format&n=1W0Ytfcz_GRwDXc0&q=85&s=bec655a76e27c22d75060f3e03d5be7e" alt="The image shows a GitHub Actions page displaying workflow runs for a repository named &#x22;block-buster&#x22; with workflows such as &#x22;Create code-check.yml&#x22; and &#x22;pages build and deployment&#x22;." width="1920" height="1080" data-path="images/GitHub-Foundations-Certification/GitHub-Actions/Demo-GitHub-Actions/github-actions-block-buster-workflows.jpg" />
</Frame>

## Quick reference

| Concept                | Description                                      | Example                        |
| ---------------------- | ------------------------------------------------ | ------------------------------ |
| Workflow file location | Where GitHub looks for your workflow definitions | `.github/workflows/<name>.yml` |
| Trigger on push        | Run when commits are pushed to branch(es)        | `on: push: branches: [ main ]` |
| Manual trigger         | Allow manual execution from the GitHub UI        | `on: workflow_dispatch`        |
| Checkout action        | Prepare runner with repository files             | `uses: actions/checkout@v4`    |
| Failing a job          | Exit with non-zero code to mark job as failed    | `exit 1` in a shell `run` step |

## Learn more

* [GitHub Actions — Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows)
* [actions/checkout](https://github.com/actions/checkout)
* [GitHub Pages documentation](https://docs.github.com/en/pages)

That's the basic flow: declare triggers, define jobs and steps, use actions (for checkout, caching, etc.), and run scripts or other action steps to validate, build, test, or deploy your code.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/github-foundation-certification/module/e995be1d-2fac-4dc2-b467-fb8d1072632b/lesson/a6f134c1-36ee-46b9-bb45-0617829b8f69" />
</CardGroup>
