Github Action Basics
GitHub Actions allow you to automate workflows directly from your GitHub repository. It enables you to build, test, and deploy your code based on specific events (such as code pushes, pull requests, and more).
Key Concepts of GitHub Actions
Workflows: Automated processes that you define in your repository.
Jobs: A workflow is composed of one or more jobs that can run sequentially or in parallel.
Steps: Jobs contain steps that run commands in the job's virtual environment.
Actions: The individual tasks that you can combine to create jobs and customize your workflow. You can use actions defined in the GitHub marketplace or create your own.
Adding a GitHub Action to Your Repository
Create a Workflow File:
Workflow files are stored in the
.github/workflows
directory of your repository.Workflow files use YAML syntax and have a
.yml
extension.
Example WorkFlow File:
Breakdown:
name
: The name of the workflow.on
: The events that trigger the workflow. In this case, it's triggered on any push to the main branch.jobs
: The jobs that will run as part of the workflow.runs-on
: Specifies the virtual environment to run the job (e.g.,ubuntu-latest
).steps
: The steps to run within the job.name
: A descriptive name for the step.uses
: Specifies an action to use (from the GitHub Actions marketplace).run
: Runs a command in the virtual environment.
Common on
Event Options:
on
Event Options:push: Triggers the workflow when code is pushed to the repository.
pull_request: Triggers the workflow when a pull request is opened, updated, or closed.
schedule: Triggers the workflow on a scheduled time, using cron syntax.
workflow_run: Triggers the workflow when another workflow completes.
check_suite: Triggers the workflow when a check suite is completed.
check_run: Triggers the workflow when a check run is created or completed.
Combining Multiple Events You can combine multiple events, filter by branch, tags, or specify types for more granular control over when a workflow runs.
Filtering Events by Tags
Last updated