How to bring Github Actions to your project
# Dev NoteA Brief Description of GitHub Actions
Built-in CI/CD for GitHub.

Introduction
In the past, implementing CI might involve lengthy discussions (or even arguments) within the team about the best CI solutions, such as CircleCI, DroneCI, Jenkins, and others. However, as long as the code is hosted on GitHub, integrating CI becomes a breeze with GitHub Actions. While it may not be a universal solution or a silver bullet, I find it quite straightforward for typical scenarios like running tests or even pushing and deploying code. Below, I will introduce how to get started.
How to Get Started
Simply add a workflow descriptor file named .github/workflows/your-workflow.yml in the root directory of your code.
Related Resources
Before diving in, it might be quicker to share a few document links to get you started. However, if you prefer to read through the documentation first, here are some resources:
- Overview: https://github.com/features/actions
- Documentation: https://help.github.com/en/actions
- GitHub Actions Marketplace: https://github.com/marketplace?type=actions
How to Add GitHub Actions to Your Project
A workflow consists of several jobs, and each job is made up of multiple steps. A step can be a GitHub Action, running a command, and so on. Here’s a basic example:
name: your-name
# Refer to the documentation for available events
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
push:
branches:
- master
paths-ignore: # Sometimes, you may not want to trigger GitHub Actions just by changing a file; you can use this ignore
- 'docs/**'
- 'README.md'
- 'LICENSE'
- 'CONTRIBUTING.md'
branches-ignore:
- 'xxxx'
tags-ignore:
- 'v1.*'
env: # Set environment variables
PROJECT_ID: ${{ secrets.PROJECT_ID }}
RUN_REGION: asia-northeast2
SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
jobs:
setup-build-and-deploy:
name: Setup gcloud and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '290.0.1'
project_id: ${{ secrets.PROJECT_ID }}
service_account_email: ${{ secrets.SA_EMAIL }}
server_account_key: ${{ secrets.SA_KEY }}
export_default_credentials: true
- name: Deploy
run: |-
echo $SERVICE_ACCOUNT > /tmp/key.json && \
gcloud auth activate-service-account --key-file /tmp/key.json && \
gcloud app deploy --project "$PROJECT_ID"
For more advanced scenarios, if you want to dynamically evaluate conditions at runtime, you can write it like this: https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
env:
my_env_var: ${{ ALPHA ? 'A' : 'B' }}
When running, GitHub Actions automatically provides some context for you.
Environment Variables
Environment variables can be set in the secrets of your project. By default, only collaborators can see them, and others cannot access the secrets via Pull Requests in GitHub Actions.

This article serves as a quick reference on how to use GitHub Actions; next time you set it up, it should be much faster!
Related Posts
- Stop Using Access Keys AlreadyAccess Keys are an easily overlooked security risk on AWS. Use OIDC with IAM Roles so GitHub Actions can securely access AWS resources without any secrets.
- Database Primary Keys: AUTO_INCREMENT, UUID, and UUIDv7Backend developers often have to decide on a primary key: auto increment or UUID? What about collisions? How much faster is UUIDv7 compared with created_at + index? After benchmarking 20 million rows and looking at the design trade-offs, this post gives you the answer.
- Sharing My Experience with ZeaburIndependent developers often choose platforms like Vercel for deploying their services. However, when more advanced requirements arise, such as database connections, Vercel can become less convenient. Additionally, the pricing of typical cloud service providers can be quite expensive for solo developers. In this article, I’ll share some insights on using Zeabur and highly recommend it to everyone!
- Keyboard Enthusiast's Guide - Firmware EditionThis article is part of the IT 2023 Ironman Competition: A Beginner's Guide to Keyboards - Firmware Edition.