Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ import runs from './runs.js'
// sleep function
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

// getting branch on pull_request event is different from push
const getBranch = (payload) => {
if (payload.pull_request) {
return payload.pull_request.head.ref
}
return payload.ref.replace('refs/heads/', '')
}

export default async function ({ token, delay, timeout }) {
let timer = 0

// init octokit
const octokit = github.getOctokit(token)

// extract runId
const { runId: run_id } = github.context
const { payload, runId: run_id } = github.context

// get workflow id and created date from run id
const { data: { workflow_id, run_started_at } } = await octokit.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}', {
Expand All @@ -30,8 +38,13 @@ export default async function ({ token, delay, timeout }) {

core.info(`searching for workflow runs before ${before}`)

// branch to which to scope workflow runs
const branch = getBranch(payload)

core.info(`searching for workflow runs for branch ${branch}`)

// get previous runs
let waiting_for = await runs({ octokit, run_id, workflow_id, before })
let waiting_for = await runs({ octokit, workflow_id, run_id, branch, before })

if (waiting_for.length === 0) {
core.info('no active run of this workflow found')
Expand Down
5 changes: 3 additions & 2 deletions src/lib/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { inspect } from 'util'
import core from '@actions/core'
import github from '@actions/github'

export default async function ({ octokit, workflow_id, run_id, before }) {
export default async function ({ octokit, workflow_id, run_id, branch, before }) {
// get current run of this workflow
const { data: { workflow_runs } } = await octokit.request('GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs', {
...github.context.repo,
workflow_id
workflow_id,
branch
})

// find any instances of the same workflow
Expand Down