GitHub Actions Basics
GitHub Actions is a built-in automation tool that runs workflows in response to events like pushes or pull requests. It's commonly used for continuous integration (CI), running tests automatically on every change.
Workflows are defined in YAML files stored in a `.github/workflows` folder in your repository, describing what triggers the workflow and what steps to run.
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm testCreating a workflow
Add a YAML file like `.github/workflows/ci.yml` describing triggers (like push or pull_request) and jobs containing steps such as checking out code and running tests.
Common use cases
GitHub Actions is used for running automated tests, linting code, building and deploying applications, and publishing packages, all automatically on every push or PR.
mkdir -p .github/workflows
cat > .github/workflows/ci.yml << 'YML'
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm test
YMLCreates a basic GitHub Actions workflow that runs tests every time code is pushed.
git add .github/workflows/ci.yml
git commit -m "Add CI workflow"
git push[main 8b2f1aa] Add CI workflowCommitting and pushing the workflow file activates it on GitHub, running automatically on the next push.
Key points
- GitHub Actions automates workflows like testing and deployment.
- Workflows are defined in YAML files in .github/workflows.
- Common triggers include push and pull_request events.
- Actions are widely used for continuous integration (CI).
