Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github action run two process one after other

I've two GitHub actions which should run one after other, the first install 1 is installing & running a server (e.g. server is running on port 3000), this works however the install 1 is not finishing ( is the server is up and you dont get "stop" signal which is ok) but I need to proceed to the next step install 2 only when the server is up, how should I solve this issue?

In short when you running some process and you need to run other after a while

Please see this repo and the action.

- name: install 1
  shell: bash
  run: |
    make install
    make run
    
- name: install 2
  shell: bash
  run: |
    kubectl apply -f ./config/samples/test.yaml

im using the kubebuilder to generate the project include the makefile... https://github.com/kubernetes-sigs/kubebuilder

like image 530
Jenny M Avatar asked Apr 02 '21 07:04

Jenny M


2 Answers

The two processes install 1 and install 2 are already executed one after the other by the implicit if: ${{ success() }}.

Your problem is that the server is not completely up yet. There are several possibilites to solve this problem:

  1. Wait for few seconds with the sleep command:
  - name: install 2
    shell: bash
    run: |
      sleep 10 &&
      kubectl apply -f ./config/samples/test.yaml
  1. Wait for the port to open e.g. with the tool wait-port
  2. Wait for the port to open with native Linux tools netcat or netcat/netstat

You can alternatively create an exit code yourself, which you can use in the next step from this post:

  - name: install 1
    id: install1
    shell: bash
    run: |
      make install
      make run
      echo ::set-output name=exit_code::$?

  - name: install 2
    if: steps.install1.outputs.exit_code == 0
    shell: bash
    run: |
      kubectl apply -f ./config/samples/test.yaml

EDIT: I think I have found your problem. By executing make run your server runs permanently and blocks the further processing of the action. You could for example run make run in the background with make run &. And I think you won't need the two jobs then either. For more details during the build you can add the debug option.

like image 180
flaxel Avatar answered Oct 07 '22 10:10

flaxel


Use the needs keyword. You would also want to be separating these into different jobs.

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
    - name: install 1
      shell: bash
      run: |
        make install
        make run

  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
    - name: install 2
      shell: bash
      run: |
        kubectl apply -f ./config/samples/test.yaml
like image 45
John Kealy Avatar answered Oct 07 '22 11:10

John Kealy