SovranCode
HomeCourses Git & GitHub GitHub Actions
This device
Course contentsGitHub Actions · 41 topics

1. Git Fundamentals

Git IntroductionGit Version ControlGit vs GitHubGit InstallationGit Working TreeGit RepositoryGit CommitGit .gitignoreGit Project: Learning Journal

2. Git History

Git LogGit DiffGit ResetGit RevertGit StashGit Project: Messy Repository

3. Branches & History

Git BranchGit MergeGit Merge ConflictsGit RebaseGit Cherry-PickGit TagsGit Project: Feature Branch

4. Remotes and GitHub

Git RemoteGitHub AuthenticationGitHub RepositoryGitHub ForkGitHub IssuesGitHub PagesGit Project: Two Clone Sync

5. GitHub Collaboration

GitHub Pull RequestsGitHub Code ReviewGit Branching WorkflowGitHub Branch ProtectionGitHub CollaborationGitHub ContributingGit Project: Reviewed Pull Request

6. Automation and Professional Git

GitHub ActionsGit InternalsGit RecoveryGitHub SecurityGit Project: Team Repository CIProject
Learn Git & GitHub40 complete · 1 planned

1. Git Fundamentals

Git IntroductionGit Version ControlGit vs GitHubGit InstallationGit Working TreeGit RepositoryGit CommitGit .gitignoreGit Project: Learning Journal

2. Git History

Git LogGit DiffGit ResetGit RevertGit StashGit Project: Messy Repository

3. Branches & History

Git BranchGit MergeGit Merge ConflictsGit RebaseGit Cherry-PickGit TagsGit Project: Feature Branch

4. Remotes and GitHub

Git RemoteGitHub AuthenticationGitHub RepositoryGitHub ForkGitHub IssuesGitHub PagesGit Project: Two Clone Sync

5. GitHub Collaboration

GitHub Pull RequestsGitHub Code ReviewGit Branching WorkflowGitHub Branch ProtectionGitHub CollaborationGitHub ContributingGit Project: Reviewed Pull Request

6. Automation and Professional Git

GitHub ActionsGit InternalsGit RecoveryGitHub SecurityGit Project: Team Repository CIProject
PREVIOUS · PROJECTGit Project: Reviewed Pull Request
NEXT LESSONGit Internals
6. Automation and Professional Git 90 min

GitHub Actions

Add a workflow that runs on pull requests, fails on a real defect, and reports a result reviewers can trust.

What you will leave with

You will add a workflow file GitHub runs on pull requests, watch it fail while README.md uses a Pages clone URL, fix that defect with git push, and read gh pr checks. You will not deploy a site, will not paste tokens into logs, and will not require the check in protection until it has passed once.

The file is Git; the run is GitHub

GitHub Pull Requests opened a conversation. GitHub Code Review put comments on that conversation. This lesson adds a third voice: a GitHub runner that checks out the same Git commit and reports pass or fail on the pull request. GitHub Branch Protection can later require that report. It cannot invent the workflow.

GIT

The workflow file

YAML under .github/workflows/. git add stages it. It travels with the clone. It is not a Git hook.

GITHUB

The run and the check

GitHub starts a job on pull_request (and on push to main). The Actions tab and gh pr checks show the result. That result is not a Git object.

# These are Git. None of them starts a GitHub Actions run.
git add README.md
git commit -m "Note"
git push origin main

Use a disposable GitHub repository you own. A repository from the reviewed pull request project is fine if you still control it. Do not add a workflow to a project you do not maintain.

The runner does not see your working tree

actions/checkout copies the Git commit for that event onto GitHub's machine. Unstaged edits on your laptop are invisible. If you want the check to see a change, commit it and push it.

A small workflow you can name

Put one file at .github/workflows/clone-url.yml. The name in the file is what reviewers read. The job id clone-url is what protection can require later. Keep both boring and exact.

name: Clone URL check

on:
  pull_request:
  push:
    branches: [main]

jobs:
  clone-url:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Refuse a Pages clone URL
        run: |
          set -e
          if grep -n 'github.io' README.md; then
            echo "README must not use a Pages host as a git clone URL"
            exit 1
          fi
          grep -E 'git clone (https://github.com/|git@github.com:)' README.md
