Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Only seeing "in progress" status #36

Open
wants to merge 41 commits into
base: master
Choose a base branch
from

Conversation

patrickpaulin
Copy link

@patrickpaulin patrickpaulin commented Apr 22, 2021

Pull Request Template

📢 Type of change

  • Bugfix
  • New feature
  • Refactoring
  • Enhancement

📜 Description

The function getWorkflowRunStatus() was working incorrectly. I added a new way to get the current status of jobs.

You can see that job.name didn't match with process.env.GITHUB_JOB most part of time. Because of this, when we try to find step conclusion in array of steps, we'll get nothing, because jobs object is null.

There is another point here. This way bellow we don't get the success or skipped scenarios. We just have: in progress (default) and some failure cases. Following the docs, I assumed that we just have these steps conclusion: skipped, failure, success and cancelled.

So I created some logic to get the previous steps conclusion and I assumed that if nothing has failed we got some success scenario. I also discarding the current step, notification step. Most part of time we need to send a notification about previous steps or jobs and not to the current one.

example:

Before changes 😴

  let lastStep;
  const stoppedStep = job?.steps.find(
    (step: Octokit.ActionsListJobsForWorkflowRunResponseJobsItemStepsItem) =>
      step.conclusion === "failure" ||
      step.conclusion === "timed_out" ||
      step.conclusion === "cancelled" ||
      step.conclusion === "action_required"
  );
...

After changes: 😄

let lastStep = {} as Octokit.ActionsListJobsForWorkflowRunResponseJobsItemStepsItem
  let jobStartDate

  /**
   * We have to verify all jobs steps. We don't know
   * if users are using multiple jobs or not. Btw,
   * we don't need to check if GITHUB_JOB env is the 
   * same of the Octokit job name, because it is different.
   * 
   * @note We are using a quadratic way to search all steps.
   * But we have just a few elements, so this is not 
   * a performance issue
   * 
   * The conclusion steps, according to the documentation, are:
   * <success>, <cancelled>, <failure> and <skipped>
   */
  let abort = false
  for(let job of workflowJobs.data.jobs) {
    for(let step of job.steps) {
      // check if current step still running
      if (step.completed_at !== null) {
        lastStep = step
        jobStartDate = job.started_at
        // Some step/job has failed. Get out from here.
        if (step?.conclusion !== "success" && step?.conclusion !== "skipped") {
            abort = true
            break
        }
       /**  
        * If nothing has failed, so we have a success scenario
        * @note ignoring skipped cases. 
        */
        lastStep.conclusion = "success"
      }
    }
    // // Some step/job has failed. Get out from here.
    if (abort) break
   }

💚 How did you test it?

manually

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes

🔮 Next steps

📸 Screenshots / GIFs

Screen Shot 2021-04-22 at 12 47 33

Screen Shot 2021-04-22 at 12 51 41

Screen Shot 2021-04-22 at 14 50 19

@patrickpaulin patrickpaulin changed the title Fix: Only seeing "in progress" when running within a matrix Fix: Only seeing "in progress" status Apr 26, 2021
@TheFlow0360
Copy link

Any chance this is getting merged @aldwyn-acn ? I actually use the fork now because I didn't find another way to get the status working for reusable workflows.

@vimox-shah-genea
Copy link

@patrickpaulin It is not working for me. If it is working for everyone you should publish on market place. It will be easy for everyone.

@vimox-shah-genea
Copy link

vimox-shah-genea commented Mar 16, 2023

name: Build and Deploy 
'on':
  workflow_dispatch:
jobs:
  deploy_dev2:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: MS Teams Notification Setup
        uses: patrickpaulin/ms-teams-deploy-card@master
        if: always()
        with:
          github-token: ${{ secrets.TOKEN_PIPELINE }}
          webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
          environment: ${{ secrets.ENV }}
          card-layout-exit: complete
          show-on-failure: true
          allowed-file-len: 10
          timezone: Asia/Kolkata
      - name: Terraform Plan Status
        if: steps.plan.outcome == 'failure'
        run: exit 1
      - name: Build succeeded
        if: steps.plan.outcome == 'success'
        run: echo "App built and deployed" && exit 0

Above is my workflow file. I am not getting success status after completion of the job. Let me know If doing something wrong. @patrickpaulin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants