diff --git a/.gitignore b/.gitignore index 1ba24b87..af701185 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ compiler/**/*.js .*.generated.ts .tmp/ .DS_Store +.build_cache/ diff --git a/scripts/authors.sh b/scripts/authors.sh index d0d9ead4..415d1d84 100755 --- a/scripts/authors.sh +++ b/scripts/authors.sh @@ -4,10 +4,18 @@ set -e err() { echo "error: line $(caller)"; } trap err ERR +mkdir -p .build_cache cd src/static authors="../../build/static/authors.html" sed "/REPLACETHIS/,$ d" authors.html > "$authors" -git shortlog -sn HEAD | cut -c8- | awk '!seen[$0]++' | sed 's/^/
/' | sed 's/$/<\/p>/' >> "$authors" + +# If we're in a git repo, refresh the cache +if [ -d "../../.git/" ]; then + git shortlog -sn HEAD | cut -c8- | awk '!seen[$0]++' | sed 's/^/
/' | sed 's/$/<\/p>/' > ../../.build_cache/authors +fi + +cat ../../.build_cache/authors >> "$authors" + sed "1,/REPLACETHIS/ d" authors.html >> "$authors" diff --git a/scripts/sign b/scripts/sign index 194c3187..25bf30c3 100755 --- a/scripts/sign +++ b/scripts/sign @@ -4,7 +4,7 @@ set -e sign_and_submit() { # Don't trust the return value of web-ext sign. - (source AMOKEYS && (web-ext sign -s build --api-key $AMOKEY --api-secret $AMOSECRET "$@" || true)) + (source AMOKEYS && (yarn run web-ext sign -s build --api-key "$AMOKEY" --api-secret "$AMOSECRET" "$@" || true)) } publish_beta_nonewtab() { @@ -23,6 +23,7 @@ publish_beta() { scripts/version.js beta sed 's/"name": "Tridactyl"/"name": "Tridactyl: Beta"/' -i build/manifest.json sign_and_submit + tar --exclude-from=<(.grep -v .build_cache/ .gitignore) --exclude-vcs -czf ../../public_html/betas/tridactyl_source_beta.tar.gz . } build_no_sign_beta(){ @@ -31,9 +32,9 @@ build_no_sign_beta(){ scripts/version.js beta sed 's/"name": "Tridactyl"/"name": "Tridactyl: Beta"/' -i build/manifest.json mkdir -p web-ext-artifacts - $(yarn bin)/web-ext build --source-dir ./build --overwrite-dest + yarn run web-ext build --source-dir ./build --overwrite-dest for f in web-ext-artifacts/*.zip; do - mv $f ${f%.zip}.xpi + mv "$f" "${f%.zip}".xpi done } @@ -42,9 +43,9 @@ build_no_sign_stable(){ yarn run build --no-native sed 's/tridactyl.vim.betas@cmcaine/tridactyl.vim@cmcaine/' -i build/manifest.json mkdir -p web-ext-artifacts - $(yarn bin)/web-ext build --source-dir ./build --overwrite-dest + yarn run web-ext build --source-dir ./build --overwrite-dest for f in web-ext-artifacts/*.zip; do - mv $f ${f%.zip}.xpi + mv "$f" "${f%.zip}".xpi done } @@ -53,7 +54,7 @@ publish_stable() { yarn run build --no-native sed 's/tridactyl.vim.betas@cmcaine/tridactyl.vim@cmcaine/' -i build/manifest.json sign_and_submit - tar --exclude-from=.gitignore -czf ../../public_html/betas/tridactyl_source.tar.gz . + tar --exclude-from=<(grep -v .build_cache/ .gitignore) --exclude-vcs -czf ../../public_html/betas/tridactyl_source.tar.gz . } case $1 in @@ -61,5 +62,6 @@ case $1 in nosignstable) build_no_sign_stable;; nosignbeta) build_no_sign_beta;; nonewtab) publish_beta_nonewtab;; - *|beta) publish_beta;; + beta) publish_beta;; + *) publish_beta;; esac diff --git a/scripts/version.js b/scripts/version.js index d153ab1b..301e1aaf 100755 --- a/scripts/version.js +++ b/scripts/version.js @@ -1,6 +1,7 @@ #!/usr/bin/env node const { exec } = require("child_process") +const fs = require("fs") function bump_version(versionstr, component = 2) { const versionarr = versionstr.split(".") @@ -12,21 +13,37 @@ function bump_version(versionstr, component = 2) { } async function add_beta(versionstr) { - return new Promise((resolve, err) => { - exec("git rev-list --count HEAD", (execerr, stdout, stderr) => { - if (execerr) err(execerr) - resolve(versionstr + "pre" + stdout.trim()) + await fs.promises.mkdir(".build_cache", {recursive: true}) + try { + await fs.promises.access(".git") + await new Promise((resolve, err) => { + exec("git rev-list --count HEAD > .build_cache/count", (execerr, stdout, stderr) => { + if (execerr) err(execerr) + resolve(stdout.trim()) + }) }) - }) + } + catch { + ; // Not in a git directory - don't do anything + } + return versionstr + "pre" + (await fs.promises.readFile(".build_cache/count", {encoding: "utf8"})).trim() } async function get_hash() { - return new Promise((resolve, err) => { - exec("git rev-parse --short HEAD", (execerr, stdout, stderr) => { - if (execerr) err(execerr) - resolve(stdout.trim()) + await fs.promises.mkdir(".build_cache", {recursive: true}) + try { + await fs.promises.access(".git") + await new Promise((resolve, err) => { + exec("git rev-parse --short HEAD > .build_cache/hash", (execerr, stdout, stderr) => { + if (execerr) err(execerr) + resolve(stdout.trim()) + }) }) - }) + } + catch { + ; // Not in a git directory - don't do anything + } + return (await fs.promises.readFile(".build_cache/hash", {encoding: "utf8"})).trim() } function make_update_json(versionstr) { @@ -102,7 +119,7 @@ async function main() { make_update_json(manifest.version), ) } catch(e) { - console.warn("updates.json wasn't updated: " + e) + console.warn("Unless you're the buildbot, ignore this error: " + e) } // Save manifest.json