Discover how to automate tasks with GitHub Actions. Learn to set up a repo, create workflows, define triggers, and secure secrets with our step-by-step guide.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Create a GitHub Repository
Before automating any tasks, you need a repository where your code and workflow files will live.
Follow these steps:
Step 2: Enable GitHub Actions
All public repositories already have GitHub Actions enabled by default. Private repos do too, if your plan supports them.
Step 3: Create a Workflow File
Workflows live in the .github/workflows/
folder of your repo. Let’s create a file named ci.yml
.
On your local machine or via GitHub’s UI:
mkdir -p .github/workflows
cat > .github/workflows/ci.yml << 'EOF'
name: CI Pipeline
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Say Hello
run: echo "Hello, GitHub Actions!"
EOF
Step 4: Define Event Triggers
Specify when the workflow should run under the on:
key in your YAML.
push
: triggers on every push to branches you specify.pull\_request
: runs on PR creation, update, or merge.schedule
: cron-based scheduling.on:
push:
branches: [ main, develop ]
pull\_request:
branches: [ main ]
schedule:
- cron: '0 0 _ _ \*' # daily at midnight UTC
Step 5: Configure Jobs and Runners
A workflow can define multiple jobs that run in parallel or sequentially.
ubuntu-latest
, windows-latest
).needs: [job-a]
.strategy:
matrix:
node-version: [12, 14, 16]
steps:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
...
Step 6: Add Steps and Reusable Actions
Each job consists of ordered steps. Steps can be shell commands or pre-built actions.
actions/checkout@v3
to get your repo.actions/setup-python@v4
or actions/cache@v3
.run:
.steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest
Step 7: Commit and Push Your Workflow
Once your workflow file is ready, commit and push to your repository.
git add .github/workflows/ci.yml
git commit -m "Add CI workflow"
git push origin main
Step 8: Monitor and Debug Runs
Use GitHub’s UI to inspect each run.
Step 9: Secure Secrets and Environment Variables
Don’t hardcode sensitive data. Store keys and tokens in GitHub Secrets.
SECRET\_NAME
.steps:
- name: Use secret
run: echo "Secret is ${{ secrets.SECRET\_NAME }}"
env:
at workflow, job, or step level.
Step 10: Explore Advanced Features
GitHub Actions supports many advanced capabilities:
actions/cache@v3
).@actions/upload-artifact
).
By following these steps, you’ll have a solid foundation for automating tasks with GitHub Actions. Explore the official documentation to learn more and tailor workflows to your project’s needs.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.