# From a clone of a GitHub repository YOU own
git switch main
git pull origin main
git switch -c feature/actions-check

mkdir -p .github/workflows
# Write .github/workflows/clone-url.yml from the contract below.
# If README.md has no Clone heading, or still uses a Pages URL, keep that defect
# for the first pull request so the check fails on purpose.

git add .github/workflows/clone-url.yml README.md
git diff --cached
git commit -m "Add a Clone URL check and a README the check can fail"
git push -u origin feature/actions-check
QUICK CHECK

Test what you learned

Type the Git command that stages .github/workflows/clone-url.yml.

on

pull_request is the teaching event. push to main re-runs after merge so the default branch is not a special case.

jobs.clone-url

One job, one name. runs-on: ubuntu-latest is GitHub's runner, not your laptop and not a Git config.

checkout

actions/checkout@v4 is GitHub fetching the commit. Do not add a marketplace of other actions in this lab.

The script

Fail if README mentions github.io. Pass only if a git clone line uses GitHub's Git host. Same contract you can run locally.

# Same contract GitHub will run. Dirty files you have not committed do not count.
grep -n 'github.io' README.md && echo "would fail" || echo "no Pages host"
grep -E 'git clone (https://github.com/|git@github.com:)' README.md

Local grep is a preview. It is not the GitHub check. CI must fail and pass on the pull request, not only in your terminal.

Fail on a real defect

The first pull request should be red. Plant the same Pages clone URL GitHub Code Review already treated as a defect. If README already has a correct Git URL, change it to a .github.io host in this branch so the first run has something true to reject.

## Clone

git clone https://OWNER.github.io/sovrancode-reviewed-pr/

That host is a static site, not a Git remote. The workflow's grep 'github.io' should exit 1. If the first run is green, you did not give the check a defect. Stop and plant one; a badge that never failed is decoration.

Watch the check on the pull request

gh pr create --base main --title "Add a Clone URL check" --body "$(cat <<'EOF'
## Summary
Adds a GitHub Actions workflow that fails when README.md uses a Pages host as a git clone URL.

## How to verify
1. Wait for the Clone URL check on this pull request.
2. Confirm it fails while README.md still contains github.io.
3. After the follow-up push, confirm the same check passes.
EOF
)"

gh pr checks
gh run list
QUICK CHECK

Test what you learned

Type the GitHub CLI command that lists recent workflow runs.

QUICK CHECK

Test what you learned

Type the GitHub CLI command that shows checks for the current pull request.

gh pr checks talks to GitHub. git log will not. Wait until the run finishes; a pending check is not a pass. Open the run on GitHub and read the step that grepped README. That log is the proof the runner saw the Pages URL.

Red is required evidence

Save gh pr checks while it fails. The unit project already taught a review comment. This is a second, automatic voice saying the same clone risk.

Not a substitute for review

A green check does not mean the change is wanted. Reviewers still read the diff. The check only answers the contract you wrote in YAML.

Not git pull

Starting the run is GitHub reacting to a push. git pull still only updates your local branch.

Job name

Record the check name as GitHub shows it (often clone-url). You will need that string if you require it later.

Pass, then maybe require

# Stay on feature/actions-check. The first run must have been red.
# Edit README.md so git clone uses the GitHub Git URL, then:
git add README.md
git diff --cached
git commit -m "Use the GitHub Git URL in the Clone section"
git push
gh pr checks
gh run list

# Do not force-push. The failed run is evidence.

Stay on the same feature branch. Ordinary git push. GitHub starts a new run for the new commit. gh pr checks should turn green. Then merge if the pull request is otherwise ready.

Only after a green run: in the protection rule for main, you may require the clone-url check. Do that on a repository you own. Do not require two reviewers. Do not require a check whose name you have never seen in gh pr checks.

Require last

Protection that requires a missing check blocks every merge, including yours. The GitHub Actions lesson is fail, pass, then optionally require—not require first.

What not to invent

A workflow on a stranger's repo

Do not open a pull request that only adds Actions to a popular project as homework.

Secrets in the log

Do not echo tokens, GITHUB_TOKEN, or passwords. Git .gitignore still applies to files; logs are another leak. GitHub Security covers least privilege, signing, and token rotation.

Deploy as the first check

