Skip to content
Merged
Changes from 1 commit
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
150 changes: 150 additions & 0 deletions .github/workflows/open-issue-on-failure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#
# Copyright 2026 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Reusable workflow that opens (or comments on) a tracking issue when a
# release/publish job fails. Call it from a job gated with `if: failure()`
# in the workflow that runs the release. The issue is opened in the calling
# repository (context.repo). To avoid duplicates, if an open issue with the
# same title already exists, a comment is added to it instead of opening a
# new one.

name: Open issue on failure

on:
workflow_call:
inputs:
title:
required: true
type: string
description: Title of the issue to open.
body:
required: false
type: string
default: ''
description: Extra context appended to the generated issue body.
labels:
required: false
type: string
default: ''
description: Comma-separated list of labels to apply to the issue.
mention:
required: false
type: string
default: ''
description: >
Space-separated @-handles or teams to mention in the issue body,
e.g. "@dapr/maintainers-dapr @dapr/approvers-dapr".
secrets:
dapr_bot_token:
required: false
description: >
Token used to author the issue. When omitted, the built-in
GITHUB_TOKEN is used (needs issues: write on the calling job).

permissions: {}

jobs:
open-issue:
name: Open issue on failure
runs-on: ubuntu-latest
permissions:
issues: write
actions: read # to list the run's failed jobs and link to them
steps:
- uses: actions/github-script@v7
env:
TITLE: ${{ inputs.title }}
EXTRA_BODY: ${{ inputs.body }}
LABELS: ${{ inputs.labels }}
MENTION: ${{ inputs.mention }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
WORKFLOW: ${{ github.workflow }}
REF: ${{ github.ref_name }}
SHA: ${{ github.sha }}
with:
github-token: ${{ secrets.dapr_bot_token || github.token }}
script: |
const { TITLE, EXTRA_BODY, LABELS, MENTION, RUN_URL, WORKFLOW, REF, SHA } = process.env;
const { owner, repo } = context.repo;
const labels = LABELS.split(',').map(l => l.trim()).filter(Boolean);
// Stable marker so we can re-find this issue even if the title changes.
const marker = `<!-- open-issue-on-failure:${TITLE} -->`;
Comment thread
cicoyle marked this conversation as resolved.
Outdated

// Reusable workflows share the caller's run_id, so this lists every
// job in the release run. Drives both the failed-job links and the
// "already retried" note. Empty on error (needs actions: read).
Comment thread
cicoyle marked this conversation as resolved.
Outdated
let failed = [];
try {
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
owner, repo, run_id: context.runId, per_page: 100,
});
failed = jobs.filter(j => ['failure', 'cancelled', 'timed_out'].includes(j.conclusion));
} catch (e) {
core.warning(`Could not list failed jobs (needs actions: read): ${e.message}`);
}
const failedJobs = failed.length
? ['', '**Failed jobs:**', ...failed.map(j => `- [${j.name}](${j.html_url})`)].join('\n')
: '';

const runContext = [
`- **Workflow run:** ${RUN_URL}`,
`- **Ref:** \`${REF}\``,
`- **Commit:** \`${SHA}\``,
].join('\n');

const issueBody = [
MENTION.trim(),
`A release/publish job failed in **${WORKFLOW}**.`,
'',
runContext,
Comment thread
cicoyle marked this conversation as resolved.
failedJobs,
EXTRA_BODY.trim() && `\n${EXTRA_BODY.trim()}`,
'',
marker,
].filter(Boolean).join('\n');

// Dedup: find an existing open issue with the same title (or marker).
const open = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: 'open',
labels: labels.join(',') || undefined,
per_page: 100,
});
Comment thread
cicoyle marked this conversation as resolved.
const match = open.find(i =>
!i.pull_request && (i.title === TITLE || (i.body || '').includes(marker)));

if (match) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: match.number,
body: [
'The release/publish job failed again.',
'',
runContext,
failedJobs,
].filter(Boolean).join('\n'),
});
core.notice(`Commented on existing issue #${match.number}`);
return;
}

const created = await github.rest.issues.create({
owner,
repo,
title: TITLE,
body: issueBody,
labels,
});
core.notice(`Opened issue #${created.data.number}`);