-
Notifications
You must be signed in to change notification settings - Fork 71
230 lines (204 loc) · 9.25 KB
/
pack.yml
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Pack new version
on:
workflow_dispatch:
inputs:
release_github:
type: boolean
description: Release on Github
default: true
publish_cws:
type: boolean
description: Publish to Chrome Web Store
default: true
publish_amo:
type: boolean
description: Publish to Firefox Browser Add-ons
default: true
publish_mea:
type: boolean
description: Publish to Microsoft Edge Add-ons
default: true
pre_release:
type: boolean
description: Make a beta release
default: false
commit_beta_changes:
type: boolean
description: Commit beta versions
default: true
jobs:
publish:
environment: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Update the changelog.json
run: |
# Install jq
sudo apt-get install jq
# Setup variables
jqCommand="jq"
changelogPath="./extension/changelog.json"
releaseBodyFile="./releaseBody.md"
tmpFile="tmp.tmp"
firstEntry="$("${jqCommand}" -j ".[0]" "${changelogPath}")"
version="$(echo "$firstEntry" | "${jqCommand}" -j "[ .version | to_entries[] | .value ] | join(\".\")")"
manifestVersion="$("${jqCommand}" -j ".version" < ./extension/manifest.json)"
[ $version != $manifestVersion ] && echo "Manifest version and changelog version are not same. Please verify again." && exit 1
# Export version for future tasks
export version
echo "version=$version" >> "$GITHUB_ENV"
# Create release body
echo "$firstEntry" | "${jqCommand}" -j '
def process_category($keyAndTitle):
. as $logs |
$keyAndTitle | split(";")[0] as $key |
$keyAndTitle | split(";")[1] as $title |
if ($logs[$key] | length) > 0 then
($logs[$key] |
map("* " +
(if .message | type == "string" then .message
elif .message | type == "array" then .message | join(" ")
else .message | tostring
end
) +
"\n") |
. |= [$title] + . |
. |= . + ["\n"] |
join(""))
else ("")
end;
.logs |
process_category("features;### Features\n"),
process_category("fixes;### Fixes\n"),
process_category("changes;### Changes\n"),
process_category("removed;### Removed\n")
' >> "$releaseBodyFile"
# Update changelog.json date and remove empty features, fixes and changes entries
"${jqCommand}" -j ".[0].date |= \"$(date +"%Y/%m/%d")\"" "${changelogPath}" > "${tmpFile}" && mv "${tmpFile}" "${changelogPath}"
"${jqCommand}" -j '. as $all | $all[0].logs | delpaths([keys_unsorted[] | select(($all[0].logs[.] | length) == 0) | [.]]) | . as $new | $all | .[0].logs |= $new' "${changelogPath}" > "${tmpFile}" && mv "${tmpFile}" "${changelogPath}"
- name: Format with prettier
uses: creyD/[email protected]
with:
prettier_options: --config .prettierrc --write . --list-different
commit_options: --dry-run
push_options: --dry-run
- name: Create zip files for CWS and AMO
run: |
# Setup variables
jqCommand="jq"
manifestPath="./extension/manifest.json"
manifestCopyPath="manifest.json.orig"
# Create manifest copy
cp "${manifestPath}" "${manifestCopyPath}"
# Remove "background.scripts" from manifest (copy) for CWS
"${jqCommand}" -j "del(.background.scripts)" "${manifestCopyPath}" > "${manifestPath}"
# Create and move extension zip file
cd extension || exit 1
zip -q -r "../torntools_${version}_chrome.zip" .
cd ..
# Remove "background.service_worker" from manifest (copy) for AMO
"${jqCommand}" -j "del(.background.service_worker)" "${manifestCopyPath}" > "${manifestPath}"
# Create and move extension zip file
cd extension || exit 2
zip -q -r "../torntools_${version}_firefox.zip" .
cd ..
[ ! -d "versions" ] && mkdir versions
mv "torntools_${version}_chrome.zip" ./versions/
mv "torntools_${version}_firefox.zip" ./versions/
- name: Github Release
uses: ncipollo/release-action@v1
if: ${{ inputs.release_github }}
with:
artifacts: "versions/torntools_${{ env.version }}_chrome.zip,versions/torntools_${{ env.version }}_firefox.zip,${{ steps.web-ext-build.outputs.target }}"
name: "Release: v${{ env.version }}"
tag: "${{ env.version }}"
bodyFile: "./releaseBody.md"
token: ${{ secrets.GH_TOKEN }}
prerelease: ${{ inputs.pre_release }}
- name: Release on Chrome Web Store
uses: wdzeng/chrome-extension@v1
if: ${{ inputs.publish_cws }}
with:
extension-id: "hjpaapdjcgbmeikfnahipphknonhlhib"
zip-path: versions/torntools_${{ env.version }}_chrome.zip
client-id: ${{ secrets.CHROME_CLIENT_ID }}
client-secret: ${{ secrets.CHROME_SECRET }}
refresh-token: ${{ secrets.CHROME_REFRESH_TOKEN }}
- name: Release on Firefox Browser Add-ons
uses: wdzeng/firefox-addon@v1
if: ${{ inputs.publish_amo }}
with:
addon-guid: "{3754707b-1aa4-4c6f-96e7-5b1cdc1de5f9}"
jwt-issuer: ${{ secrets.FIREFOX_JWT_ISSUER }}
jwt-secret: ${{ secrets.FIREFOX_JWT_SECRET }}
xpi-path: versions/torntools_${{ env.version }}_firefox.zip
- name: Release on Microsoft Edge Add-ons
uses: wdzeng/edge-addon@v2
if: ${{ inputs.publish_mea }}
with:
product-id: ${{ secrets.MICROSOFT_PRODUCT_ID }}
client-id: ${{ secrets.MICROSOFT_CLIENT_ID }}
api-key: ${{ secrets.MICROSOFT_API_KEY }}
zip-path: versions/torntools_${{ env.version }}_chrome.zip
- name: Delete temporary files
run: |
rm -f ./releaseBody.md
rm -rf versions
- name: Change manifest to beta version
run: |
# Setup variables again
DaySuffix() {
case $(date +%-d) in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
jqCommand="jq"
tmpFile="tmp.tmp"
readmePath="README.md"
manifestPath="./extension/manifest.json"
manifestCopyPath="manifest.json.orig"
changelogPath="./extension/changelog.json"
newVersionMajor="$(echo -n "\"${version}\"" | "${jqCommand}" -j "split(\".\")[0] | tonumber | .")"
newVersionMinor="$(echo -n "\"${version}\"" | "${jqCommand}" -j "split(\".\")[1] | tonumber | .")"
newVersionBuild="$(echo -n "\"${version}\"" | "${jqCommand}" -j "split(\".\")[2] | tonumber | . + 1")"
newVersion="${newVersionMajor}.${newVersionMinor}.${newVersionBuild}"
newVersionTitle="Beta"
export newVersion
echo "newVersion=$newVersion" >> "$GITHUB_ENV"
# Restore original manifest
mv "${manifestCopyPath}" "${manifestPath}"
# Add beta changelog entry
"${jqCommand}" -r --indent 0 "
. |=
[{
\"version\": { \"major\": ${newVersionMajor}, \"minor\": ${newVersionMinor}, \"build\": ${newVersionBuild} },
\"title\": \"${newVersionTitle}\",
\"date\": false,
\"logs\": {
\"features\": [],
\"fixes\": [],
\"changes\": [],
\"removed\": []
}
}] +
." "${changelogPath}" > "${tmpFile}" && mv "${tmpFile}" "${changelogPath}"
# Change manifest to next version
"${jqCommand}" -r --indent 0 ".[\"version\"] |= \"${newVersion}\"" "${manifestPath}" > "${tmpFile}" && mv "${tmpFile}" "${manifestPath}"
# Update README.md with new version packaged date (today, the day the action is run)
ghReleaseDateMarkdown="[. %Y" | "${jqCommand}" --raw-input --raw-output '. | @uri')\\\\&color=%23acea00\\\\&style=for-the-badge)](https://github.com/Mephiles/torntools_extension/releases/latest)<!---A pointer for bash-->"
awk "/.*A pointer for bash.*/ {sub(/.*/, \"${ghReleaseDateMarkdown}\")} {print}" "${readmePath}" > "${tmpFile}" && mv "${tmpFile}" "${readmePath}"
- name: Format with prettier
uses: creyD/[email protected]
with:
prettier_options: --config .prettierrc --write . --list-different
commit_options: --dry-run
push_options: --dry-run
- name: Add & Commit
uses: EndBug/[email protected]
if: ${{ inputs.commit_beta_changes }}
with:
message: "Pack v${{ env.version }} and update to v${{ env.newVersion }}"