-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
145 lines (124 loc) · 5.47 KB
/
action.yaml
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: "Generate GitHub Release Notes"
description: "Generate GitHub release notes from git commits"
inputs:
previous_tag:
description: "The previous tag to compare against"
required: true
repo_url:
description: "The URL of the repository"
required: true
outputs:
new_version:
description: "Incremented github tag number"
value: ${{ steps.increment_version.outputs.new_version }}
release_notes:
description: "Incremented github tag number"
value: "${{ steps.generate_notes.outputs.release_notes }}"
bugsnag_version:
description: "The app version to use for Bugsnag"
value: ${{ steps.compute_bugsnag_app_version.outputs.app_version }}
runs:
using: "composite"
steps:
- name: Increment version
id: increment_version
shell: bash
run: |
# Split the version into major, minor, patch components
IFS='.' read -r major minor patch <<< "${{ inputs.previous_tag }}"
# Increment the patch number
patch=$((patch + 1))
new_version="$major.$minor.$patch"
echo "new_version=${new_version}" >> $GITHUB_ENV
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
- name: Generate Release Notes
id: generate_notes
shell: bash
run: |
previous_tag="${{ inputs.previous_tag }}"
repo_url="${{ inputs.repo_url }}"
# Fetch all commits for processing
pr_commits=()
formatted_notes=""
first_merge_commit_skipped=false
all_commits=$(git log "$previous_tag"..HEAD --pretty=format:"%h|%p|%s|%an|%ae")
# Check if there are no commits
if [[ -z "$all_commits" || "$all_commits" =~ ^[[:space:]]*$ ]]; then
echo "No commits found between ${previous_tag} and HEAD."
formatted_notes="No new commits"
else
# Process the commit data to capture PR-related commits
while IFS='|' read -r commit_hash parent_hashes commit_message commit_author commit_email; do
# Check for "Merge pull request" in commit message
if echo "$commit_message" | grep -q "Merge pull request"; then
# Skip the first "Merge pull request" commit
if [ "$first_merge_commit_skipped" = false ]; then
first_merge_commit_skipped=true
continue
fi
pr_number=$(echo "$commit_message" | grep -oE "#[0-9]+")
pr_link="[${pr_number}](${repo_url}/pull/${pr_number:1})"
# Extract the parent hashes
read -r start_commit end_commit <<< "$parent_hashes"
# Track commits related to this PR
should_track=false
while IFS='|' read -r inner_commit_hash inner_rest; do
# Start tracking from the end_commit
if [[ "$inner_commit_hash" == "$end_commit" ]]; then
should_track=true
fi
# Stop tracking at the start_commit
if [[ "$inner_commit_hash" == "$start_commit" ]]; then
break
fi
# If tracking, add commit to PR-related array
if [ "$should_track" = true ]; then
pr_commits+=("$inner_commit_hash")
fi
done <<< "$all_commits"
fi
done <<< "$all_commits"
# Generate output for each commit
while IFS='|' read -r commit_hash _ commit_message commit_author commit_email; do
# Replace backticks in the commit message directly
commit_message=$(echo "$commit_message" | sed 's/`//g')
if [[ "$commit_author" =~ \ ]]; then
github_author="${commit_author} (${commit_email})"
else
github_author="@${commit_author}"
fi
# Append the PR link if the commit is part of the PR-related commits
if [[ "$commit_message" == *"Merge pull request"* || "$commit_message" == *"Revert"* ]]; then
formatted_notes="${formatted_notes}"
elif [[ " ${pr_commits[@]} " =~ " ${commit_hash} " ]]; then
formatted_notes="${formatted_notes}\n- ${commit_hash:0:7} - ${commit_message} by ${github_author} in ${pr_link}"
else
formatted_notes="${formatted_notes}\n- ${commit_hash:0:7} - ${commit_message} by ${github_author}"
fi
done <<< "$all_commits"
fi
if [[ -z "$formatted_notes" ]]; then
formatted_notes="No new commits"
fi
# Export the formatted notes to the GitHub environment
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo -e "${formatted_notes}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Compute Bugsnag App Version
id: compute_bugsnag_app_version
shell: bash
run: |
# Assign new_version from earlier step output to a shell variable
new_version="${{ steps.increment_version.outputs.new_version }}"
release_notes="${{ steps.generate_notes.outputs.release_notes }}"
# Initialize app_version with new_version
app_version="$new_version"
# Conditional assignment based on release_notes output
if [[ "$release_notes" == "No new commits" ]]; then
app_version="${{ inputs.previous_tag }}"
fi
# Set the app_version as an output
echo "app_version=$app_version" >> $GITHUB_OUTPUT
# Log for debug purposes
echo "Release notes: $release_notes"
echo "Bugsnag version: $app_version"