Skip to content

Commit

Permalink
Merge pull request #371 from JJRcop/makers-set-version
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 authored Jul 30, 2023
2 parents 81dd3ba + ab0a9de commit 9f21e66
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
3 changes: 1 addition & 2 deletions extension/src/setup/instructions.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@
<li>Make sure <a href="https://github.com/sagiegurari/cargo-make" target="_blank"><kbd>cargo-make</kbd></a> and (on Windows) <a href="https://wixtoolset.org/releases/" target="_blank">WiX Toolset</a> are installed.</li>
<li>Clone the <a href="https://github.com/filips123/PWAsForFirefox" target="_blank">repository</a> and <kbd>cd</kbd> into the <kbd>native</kbd> directory.</li>
<li>Checkout the <kbd class="connector-repository-tag"></kbd> tag.</li>
<li>Modify <kbd>version</kbd> field inside <kbd>Cargo.toml</kbd> to <kbd class="connector-project-version"></kbd>.</li>
<li>Modify <kbd>DISTRIBUTION_VERSION</kbd> variable inside <kbd>userchrome/profile/chrome/pwa/chrome.jsm</kbd> to <kbd class="connector-project-version"></kbd>.</li>
<li>Prepare the source code for building: <kbd>makers set-version</kbd></li>
<li>Build and install the project: <kbd>makers install</kbd></li>
<li>After the project is installed, you should be automatically proceeded to the next step. If nothing changes after around 30 seconds, restart the browser.</li>
</ol>
Expand Down
7 changes: 7 additions & 0 deletions native/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ script = [
"echo FATAL: This environment does not support automatic installation using cargo-make",
"exit 1"
]

### OTHERS ###

[tasks.set-version]
description = "Set version to given version or current git tag"
script_runner="@duckscript"
script = "!include_files ./set-version.ds"
3 changes: 1 addition & 2 deletions native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ cd PWAsForFirefox/native
# Set the VERSION environment variable
# And run the following commands to set version
git checkout tags/v${VERSION}
sed -i "s/version = \"0.0.0\"/version = \"$VERSION\"/g" Cargo.toml
sed -i "s/DISTRIBUTION_VERSION = '0.0.0'/DISTRIBUTION_VERSION = '$VERSION'/g" userchrome/profile/chrome/pwa/chrome.jsm
makers set-version ${VERSION}

# Build and install the project
makers install
Expand Down
52 changes: 52 additions & 0 deletions native/set-version.ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# For Makefile.toml, but could be run on its own
# Sets version strings in configuration files to first argument or from git

fn <scope> replace_version
content = set ${1}
version_find = set ${2}
pwa_ver = set ${3}
quote_find = set ${4}
version_find_length = strlen ${version_find}
back_index = indexof ${content} ${version_find}
back_index = calc ${back_index} + ${version_find_length}
back = substring ${content} ${back_index}
back_length = strlen ${back}
front = substring ${content} -${back_length}
quote_find_index = indexof ${back} ${quote_find}
back = substring ${back} ${quote_find_index}
content = concat ${front} ${pwa_ver} ${back}
return ${content}
end

if ${1}
# Use first argument
pwa_ver = set ${1}
else
# No argument, find tag from git
git_tag = exec git describe --tags --abbrev=0
assert_eq ${git_tag.code} 0 "No version provided to task and unable to retrieve git tag"
pwa_ver = trim ${git_tag.stdout}
release git_tag
unset git_tag
end
# Remove single leading v if it exists
if starts_with ${pwa_ver} "v"
pwa_ver = substring ${pwa_ver} 1
end

cargo_toml_path = set "./Cargo.toml"
chrome_jsm_path = set "./userchrome/profile/chrome/pwa/chrome.jsm"
cargo_toml_exists = is_file ${cargo_toml_path}
chrome_jsm_exists = is_file ${chrome_jsm_path}
if ${cargo_toml_exists} and ${chrome_jsm_exists}
echo "Replacing version = \"${pwa_ver}\""
cargo_toml = readfile ${cargo_toml_path}
cargo_toml = replace_version ${cargo_toml} "# Version will be set by CI from the Git tag when building and releasing\nversion = \"" ${pwa_ver} "\""
writefile ${cargo_toml_path} ${cargo_toml}
echo "Replacing DISTRIBUTION_VERSION = '${pwa_ver}'"
chrome_jsm = readfile ${chrome_jsm_path}
chrome_jsm = replace_version ${chrome_jsm} "DISTRIBUTION_VERSION = '" ${pwa_ver} "'"
writefile ${chrome_jsm_path} ${chrome_jsm}
else
assert_fail "Unable to locate ./Cargo.toml and ./userchrome/profile/chrome/pwa/chrome.jsm"
end

0 comments on commit 9f21e66

Please sign in to comment.