Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
190 lines (175 loc) · 8.76 KB
/
Copy pathaction.yml
File metadata and controls
190 lines (175 loc) · 8.76 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: 'Release Notes Manager'
description: 'Generate release notes or show how pull requests affect the release notes'
author: 'Ahmed Khaled ahmed.khaled.yousry@gmail.com'
inputs:
action-type:
description: "Type of action to perform (release or pr)"
required: true
default: 'release'
type: choice
options:
- release
- pr
new-release-tag:
description: "Tag name of the new release"
required: false
type: string
previous-release-reference:
description: "Tag name of the previous release or commit SHA right before the first commit in the new release"
required: false
type: string
release-notes-source:
description: "Release Notes Source"
required: false
default: 'Pull Requests'
type: choice
options:
- Commit Messages
- Pull Requests
pr-release-notes-mode:
description: "Release Notes Mode (only affects release notes generation if you chose source as Pull Requests)"
required: false
default: 'Full'
type: choice
options:
- Short
- Full
pull-request-number:
description: "Pull Request Number"
required: false
type: string
pull-request-trigger-event:
description: "Event that triggered the workflow when type is pr"
required: false
type: string
github-repository:
description: "The GitHub repository to use to get the pull requests' info, in the form owner/repo"
required: false
type: string
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# By default actions/checkout fetches the .git folder with only a small part of the git history
# usually the latest commit only, and my release notes script needs all the git history
# so I need to add this "fetch-depth: 0", which makes it fetch ALL the git history/commit messages
fetch-depth: 0
- name: Install libcurl
run: sudo apt install libcurl4-openssl-dev
shell: bash
- name: Download nlohmann json.hpp header file
run: wget https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp
shell: bash
- name: Build the script
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
run: g++ -o release_notes_generator "$GITHUB_ACTION_PATH"/Main.cpp "$GITHUB_ACTION_PATH"/Config.cpp "$GITHUB_ACTION_PATH"/Utils.cpp "$GITHUB_ACTION_PATH"/Format.cpp -lcurl -I.
shell: bash
- name: Copy script external configuration file from GitHub Action repo
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
run: cp "$GITHUB_ACTION_PATH"/release_notes_config.json .
shell: bash
# I am doing this extra step to make the workflow work with draft releases
# since a draft release's tag hasn't yet been created in the git history
# I can't use its tag in the release notes script as a reference to the last commit in the release
- name: Get the git reference (commit SHA/branch name) that the new release tag is on
if: ${{ inputs.action-type == 'release' }}
id: get-new-release-git-reference
# I check if the tag exists in the git history, >/dev/null is used to not show the output generated from the command
# if the tag exists then I get the commit SHA it's on, if not, then the release being created is a draft release
# with a new tag, so I get the commit SHA of the location the new tag will be added to, using the GitHub API
env:
NEW_RELEASE_TAG: ${{ inputs.new-release-tag }}
run: |
if git rev-parse --quiet --verify "$NEW_RELEASE_TAG" > /dev/null; then
NEW_RELEASE_REFERENCE=$(git rev-parse "$NEW_RELEASE_TAG")
else
NEW_RELEASE_REFERENCE=$(gh release view "$NEW_RELEASE_TAG" --json targetCommitish --jq .targetCommitish)
fi
echo "NEW_RELEASE_REFERENCE=$NEW_RELEASE_REFERENCE" >> "$GITHUB_OUTPUT"
shell: bash
- name: Validate the given previous release reference
if: ${{ inputs.action-type == 'release' }}
env:
PREVIOUS_RELEASE_REFERENCE: ${{ inputs.previous-release-reference }}
run: |
if ! git rev-parse --quiet --verify "$PREVIOUS_RELEASE_REFERENCE" > /dev/null; then
echo "Input error: Given previous reference '$PREVIOUS_RELEASE_REFERENCE' does not exist"
echo "Please make sure that the previous reference you input exists in this repository's git history"
exit 1
fi
shell: bash
# I am using checkout here so that it also works if the new release reference is a commit
# In the second checkout, I checkout back to the original branch that triggered the GitHub workflow
- name: If the new release reference is a branch (e.g. v1.4.x) ensure that I have a local branch tracking the remote branch
if: ${{ inputs.action-type == 'release' }}
env:
NEW_RELEASE_REFERENCE: ${{ steps.get-new-release-git-reference.outputs.NEW_RELEASE_REFERENCE }}
run: |
git checkout "$NEW_RELEASE_REFERENCE" > /dev/null 2>&1
git checkout ${{ github.ref_name }} > /dev/null 2>&1
shell: bash
- name: Run the release notes script with the needed parameters
if: ${{ inputs.action-type == 'release' }}
env:
RELEASE_NOTES_SOURCE: ${{ inputs.release-notes-source }}
PREVIOUS_RELEASE_REFERENCE: ${{ inputs.previous-release-reference }}
NEW_RELEASE_REFERENCE: ${{ steps.get-new-release-git-reference.outputs.NEW_RELEASE_REFERENCE }}
RELEASE_NOTES_MODE: ${{ inputs.pr-release-notes-mode }}
REPOSITORY: ${{ inputs.github-repository }}
run: ./release_notes_generator "$RELEASE_NOTES_SOURCE" "$PREVIOUS_RELEASE_REFERENCE" "$NEW_RELEASE_REFERENCE" "$GH_TOKEN" "$RELEASE_NOTES_MODE" "$REPOSITORY"
shell: bash
# GitHub's cli tool "gh" automatically uses the GITHUB_TOKEN environment variable
- name: Update the new GitHub release description with the generated markdown release notes
if: ${{ inputs.action-type == 'release' }}
env:
NEW_RELEASE_TAG: ${{ inputs.new-release-tag }}
run: gh release edit "$NEW_RELEASE_TAG" --notes-file release_notes.md
shell: bash
- name: Upload to the new GitHub release assets the generated HTML release notes
if: ${{ inputs.action-type == 'release' }}
# If HTML release notes are already added as an asset to the release, then uploading release_notes.html will give an error
# this means that the workflow is used to update release notes for an already existing release
# I check if the upload failed, and if yes, I delete the existing HTML file and upload the newly generated one
# I use "set +e" to disable the GitHub workflow to exit if any command fails, then I reenable it with "set -e"
env:
NEW_RELEASE_TAG: ${{ inputs.new-release-tag }}
run: |
set +e
gh release upload "$NEW_RELEASE_TAG" release_notes.html > /dev/null 2>&1
html_upload_status=$?
set -e
if [ $html_upload_status -ne 0 ]; then
gh release delete-asset "$NEW_RELEASE_TAG" release_notes.html
gh release upload "$NEW_RELEASE_TAG" release_notes.html
fi
shell: bash
- name: Run script to generate pull request change note
if: ${{ inputs.action-type == 'pr' }}
env:
PULL_REQUEST_NUMBER: ${{ inputs.pull-request-number }}
REPOSITORY: ${{ inputs.github-repository }}
run: ./release_notes_generator single_pr "$PULL_REQUEST_NUMBER" "$GH_TOKEN" "$REPOSITORY"
shell: bash
- name: Set extra comment message based on the trigger event type
if: ${{ inputs.action-type == 'pr' }}
id: set-extra-message
env:
TRIGGER_EVENT: ${{ inputs.pull-request-trigger-event }}
run: |
if [ "$TRIGGER_EVENT" = "opened" ]; then
echo "COMMENT_TEXT=Thank you for contributing!<br>Below is how your contribution will appear in Synfig's release notes. Review it and improve your pull request's title and description so that your contribution is clear. You can add images, videos, and anything else you want. Have fun!<br>" >> "$GITHUB_OUTPUT"
elif [ "$TRIGGER_EVENT" = "edited" ]; then
echo "COMMENT_TEXT=Thank you for attempting to improve your contribution description!<br>Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!<br>" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Comment in the pull request with the generated change note and extra message
if: ${{ inputs.action-type == 'pr' }}
env:
COMMENT_TEXT: ${{ steps.set-extra-message.outputs.COMMENT_TEXT }}
PULL_REQUEST_NUMBER: ${{ inputs.pull-request-number }}
run: gh pr comment "$PULL_REQUEST_NUMBER" --body "$COMMENT_TEXT$(cat release_notes.md)"
shell: bash