8

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

Jenny M
  • 923
  • 1
  • 14
  • 37

2 Answers2

8

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.

flaxel
  • 4,173
  • 4
  • 17
  • 30
  • Thanks, the problem is that the server is up and running , it doesn't proceed to the next step/command. I guess that the reason that it didnt get some "finish" signal, as it up... – Jenny M Apr 04 '21 at 10:29
  • I add an alternative solution. :D – flaxel Apr 04 '21 at 10:38
  • Thanks, i'll try next suggestion , in addition please see my post update, i've submited repo which is doing exactly that, could you please have a look? – Jenny M Apr 04 '21 at 10:45
  • you can clone it and play :) – Jenny M Apr 04 '21 at 10:46
  • Yes I will do it after lunch. – flaxel Apr 04 '21 at 10:46
  • thank you very much trying now the second option :-) – Jenny M Apr 04 '21 at 10:47
  • I got an error: ` Unrecognized named-value: 'steps'. ` for job 2 inside the if statement – Jenny M Apr 04 '21 at 10:53
  • I guess you use the two jobs. If it is correct you must add the name of the job as identifier. And you must not call the checkout action twice. :D – flaxel Apr 04 '21 at 10:55
  • Thanks I've update it and the `install 2` doesnt starts it remain on install operator and stuck...any idea ? does it works for you? – Jenny M Apr 04 '21 at 11:01
  • Sorry I need to leave for couple of hours, if you have another suggestion please update your post and I'll try it when I back. thanks! – Jenny M Apr 04 '21 at 11:10
  • Any idea how to make it work as I use the kubebuilder to generate the project (include the makefile) ... https://github.com/kubernetes-sigs/kubebuilder – Jenny M Apr 10 '21 at 13:35
  • I have already created a PR in your repository with the recommendations from the last change. – flaxel Apr 10 '21 at 13:40
  • thanks, could you please explain how the debug solve the issue? – Jenny M Apr 11 '21 at 07:39
  • 2
    The problem was solved by the &. As a result, the process runs in the background and no longer blocks the further process. The debug should only help you for later, if there is an error again, to find it easier. I.e. you can also take the option out if you want. – flaxel Apr 11 '21 at 10:47
  • @flaxel was wondering if u could add ur solution here after you found it. – chia yongkang May 06 '22 at 02:47
  • 1
    @chiayongkang I added the solution in the **EDIT** section of my answer. – flaxel May 06 '22 at 05:49
2

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
John Kealy
  • 1,503
  • 1
  • 13
  • 32
  • 1
    Thanks! , I've tried it out its a bit more tricky, it didnt help as when the server is up and running (when runnig `make run` ) is stuck and dont start the next command in job2, any other idea way to make it work? – Jenny M Apr 03 '21 at 19:21