-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
122 lines (113 loc) · 4.79 KB
/
action.yml
File metadata and controls
122 lines (113 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Auto Release Description Generator
description: Automatically generate release descriptions using AI based on git diff
inputs:
gemini-api-key:
description: 'The API key for the Gemini API'
required: true
github-token:
description: 'GitHub token for release operations'
required: true
pr-number:
description: 'Pull request number'
required: true
jira-ticket-url-prefix:
description: 'JIRA ticket URL prefix (e.g., https://company.atlassian.net/browse/)'
required: false
default: 'https://virdocs.atlassian.net/browse/'
ignore-files:
description: 'Comma-separated list of files to ignore in the diff (e.g., package-lock.json,yarn.lock)'
required: false
default: 'package-lock.json,yarn.lock,pnpm-lock.yaml,composer.lock,Gemfile.lock,poetry.lock,Pipfile.lock'
outputs:
description:
description: 'The generated release description'
value: ${{ steps.generate_description.outputs.description }}
updated:
description: 'Whether the release description was updated'
value: ${{ steps.update_pr.outputs.updated }}
runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: Install dependencies
shell: bash
run: |
npm install
working-directory: ${{ github.action_path }}
- name: Generate PR diff from GitHub
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
PR_NUMBER: ${{ inputs.pr-number }}
IGNORE_FILES: ${{ inputs.ignore-files }}
run: |
# Get the PR diff directly from GitHub using gh CLI
gh pr diff ${{ inputs.pr-number }} > pr.diff
echo "Generated diff file with $(wc -l < pr.diff) lines"
# Filter out ignored files from the diff
if [ -n "$IGNORE_FILES" ]; then
echo "Filtering out ignored files: $IGNORE_FILES"
node ${{ github.action_path }}/filter_diff.js pr.diff "$IGNORE_FILES"
echo "Filtered diff file now has $(wc -l < pr.diff) lines"
fi
- name: Generate PR description
id: generate_description
shell: bash
env:
GEMINI_API_KEY: ${{ inputs.gemini-api-key }}
GH_TOKEN: ${{ inputs.github-token }}
PR_NUMBER: ${{ inputs.pr-number }}
JIRA_TICKET_URL_PREFIX: ${{ inputs.jira-ticket-url-prefix }}
run: |
# Generate description using AI (with chunking support for large diffs)
# The script writes description to stdout, errors to stderr
if ! node ${{ github.action_path }}/generate_pr_description.js pr.diff > release_description.md 2>generate_errors.log; then
echo "Error: Failed to generate release description" >&2
cat generate_errors.log >&2
exit 1
fi
# Get existing PR body to preserve all content
gh pr view ${{ inputs.pr-number }} --json body --jq '.body' > pr_body.md || {
echo "Error: Failed to get PR body" >&2
exit 1
}
# Insert the generated description into the existing PR body
# This preserves all existing content and uses comment tags for auto-generated section
node ${{ github.action_path }}/insert_release_description.js pr_body.md release_description.md > new_body.md || {
echo "Error: Failed to insert release description" >&2
exit 1
}
# Output the description for other steps to use
# Use a unique delimiter to avoid conflicts with content that might contain "EOF"
# Generate delimiter once and ensure it's used consistently
DELIMITER="GITHUB_OUTPUT_DESCRIPTION_$(date +%s)_$$"
{
echo "description<<${DELIMITER}"
# Ensure file exists and is readable
if [ -f release_description.md ] && [ -s release_description.md ]; then
# Output the file content
cat release_description.md
# Always ensure newline before delimiter (GitHub Actions requirement)
# This handles cases where file doesn't end with newline
printf '\n'
else
echo "Error: release_description.md is missing or empty" >&2
echo "Error: release_description.md is missing or empty"
fi
# Closing delimiter must match exactly - use the same variable
echo "${DELIMITER}"
} >> $GITHUB_OUTPUT
- name: Update PR description
id: update_pr
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
PR_NUMBER: ${{ inputs.pr-number }}
run: |
# Update PR with merged body (preserves all existing content)
gh pr edit ${{ inputs.pr-number }} --body-file new_body.md
echo "updated=true" >> $GITHUB_OUTPUT
echo "Successfully updated PR #${{ inputs.pr-number }} description"