Pages already taught a static host. This workflow does not publish a site. The team CI project will assemble protection plus a check as release evidence.

A marketplace of actions

One checkout plus a shell script is the lab. Third-party actions you cannot read are out of scope.

Guided practice: red, then green

  1. 01
    Pick a repository you own

    Confirm git remote -v is your GitHub URL. Update local main.

  2. 02
    Add the workflow and a defect

    On feature/actions-check, add .github/workflows/clone-url.yml. README must contain github.io in a clone command for the first run.

  3. 03
    Open the pull request and wait

    gh pr create, then gh pr checks and gh run list. Record the failed run.

  4. 04
    Fix and push

    Use the GitHub Git URL. git push without force. Wait until the same check is green.

  5. 05
    Optional require

    If protection already exists, add required status check clone-url only after green. Merge the pull request. Confirm a run on main if push is in on.

Independent lab: a trusted check

  1. On a GitHub repository you own, add .github/workflows/clone-url.yml with on: pull_request, job id clone-url, actions/checkout@v4, and a step that fails when README.md contains github.io and passes when a git clone line uses GitHub's Git host.
  2. Open a pull request whose first commit still has the Pages defect. Show gh pr checks (or the Checks panel) failing. Do not merge yet.
  3. Fix the Clone command on the same branch. git push without --force. Show the same check passing.
  4. Optional: require clone-url on protected main only after that green run. Do not require two reviewers.
  5. Write six lines: repository URL, pull request number, failed run id or timestamp, passing run id or timestamp, the check name as GitHub showed it, and one sentence that distinguishes a GitHub Actions run from git show. Do not add a workflow to a project you do not maintain.
Definition of done

You can store a workflow in Git, let GitHub fail a real defect on a pull request, pass it with an ordinary follow-up push, and read the check on GitHub—on a repository you own, without requiring a check that has never run.

Common Actions mistakes

Expecting local edits to run CI

The runner checks out a commit. Save, commit, push.

Requiring a check that never ran

Every pull request waits forever. Fail and pass first.

Calling the YAML a Git hook

Hooks live in .git/hooks and run on your machine. This file runs on GitHub.

A check instead of review

Green means the script passed. It does not mean the change should merge.

Lesson review

You can add a GitHub Actions workflow that runs on pull requests, fails a real clone-URL defect, passes after an ordinary push, and reports on the pull request—not inside Git. Git Internals reads the commit the runner checked out, Git Recovery isolates when a regression entered history, and GitHub Security constrains workflow credentials. The team CI project stays planned.

  • I know a workflow is a Git file GitHub runs; git commit does not start the runner.
  • I can add .github/workflows/clone-url.yml with on: pull_request and actions/checkout@v4.
  • I can gh run list and gh pr checks, and I have evidence of one red run and one green run.
  • I require that check in protection only after it has passed, on a repository I own.

Related lessons

  • GitHub Pull Requests — Checks report on the pull request, not inside Git itself.
  • GitHub Branch Protection — Required status checks can block a merge after a workflow already passes.
  • GitHub Code Review — A red check is evidence; it does not replace a review comment.
  • Git Project: Reviewed Pull Request — The unit project closed an issue; this lesson adds a check that pull request can fail.
  • Git .gitignore — Do not print tokens in workflow logs.
  • GitHub Security — Constrain GITHUB_TOKEN permissions and keep secrets away from untrusted code.
KNOWLEDGE CHECK

Check your GitHub Actions model

Keep the workflow file in Git, let GitHub run it on the pull request, fail a real defect, then pass—before you require the check.

01What is a GitHub Actions workflow?
02Does git commit run the Clone URL check?
03What should a useful first check do?
04Where do pull request check results live?
05What does actions/checkout do in this lesson?
06When should you require this check in branch protection?
07Where should you add this workflow?
PREVIOUS · PROJECTGit Project: Reviewed Pull Request
NEXT LESSONGit Internals
ON THIS PAGEGitHub ActionsThe file is Git; the run is GitHubA small workflow you can nameFail on a real defectWatch the check on the pull requestPass, then maybe requireWhat not to inventGuided practice: red, then greenIndependent lab: a trusted checkCommon Actions mistakesLesson reviewKnowledge checkRelated lessons
Course contents