Github Actions
Github Actions
Code Deployment
Code & Repository Management
(CI / CD)
What is GitHub?
And what are “repositories”?
What’s CI / CD?
Methods for
automating app
development &
deployment
CI / CD Work ow
GitHub Actions
For CI / CD
Alternatives
Save code snapshots Work with alternative code Move between branches &
(“commits”) versions (“branches”) commits
With Git, you can easily roll back to older code snapshots or
develop new features without breaking production code.
What Is GitHub?
Backup, work across Via “Issues”, “Projects”, “Pull Via GitHub Actions, GitHub
machines & work in teams Requests” & more Apps & more
Video-based
Practice & Experiment Learn & Grow Together
Explanations
Save code snapshots Work with alternative code Move between branches &
(“commits”) versions (“branches”) commits
With Git, you can easily roll back to older code snapshots or
develop new features without breaking production code.
Git Repositories
git commit
C1 C2 C3 C4 C5 C6
Working with Commits (Code Snapshots)
git commit
C1 C2 C3 C4 C5 C6
Understanding Staging
fi
Working with Commits (Code Snapshots)
git commit
C1 C2 C3 C4 C5 C6
Working with Commits (Code Snapshots)
git commit
C1 C2 C3 C4 C5 C6
Working with Commits (Code Snapshots)
git commit
C1 C2 C3 C4 C5 C6 C7
Working with Commits (Code Snapshots)
C1 C2 C3 C4 C5 C6
Working with Commits (Code Snapshots)
C1 C2 C3 C4
Key Commands
git init Initialize a Git repository (only required once per project)
git add <file(s)> Stage code changes (for the next commit)
git commit -m “…” Create a commit for the staged changes (with a message)
git status Get the current repository status (e.g., which changes are staged)
git revert <id> Revert the changes of commit <id> (by creating a new commit)
C2 C2
Merge branches
C3
git merge <name>
C4 C4
What Is GitHub?
Backup, work across Via “Issues”, “Projects”, “Pull Via GitHub Actions, GitHub
machines & work in teams Requests” & more Apps & more
Public Private
Step 1 Step 1
fl
fl
fl
Events (Workflow Triggers)
Repository-related Other
schedule
watch discussion Work ow is scheduled
Repository was Discussion action Many More!
starred (created, deleted, …)
work ow_call
Can be called by other
work ows
fl
fl
fl
fl
fl
fl
What Are Actions?
Command
Action
(“run”)
ffi
Job Runners
Every job has a Runner
Work ow Job
Runner
Steps execute
on the Runner Server (virtual
machine) that runs
the job
Steps
GitHub provides
Ubuntu Linux,
Windows & macOS
Runners
Work ows have at least one (but GitHub provides detailed insights
Jobs: De ne Runner + Steps
possible more) event(s) into job execution (+ logs)
.github/work ows/< le>.yml Pre-de ned Runners (with But you can also use pre-de ned
(on GitHub or locally) di erent OS) exist Actions (o cial, community or
custom)
GitHub Actions syntax must be You can also create custom
followed Runners
ff
fi
fl
fl
fl
fl
fi
fi
ffi
fl
fi
fl
fi
fi
Exercise Time!
Use the Attached
Project
Examples!
fl
Available Events
Repository-related Other
schedule
watch discussion Work ow is scheduled
Repository was Discussion action Many More!
starred (created, deleted, …)
work ow_call
Can be called by other
work ows
fl
fl
fl
fl
fl
fl
Event Activity Types & Filters
More detailed control over when a More detailed control over when a
work ow will be triggered work ow will be triggered
opened
Filter based
closed
pull_request Event push Event on target
edited
branch
…
fl
fl
Cancelling Skipping
The exact type of event that For push & pull_request: Add
There are many supported events
should trigger a work ow lters to avoid some executions
Most are repository-related (e.g., Examples: Opening or editing a Filter based on target branch and
push, pull_request) pull request should trigger the wf / or a ected le paths
Avoids spam from untrusted You can skip via [skip ci] etc. in
contributors commit message
fi
fl
fl
ff
fi
fl
Exercise Time!
1 2
Variation
Also run for “dev” branch and Variation
DON’T run if work ow les Also run for “dev” branch
were edited
fl
fl
fl
fi
Job Data & Outputs
It’s All About Data!
Caching Dependencies
Understanding Job Artifacts
Example: Name of a le
generated in a previous
build step
fi
fi
ff
fi
Caching Dependencies
Often repeated
Test App Build Project
Dependencies
don’t change
frequently
Module Summary
Jobs often product assets that Besides Artifacts, Steps can Caching can help speed up
should be shared or analyzed product and share simple values repeated, slow Steps
Examples: Deployable website These outputs are shared Typical use-case: Caching
les, logs, binaries etc. via ::set-output dependencies
These assets are referred to as Jobs can pick up & share Step But any les & folder can be
“Artifacts” (or “Job Artifacts”) outputs via the steps context cached
GitHub Actions provides Actions Other Jobs can use Job outputs The cache Action automatically
for uploading & downloading via the needs context stores & updates cache values
(based on the cache key)
Using Secrets
Environment 1 Environment 2
“testing” “production”
Together with
Use Secrets
environment variables
GitHub Repository Environments
Dynamic values used in code Some dynamic values should not Jobs can reference di erent
(e.g., database name) be exposed anywhere GitHub Actions Environments
May di er from work ow to Examples: Database credentials, Environments allow you to set up
work ow API keys etc. extra protection rules
Can be de ned on Work ow-, Secrets can be stored on You can also store Secrets on
Job- or Step-level Repository-level or via Environment-level
Environments
Can be used in code and in the
GitHub Actions Work ow Secrets can be referenced via the
secrets context object
Accessible via interpolation and
the env context object
fl
ff
fi
fl
fl
ff
fl
Controlling Execution Flow
Beyond Step-By-Step Flows
2
Install dependencies
3
Lint code
4
Run automated tests
5
Upload report
Controlling Execution Flow
1
Get code (from repository)
2
Install dependencies
3
Lint code
4
Run automated tests
5
Upload report
Controlling Execution Flow
1
Get code (from repository)
2
Install dependencies
3
Lint code
4
Run automated tests
5
Upload report
Conditional Jobs & Steps
Jobs Steps
failure() success()
always() cancelled()
Work ow 1 Work ow 2
Job 1 Job 1
Steps Steps
Job 2
Work ow 1
Example: Upload website code to
hosting server
fl
fl
fl
Module Summary
Control Step or Job execution Run multiple Job con gurations in Work ows can be reused via the
with if & dynamic expressions parallel workflow_call event
Change default behavior with Add or remove individual Reuse any logic (as many Jobs &
failure(), success(), combinations Steps as needed)
cancelled() or always()
Control whether a single failing Work with inputs, outputs and
Use continue-on-error to Job should cancel all other Matrix secrets as required
ignore Step failure Jobs via continue-on-error
fl
fl
fi
Using Containers
Utilizing Docker Containers
Containers - A Re-Introduction
Docker Container
Advantage: Reproducible
execution environment & results
Containers & GitHub Actions
still runs on
Packages of code + execution You can run Jobs in pre-de ned Extra services can be used by
environment environments Steps in Jobs
Great for creating re-usable Build your own container images Example: Locally running, isolated
execution packages & ensuring or use public images testing database
consistency
Based on custom images or
Example: Same environment for Great for Jobs that need extra public / community images
testing + production tools or lots of customization
fi
Building Custom Actions
Beyond Shell Commands & The Marketplace
No Existing (Community)
Simplify Work ow Steps
Action
{}
JavaScript Actions Docker Actions Composite Actions
Use JavaScript (NodeJS) + Perform any task(s) of your Combine run (commands)
any packages of your choice choice with any language and uses (Actions)
Pretty straightforward (if you Lots of exibility but requires Allows for reusing shared
know JavaScript) Docker knowledge Steps (without extra skills)
fl
fi
fi
fi
fl
Module Summary
Simplify Work ows & avoid Create custom Actions by Write Action logic in JavaScript
repeated Steps combining multiple Steps (NodeJS) with @actions/toolkit
Implement logic that solves a Composite Actions are like Alternatively: Create your own
problem not solved by any “Work ow Excerpts” Action environment with Docker
publicly available Action
Either way: Use inputs, set outputs
Create & share Actions with the Use Actions (via uses) and and perform any logic
Community Commands (via run) as needed
fl
fl
Permissions & Security
Keep Things Secure
Third-Party Permissions
fl
Security Concerns
Malicious Third-Party
Script Injection Permission Issues
Actions
Considerable
amount of Only use your own Actions Highest Level of Security
e ort
You should
analyze the
Use all public Actions Lowest Level of Security
Action code
rst!
fi
ff
fi
GitHub Permissions & GITHUB_TOKEN
Why do they have access to your e.g., for checking out the
GitHub repository? code or inspecting issues
Goal 2
Deploy (“publish”) the website Install dependencies
Trigger 3
Whenever a new commit is pushed Build website
to the “main” branch
4
Run automated tests
5
Deploy website