Workflowsにデプロイしてみた【GCP】

## まずyamlファイルを用意します。
```hello.yaml
main:
  steps:
    - step1:
        call: http.post
        args:
          url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
          auth:
            type: OAuth2
          body:
            overrides:
              containerOverrides:
                - name: main-container
                  args:
                    - npm
                    - run
                    - helloA
        result: runHelloA
    - checkRunHelloAStatus:
        switch:
          - condition: ${runHelloA.code == 200}
            next: step2
          - condition: ${runHelloA.code != 200}
            next: logFailure
    - logFailure:
        call: sys.log
        args:
          text: ${runHelloA.code}
    - step2:
        call: http.post
        args:
          url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
          auth:
            type: OAuth2
          body:
            overrides:
              containerOverrides:
                - name: main-container
                  args:
                    - "npm"
                    - "run"
                    - "helloB"
```
URLの形式
https://{REGION}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/{PROJECT_ID}/jobs/{JOB_NAME}:run

ロジックは非常に簡単で、hellosをnpm run helloAで実行し、ステータスコード200が返ってくれば、helloBを実行し、そうでなければステータスコードをログに表示するだけです。

## デプロイコマンド
```
gcloud workflows deploy {workflowsName} --source="yamlファイル名"
```

```
root@9e8a85ceee38:/app# gcloud workflows deploy myHello --source="hello.yaml"
WARNING: The default location(us-central1) was used since the location flag was not specified.
Waiting for operation [operation-1735086887458-62a0d6594d698-0124134f-cda1ddd5] to complete...done.
createTime: '2024-12-24T06:14:12.139981072Z'
name: projects/myProject/locations/us-central1/workflows/myHello
revisionCreateTime: '2024-12-25T00:34:47.630451435Z'
revisionId: 
serviceAccount: mailto:projects/myproject/serviceaccounts/-compute@developer.gserviceaccount.com
sourceContents: |
  main:
    steps:
      - step1:
          call: http.post
          args:
            url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
            auth:
              type: OAuth2
            body:
              overrides:
                containerOverrides:
                  - name: main-container
                    args:
                      - npm
                      - run
                      - helloA
          result: runHelloA
      - checkRunHelloAStatus:
          switch:
            - condition: ${runHelloA.code == 200}
              next: step2
            - condition: ${runHelloA.code != 200}
              next: logFailure
      - logFailure:
          call: sys.log
          args:
            text: ${runHelloA.code}
      - step2:
          call: http.post
          args:
            url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
            auth:
              type: OAuth2
            body:
              overrides:
                containerOverrides:
                  - name: main-container
                    args:
                      - "npm"
                      - "run"
                      - "helloB"
state: ACTIVE
updateTime: '2024-12-25T00:34:47.732630309Z'
```
上記のようになればデプロイ成功です！