reboottime / Github-Actions-CICD

A repository that consolidated my Github Actions understanding.
MIT License
0 stars 0 forks source link

Major Concepts #2

Open reboottime opened 1 week ago

reboottime commented 1 week ago

Overview

This article talks about the major concepts of using Github action as a CI CD solution.

Major concepts are bellow


Credits to Claude.ai to refine my English grammars and content.

reboottime commented 1 week ago

Github Actions and CI CD

Topic Description
What is GitHub Actions A(custom) application that performs a (typically complex) frequently repeated task. The alternative to Github action is command (run)
CI & CD Continuous Integration and Continuous Delivery
• CI: Code changes are automatically built, tested & merged with existing code
• CD: After integration, new app or package versions are published automatically
Repository Automation Area Code deployment: Automate code testing, building, and deployment
reboottime commented 1 week ago

Key Elements of Github actions

Key Element Characteristics
Workflows • Attached to a GitHub repository
• Contain one or more Jobs
• Triggered upon Events
Jobs • Define a Runner (execution environment)
• Contain one or more steps
• Run in parallel (default) or sequential
• Can be conditional
Steps • Execute a shell script or an Action
• Can use custom or third-party actions
• Steps are executed in order
• Can be conditional
Runner the environment that runs the actions. Every job gets its own runner - its own virtual machine that's totally isolated from other machines and jobs
reboottime commented 1 week ago

Events (Workflow Triggers)

Category Event Description
Repository-related push Pushing a commit
fork Repository was forked
watch Repository was starred
pull_request Pull request action (opened, closed, ...)
issues An issue was opened, deleted, ...
discussion Discussion action (created, deleted, ...)
create A branch or tag was created
issue_comment Issue or pull request comment action
Other workflow_dispatch Manually trigger workflow
repository_dispatch REST API request triggers workflow
schedule Workflow is scheduled
workflow_call Can be called by other workflows
reboottime commented 1 week ago

Common Grammars

run: |
    echo "First output"
    echo "Second output"
This will run both commands in one step.
image
reboottime commented 1 week ago

Understand Job Artifacts and Caching

Job Artifacts

Job Artifacts are stuff output by a job. See explanation below:

Job Artifacts Output Asset(s) Use Cases
Job (Example: Build app) Example: App binary, website files etc. 1. Download & Use Manually Via GitHub UI Or REST API
2. Download & Use in other Jobs Via Action

A following job can use the previous step(s) artifacts. Here is how:

A full example can be found at 5.yml

Dependencies Caching

As you can see in the 05.yml file, there are some repetitive steps between jobs. For example:

Key takeaways

Summary

Concept Description
Artifacts - Jobs often produce assets that should be shared or analyzed
- Examples: Deployable website files, logs, binaries etc.
- These assets are referred to as "Artifacts" (or "Job Artifacts")
- GitHub Actions provides Actions for uploading & downloading
Outputs - Besides Artifacts, Steps can produce and share simple values
- These outputs are shared via ::set-output
- Jobs can pick up & share step outputs via the steps context
- Other Jobs can use Job outputs via the needs context
Caching - Caching can help speed up repeated, slow Steps
- Typical use-case: Caching dependencies
- But any files & folders can be cached
- The cache Action automatically stores & updates cache values
- (based on the cache key)
reboottime commented 1 week ago

Environment Variables and Secrets