Closed3

GitHub Actions の inputs を使った

Sadayoshi Tada / taddySadayoshi Tada / taddy

試しに Node.js の雑なスクリプトを用意して Actions から実行する

const env = process.env.ENV_NAME || 'dev'
const input_args = process.argv.slice(2)
console.log('Env is: ' + env + ' and input args are: ' + input_args)

Actions の yaml

name: 'Run npm script'
on:
    workflow_dispatch:
        inputs:
          action_choice:
            type: choice
            required: true
            description: Input script to run
            default: "echo"
            options:
                - "echo"
          environment:
            type: choice
            required: true
            description: Environment to run script on
            default: "dev"
            options:
                - "dev"
          action_args:
            type: string
            required: false
            description: Arguments to pass tod script
            default: ""

env:
  NODE_VERSION: 18.x

defaults:
  run:
    working-directory: ./hoge

jobs:
  main:
    name: Exec Npm Script
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: ${{ env.NODE_VERSION }}
      - name: Install dependencies
        run: yarn install
      - name: Run maintenance script with no args
        if: github.event.inputs.action_args == ''
        run: | 
            yarn ${{ github.event.inputs.action_choice }}:${{ github.event.inputs.environment }}
      - name: Run maintenance script with args
        if: github.event.inputs.action_args != ''
        run: | 
            yarn ${{ github.event.inputs.action_choice }}:${{ github.event.inputs.environment }}:${{ github.event.inputs.action_args }}
このスクラップは2023/09/06にクローズされました