Skip to content

Commit

Permalink
Fix wait end condition
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingNagger committed Nov 6, 2019
1 parent c47eb3f commit 24dac2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install Nginx pod
run: kubectl apply -f https://k8s.io/examples/application/deployment.yaml
- name: Wait for pods
uses: CodingNagger/[email protected].0
uses: CodingNagger/[email protected].1
- name: Check pods
run: |
kubectl get pods
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const core = require('@actions/core');
const { spawnSync } = require('child_process');

const successMessage = '';
const maxRetryAttempts = parseInt(`${core.getInput('max-retry-attempts')}`);
const retryDelay = parseInt(`${core.getInput('retry-delay')}`);

function checkPodsAreUp() {
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods','--field-selector=status.phase!=Running,status.phase!=Completed']);
var output = lastCommandRunning.stdout.toString();
var errorOutput = lastCommandRunning.stderr.toString();
var defaultOutput = lastCommandRunning.stdout.toString();
return {
success: `${output}`.trim() == '',
message: output,
success: errorOutput.includes('No resources found'),
message: defaultOutput,
};
}

Expand All @@ -28,7 +28,7 @@ try {
var result = checkPodsAreUp();
var attemptsCount = 0;

while(!result.success || attemptsCount < maxRetryAttempts) {
while(!result.success && attemptsCount < maxRetryAttempts) {
console.log(`Waiting ${retryDelay} seconds`);
attemptsCount++;
wait(retryDelay);
Expand Down

0 comments on commit 24dac2a

Please sign in to comment.