ビルドファイルを生成するためのワークフローの更新
このステップでは、ワークフローファイルを変更してビルドプロセスをシミュレートします。dist ディレクトリとダミーの成果物ファイルを作成するステップを追加します。
github-actions-demo の GitHub リポジトリページで、緑色の Code ボタンをクリックします。
- HTTPS タブが選択されていることを確認し、URL をコピーします。URL は
https://github.com/your-username/github-actions-demo.git のような形式になります。
- LabEx 環境でターミナルを開きます。デフォルトのパスは
~/project です。
git clone コマンドを使用してリポジトリをダウンロードします。your-username はご自身の GitHub ユーザー名に置き換えてください。
cd ~/project
git clone https://github.com/your-username/github-actions-demo.git
出力例:
Cloning into 'github-actions-demo'...
remote: Enumerating objects: X, done.
remote: Counting objects: 100% (X/X), done.
remote: Total X (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (X/X), done.
- クローンしたリポジトリ内に移動します。
cd ~/project/github-actions-demo
-
WebIDE エディタを使用して、新しいワークフローファイル .github/workflows/upload-artifacts.yml を作成します。このファイルは、左側のファイルエクスプローラーの project/github-actions-demo/.github/workflows/ の下にあります。
-
基本的なワークフロー構造の作成から始めます。ワークフロー名とトリガーを追加します。
name: Upload Artifacts
on: [push]
jobs セクションを追加し、ランナーを指定してビルドジョブを定義します。
jobs:
build:
runs-on: ubuntu-latest
steps セクションを追加します。まず、チェックアウトステップを追加します。
steps:
- uses: actions/checkout@v4
- Node.js セットアップステップを追加します。
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- 依存関係をインストールするステップを追加します。
- name: Install dependencies
run: npm install
dist ディレクトリと、その内部にファイルを作成するビルドステップを追加します。
- name: Build project
run: |
mkdir dist
echo "This is the build artifact" > dist/build.txt
- テストステップを追加します。
- name: Run tests
run: npm test
完成したファイルは次のようになります。
name: Upload Artifacts
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Build project
run: |
mkdir dist
echo "This is the build artifact" > dist/build.txt
- name: Run tests
run: npm test
解説
mkdir dist: dist という名前のディレクトリを作成します。
echo ... > dist/build.txt: コンパイルされたアセットをシミュレートするために、dist の内部にシンプルなテキストファイルを作成します。
変更を加えたら、ファイルを保存します (Ctrl+S または Cmd+S)。