+1

Cấu hình CI/CD với Github (phần 2): Tạo một workflow bằng git actions

Tạo một workflow với Github actions.

cách 1: tạo ra file yml sau đó push lên thư mục .github/workflows/ Với cách này đơn giản là chúng ta tạo ra một file yml trong thư mục .github/workflows/ rồi push lên git

cách 2: tạo một workflow theo các mẫu có sẵn

bước 1: vào git responsitory của bạn chọp tab Action

bước 2: chọn "Setup this workflow" git sẽ chọn flow default hoặc chọn một mẫu có sẵn trong danh sách git sẽ tạo ra file workflows theo những mẫu có sẵn.

bước 3: update file yml theo ý muốn.

Cấu trúc thông thường của một Github actions

đây là một file yml mình đang sử dụng để cấu hình một git action để tự động install, build và publish source vue native lên expo mỗi khi có một người push code lên branch develop.

  1. khai báo
name:  Develop to Expo Pro2
  1. sự kiện - trigger
on:
  push:
    branches:
      - develop
  1. công việc - jobs
publish:
    name: Install and publish
    runs-on: ubuntu-latest
  • setup enviroment
teps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - uses: expo/expo-github-action@v5
        with:
          expo-version: 3.x
          expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
          expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
  • actions
- run: npm install
      - run: expo publish --release-channel=pro2
      - uses: unsplash/comment-on-pr@master
        env:
          GITHUB_TOKEN: ${{ secrets.EXPO_CLI_GIT_TOKEN }}
        with:
          msg: App is ready for review, you can [see it here](https://expo.io/@bycedric/use-expo?release-channel=pro2.

Setup secrets key

Secrests key để làm gì? có một số thông tin bảo mật các bạn không muốn public cho mọi người (kể cả những member trong dự án) biết: access token, password..... vậy các bạn cần một cơ chế để public một key ra ngoài để run time có thể access vào value được lưu trong setting của git. chúng ta có thể sử dụng Secrets key

Tạo một secrets key

bước 1: Chuyển đến tab setting

bước 2: chọn sheet Secrets: ở đây hiển thị danh sách các secrets key trong responsitory

bước 3: click "new repository secret" để tạo một secret key mới: nhập key và value

bước 4: xong thì add secret thôi nào

Có một đặt điểm là bạn không thể xem giá trị hiện tại của một secret key để tránh việc người khác có thể có được những thông tin bảo mật của bạn.


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí