name: Shared - Create Issue on Failure
on: workflow_call: inputs: status: description: 'Pipeline status: success, failure, cancelled' required: true type: string environment: description: 'Deployment environment (develop, prod)' required: false type: string default: '' version: description: 'Release version (e.g., 1.2.3)' required: false type: string default: '' changelog: description: 'Release changelog (commit list)' required: false type: string default: '' message: description: 'Custom message to include in the issue body' required: false type: string default: '' labels: description: 'Labels for the GitHub issue (comma-separated)' required: false type: string default: 'bug,pipeline-failure'
jobs: create-issue: name: Create Issue if: inputs.status == 'failure' runs-on: ubuntu-latest timeout-minutes: 2
steps: - name: Create GitHub issue on failure env: GH_TOKEN: ${{ github.token }} ENVIRONMENT: ${{ inputs.environment }} VERSION: ${{ inputs.version }} CHANGELOG: ${{ inputs.changelog }} CUSTOM_MESSAGE: ${{ inputs.message }} REPO: ${{ github.repository }} BRANCH: ${{ github.ref_name }} ACTOR: ${{ github.actor }} SERVER_URL: ${{ github.server_url }} RUN_ID: ${{ github.run_id }} ISSUE_LABELS: ${{ inputs.labels }} run: | set -euo pipefail
ISSUE_TITLE="Pipeline failure: ${REPO##*/} (${BRANCH}) — ${ENVIRONMENT:-no-env}"
ISSUE_BODY="## Pipeline Failure\n\n" ISSUE_BODY+="| Field | Value |\n" ISSUE_BODY+="|-------|-------|\n" ISSUE_BODY+="| **Repository** | [${REPO}](${SERVER_URL}/${REPO}) |\n" ISSUE_BODY+="| **Branch** | \`${BRANCH}\` |\n" ISSUE_BODY+="| **Environment** | ${ENVIRONMENT:-N/A} |\n" ISSUE_BODY+="| **Actor** | @${ACTOR} |\n" ISSUE_BODY+="| **Run** | [View workflow run](${SERVER_URL}/${REPO}/actions/runs/${RUN_ID}) |\n" ISSUE_BODY+="| **Commit** | \`${GITHUB_SHA:0:7}\` |\n"
if [ -n "$CUSTOM_MESSAGE" ]; then ISSUE_BODY+="\n### Message\n${CUSTOM_MESSAGE}\n" fi
if [ -n "$VERSION" ] && [ -n "$CHANGELOG" ]; then ISSUE_BODY+="\n### Changelog (v${VERSION})\n${CHANGELOG}\n" fi
ISSUE_BODY+="\n---\n*Auto-generated by CI pipeline*"
# Build label args LABEL_ARGS="" if [ -n "$ISSUE_LABELS" ]; then IFS=',' read -ra LABELS <<< "$ISSUE_LABELS" for LABEL in "${LABELS[@]}"; do LABEL=$(echo "$LABEL" | xargs) LABEL_ARGS+=" --label \"$LABEL\"" done fi
# Create issue and assign to actor ISSUE_URL=$(eval gh issue create \ --repo "$REPO" \ --title "\"$ISSUE_TITLE\"" \ --body "\"$(echo -e "$ISSUE_BODY")\"" \ --assignee "$ACTOR" \ $LABEL_ARGS 2>&1) || true
if [ -n "$ISSUE_URL" ]; then echo "GitHub issue created: $ISSUE_URL" else echo "::warning::Failed to create GitHub issue" fi Shared (cross-cutting)· Reusable workflow ·on: workflow_call
Shared Create Issue On Failure
Shared - Create Issue on Failure
.github/workflows/shared-create-issue-on-failure.yml