logo
  • 現在做什麼
  • 關於我

Kalan

文章分類

  • 前端
  • 開發筆記
  • 雜談
  • 年度回顧

快速連結

  • 現在做什麼
  • 關於我
  • 聯絡我
  • 職涯思考🔗

關注我

在福岡生活的開發者,分享軟體開發與日本生活的點點滴滴。

© 2025 Kalan Made with ❤️. All rights reserved.

How to bring Github Actions to your project

Written byKalanKalanMay 2, 2020
Home/Dev Note
💡

If you have any questions or feedback, pleasefill out this form

Japanese原文

Table of Contents

  1. A Brief Description of GitHub Actions
  2. Introduction
  3. How to Get Started
  4. Related Resources
  5. How to Add GitHub Actions to Your Project
  6. Environment Variables

This post is translated by ChatGPT and originally written in Mandarin, so there may be some inaccuracies or mistakes.

A Brief Description of GitHub Actions

Built-in CI/CD for GitHub.

![github-actions](/img/Screenshot_2020-05-02 kjj6198 animal-crossing-info.png "github-actions")

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.

Github Secret

This article serves as a quick reference on how to use GitHub Actions; next time you set it up, it should be much faster!

← Svelte Notes (2): Compiler is more clever than you messHow to do smooth scroll with one line of CSS →

If you found this article helpful, please consider buying me a coffee ☕ It'll make my ordinary day shine ✨

☕Buy me a coffee

Table of Contents

  1. A Brief Description of GitHub Actions
  2. Introduction
  3. How to Get Started
  4. Related Resources
  5. How to Add GitHub Actions to Your Project
  6. Environment Variables