Pack new version #67
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pack new version | |
on: | |
workflow_dispatch: | |
inputs: | |
upload_cws: | |
type: boolean | |
description: Upload to CWS | |
default: true | |
publish_cws: | |
type: boolean | |
description: Publish to CWS | |
default: true | |
publish_amo: | |
type: boolean | |
description: Publish to AMO | |
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(\".\")")" | |
# Export version for future tasks | |
export version | |
echo "version=$version" >> "$GITHUB_ENV" | |
# Create release body | |
echo "$firstEntry" | "${jqCommand}" -j " | |
.logs as \$clFirstEntryLogs | ( | |
\$clFirstEntryLogs | | |
if ((.features | length) > 0) then | |
(.features | | |
map(\"* \" + .message + \"\n\") | | |
. |= [\"### Features\n\"] + . | | |
. |= . + [\"\n\"] | | |
join(\"\")) | |
else (\"\") | |
end | |
), | |
( | |
\$clFirstEntryLogs | | |
if ((.fixes | length) > 0) then | |
(.fixes | | |
map(\"* \" + .message + \"\n\") | | |
. |= [\"### Fixes\n\"] + . | | |
. |= . + [\"\n\"] | | |
join(\"\")) | |
else (\"\") | |
end | |
), | |
( | |
\$clFirstEntryLogs | | |
if ((.changes | length) > 0) then | |
(.changes | | |
map(\"* \" + .message + \"\n\") | | |
. |= [\"### Changes\n\"] + . | | |
. |= . + [\"\n\"] | | |
join(\"\")) | |
else (\"\") | |
end | |
), | |
( | |
\$clFirstEntryLogs | | |
if ((.removed | length) > 0) then | |
(.removed | | |
map(\"* \" + .message + \"\n\") | | |
. |= [\"### Removed\n\"] + . | | |
. |= . + [\"\n\"] | | |
join(\"\")) | |
else (\"\") | |
end | |
) | |
" >> "$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: Upload an extension to Chrome Web Store | |
uses: cardinalby/[email protected] | |
if: ${{ inputs.upload_cws }} | |
with: | |
zipFilePath: versions/torntools_${{ env.version }}_chrome.zip | |
extensionId: 'hjpaapdjcgbmeikfnahipphknonhlhib' | |
apiClientId: ${{ secrets.CHROME_CLIENT_ID }} | |
apiClientSecret: ${{ secrets.CHROME_SECRET }} | |
apiRefreshToken: ${{ secrets.CHROME_REFRESH_TOKEN }} | |
- name: Publish an extension on Chrome Web Store | |
uses: cardinalby/[email protected] | |
if: ${{ inputs.publish_cws }} | |
id: publish_step | |
with: | |
extensionId: 'hjpaapdjcgbmeikfnahipphknonhlhib' | |
apiClientId: ${{ secrets.CHROME_CLIENT_ID }} | |
apiClientSecret: ${{ secrets.CHROME_SECRET }} | |
apiRefreshToken: ${{ secrets.CHROME_REFRESH_TOKEN }} | |
- name: Create Firefox .xpi | |
id: web-ext-build | |
uses: kewisch/[email protected] | |
with: | |
cmd: build | |
source: extension | |
artifacts: versions | |
- name: Sign Firefox .xpi | |
uses: kewisch/action-web-ext@v1 | |
if: ${{ inputs.publish_amo }} | |
with: | |
cmd: sign | |
artifacts: versions | |
source: ${{ steps.web-ext-build.outputs.target }} | |
channel: listed | |
apiKey: ${{ secrets.FIREFOX_JWT_ISSUER }} | |
apiSecret: ${{ secrets.FIREFOX_JWT_SECRET }} | |
- name: Github Release | |
uses: ncipollo/release-action@v1 | |
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: 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 | . + 1")" | |
newVersionBuild="0" | |
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="[![GitHub Release Date](https://img.shields.io/static/v1?label=RELEASE%20DATE\\\\&message=$(date "+%B, %-d$(DaySuffix). %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 }}" |