# Migrate Continuous Integration From Travis CI to GitHub Action

# Date: 2021/July/21


在這個筆記荒廢了很長一段時間以後,看著 GitHub dependabot 滿滿的 Pull Request 通知,

深深覺得該好好更新一下相依套件了,才發現原本透過 Travis 串好的 CI 壞掉啦。

原本以為是更新套件的問題,不過詳細看了錯誤訊息是授權失敗。

看了字面上的意思,以及想到 GitHub 在今年5月份的時候有對 Authentication token 進行更新 (opens new window)
於是我也跑去刷新了一下 Personal Access Token (確保 Travis CI 有權限可以部署),結果還是失敗......

後來發現原來是因應之前的計費模式調整 (opens new window),要先去後台選擇好方案後才能繼續跑部署腳本。

原本的設定頁面大大的紅字沒有截到圖,不過基本上就是要你選方案:

要注意的是點數用完就沒了,不會再生,只能透過付費取得。

調整到這裡,部落格的自動發版復活了,但我也開始想將 CI 轉換到曾在公司使用的 GitHub Action 上了。

相較於 Travis 的終生額度制, GitHub Action 目前採用每月分鐘數的額度 (opens new window),新的一個月會刷新額度看起來比較誘人。 當然微軟爸爸比較罩也是個原因。

事不宜遲,那就馬上做調整吧。首先第一步是先把Travis CI關掉XD
再來是選擇合適的GitHub Action並修改設定檔,我是使用 Deploy to GitHub Pages (opens new window),也是目前星星數相當多的一套。

點開頁面就可以看到範本,不過下面的說明是說需要同時使用 actions/checkout 來確保部署成功,所以改成修改下面的範例:

name: GH-Pages Build and Deploy
on:
  push:
    # branches to consider in the event; optional, defaults to all
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.1

      - name: Install and Build
        run: |
          npm install
          npm run docs:build

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@4.1.4
        with:
          branch: gh-pages # The branch the action should deploy to.
          folder: docs/.vuepress/dist # The folder the action should deploy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Vuepress 產生的靜態檔案要安置的位置需要調整,除此之外都跟範例差不多。

輕鬆愉快地成功了。

也能看到中間跑了什麼,方便除錯。

看來部落格可以繼續放著長草了,可喜可賀、可喜可賀。


# References


# 其他參考資料

Heather Harvey (2021/Apr/05). Behind GitHub’s new authentication token formats (opens new window). GitHub Blog.

Gea-Suan Lin (2020/DEC/13). Travis CI 停止提供服務給 Open Source 專案 (opens new window). Gea-Suan Lin's BLOG.

Jeff Geerling (2020/DEC/05). Travis CI's new pricing plan threw a wrench in my open source works (opens new window). jeffgeerling Blog.

Last Updated: 2022/7/7 上午8:34:36