Skip to content

Commit

Permalink
Merge branch 'main' into @call
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 28, 2024
2 parents facefa8 + 6c65204 commit 3618ef8
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 107 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, macos-11, macos-12, macos-13 ]
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-13, macos-14, macos-15 ]
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: cache-soft
with:
path: soft
key: ${{ matrix.os }}-${{ hashFiles('Makesurefile') }}-soft--all-2
key: ${{ matrix.os }}-${{ hashFiles('Makesurefile') }}

- name: "run tests"
run: |
Expand All @@ -27,16 +27,16 @@ jobs:
# https://github.com/cross-platform-actions/action
# https://github.com/marketplace/actions/cross-platform-action
freebsd:
runs-on: macos-12
runs-on: ubuntu-latest
name: "Tests on FreeBSD"
steps:
- uses: actions/checkout@v3
- name: Tests in FreeBSD
- uses: actions/checkout@v4
- name: 'Tests in FreeBSD'
id: test
uses: cross-platform-actions/action@v0.21.0
uses: cross-platform-actions/action@v0.26.0
with:
operating_system: freebsd
version: '13.2'
version: '14.2'
shell: sh
run: |
sudo pkg install -y curl
Expand All @@ -61,15 +61,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-11, macos-12, macos-13 ]
os: [ macos-13, macos-14, macos-15 ]
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: cache-soft
with:
path: soft
key: ${{ matrix.os }}-soft--macos-gawk
key: ${{ matrix.os }}-${{ hashFiles('Makesurefile') }}

- name: "run tests"
run: |
Expand All @@ -85,15 +85,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-2019, windows-2022 ]
os: [ windows-2019, windows-2022, windows-2025 ]
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: cache-soft
with:
path: soft
key: ${{ matrix.os }}-soft--win
key: ${{ matrix.os }}-${{ hashFiles('Makesurefile') }}

- name: "run tests"
run: |
Expand Down
15 changes: 11 additions & 4 deletions Makesurefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
@options timing

@define NEXT_VERSION '0.9.23'
@define GOAWK_VERSION '1.25.0' # https://github.com/benhoyt/goawk/releases
@define GOAWK_VERSION '1.29.1' # https://github.com/benhoyt/goawk/releases
@define JUST_VERSION '1.3.0' # https://github.com/casey/just/releases
@define FHTAGN_VERSION 'v0.1.1' # https://github.com/xonixx/fhtagn/releases
@define FHTAGN_VERSION 'v0.2.1' # https://github.com/xonixx/fhtagn/releases
@define MDBOOK_VERSION 'v0.4.37' # https://github.com/rust-lang/mdBook/releases
@define MDBOOK_LINKCHECK_VERSION 'v0.7.7' # https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases
@define MDBOOKER_VERSION '11572b1' # https://github.com/xonixx/mdbooker/releases
Expand Down Expand Up @@ -87,7 +87,11 @@
local f="$1"

[[ "$OSTYPE" == "linux-gnu"* ]] && [[ -d /dev/shm ]] && export TMPDIR="/dev/shm"
if "$FHTAGN" "$f"

if [[ "$f" == *"[wget]"* ]] && ! command -v wget >/dev/null
then
echo "TESTS SKIPPED: $f"
elif "$FHTAGN" "$f"
then
echo "TESTS PASSED : $f"
else
Expand Down Expand Up @@ -181,7 +185,10 @@

@goal README.md @private
@doc 'compiles release version of README.md'
$AWK '
$AWK -v NEXT_VERSION="$NEXT_VERSION" '
{
gsub(/raw\.githubusercontent\.com\/xonixx\/makesure\/[^\/]+\//, "raw.githubusercontent.com/xonixx/makesure/v" NEXT_VERSION "/")
}
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") }
/^```$/ { stop=0 }
!stop' README.md > README.md.1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ Usage: makesure [options...] [-f buildfile] [goals...]
Since `makesure` is a tiny utility represented by a single file, the recommended installation strategy is to keep it local to a project where it's used (this means in code repository). Not only this eliminates the need for repetitive installation for every dev on a project, but also allows using separate `makesure` version per project and update only as needed.

```sh
wget "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=$(date +%s)" -Omakesure && \
wget "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/makesure" -Omakesure && \
chmod +x makesure && echo "makesure $(./makesure -v) installed"
```
or
```sh
curl "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=$(date +%s)" -o makesure && \
curl "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/makesure" -o makesure && \
chmod +x makesure && echo "makesure $(./makesure -v) installed"
```

Expand Down Expand Up @@ -659,7 +659,7 @@ Install Bash completion for `./makesure` locally
```sh
[[ ! -f ~/.bash_completion ]] && touch ~/.bash_completion
grep makesure ~/.bash_completion >/dev/null || echo '. ~/.makesure_completion.bash' >> ~/.bash_completion
curl "https://raw.githubusercontent.com/xonixx/makesure/main/completion.bash?token=$(date +%s)" -o ~/.makesure_completion.bash
curl "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/completion.bash" -o ~/.makesure_completion.bash
echo 'Please reopen the shell to activate completion.'
```

Expand Down
29 changes: 18 additions & 11 deletions makesure
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,27 @@ function currentTimeMillis(res){
res=executeGetLine("date +%s%3N")
sub(/%?3N/,"000",res)
return +res}
function selfUpdate(url,tmp,err,newVer){
url="https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token="rand()
function selfUpdate(tmp,err,newVer,line,sha){
tmp=executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
err=dl(url,tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
err=dl("https://github.com/xonixx/makesure/commits/main",tmp)
if(!err){
newVer=executeGetLine(tmp" -v")
if(Version!=newVer){
if(!ok("cp "tmp" "quoteArg(Prog)))
err="can'\''t overwrite "Prog
else print"updated "Version" -> "newVer
}else print"you have latest version "Version" installed"}
while(getline line<tmp){
if(match(line,/\/xonixx\/makesure\/commit\/[0-9a-z]+/)){
sha=substr(line=substr(line,RSTART,RLENGTH),25)
break}}
if(!sha)err="unable to get the latest commit"
if(!err){
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"sha"/makesure",tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
if(!err){
newVer=executeGetLine(tmp" -v")
if(Version!=newVer){
if(!ok("cp "tmp" "quoteArg(Prog)))
err="can'\''t overwrite "Prog
else print"updated "Version" -> "newVer
}else print"you have latest version "Version" installed"}}}
rm(tmp)
if(err)die(err)}
if(err)die(err"\nPlease use manual update: https://makesure.dev/Installation.html")}
function renderDuration(deltaMillis,\
deltaSec,deltaMin,deltaHr,deltaDay,dayS,hrS,minS,secS,secSI,res){
deltaSec=deltaMillis/1000
Expand Down
63 changes: 46 additions & 17 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -719,22 +719,51 @@ function currentTimeMillis( res) {
sub(/%?3N/, "000", res) # if date doesn't support %N (macos?) just use second-precision
return +res
}

function selfUpdate( url, tmp, err, newVer) {
url = "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=" rand()
tmp = executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
err = dl(url, tmp)
if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp
if (!err) {
newVer = executeGetLine(tmp " -v")
if (Version != newVer) {
if (!ok("cp " tmp " " quoteArg(Prog)))
err = "can't overwrite " Prog
else print "updated " Version " -> " newVer
} else print "you have latest version " Version " installed"
function incVersion(ver, arr) {
split(ver, arr, ".")
arr[3]++
return arr[1]"."arr[2]"."arr[3]
}
function selfUpdate( tmp, err, newVer,line,good,i,found) {
# Idea: We know current version v0.9.X. We will try next version v0.9.(X+1), v0.9.(X+2), etc. till it's not 404
good = (tmp = executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX"))"_good"
newVer = Version
for (; ;) {
if (i++ == 10) { # try max 10 versions up to prevent a possibility of infinite loop
err = "infinite loop"
break
}
# probe next version
newVer = incVersion(newVer)
if (err = dl("https://raw.githubusercontent.com/xonixx/makesure/v" newVer "/makesure", tmp))
break
close(tmp)
if ((getline line < tmp) <= 0) {
err = "can't check the dl result"
break
}
if (line ~ /^404/) {
if (found) {
if (!err && !ok("chmod +x " good)) err = "can't chmod +x " good
if (!err) {
newVer = executeGetLine(good " -v")
if (!ok("cp " good " " quoteArg(Prog)))
err = "can't overwrite " Prog
else
print "updated " Version " -> " newVer
}
} else print "you have latest version " Version " installed"
break
}
found = 1
if (!ok("cp " tmp " " good)) {
err = "can't cp"
break
}
}
rm(tmp)
if (err) die(err)
if (found) rm(good)
if (err) die(err "\nPlease use manual update: https://makesure.dev/Installation.html")
}

function renderDuration(deltaMillis,\
Expand Down Expand Up @@ -783,11 +812,11 @@ function executeGetLine(script, res) {
return res
}
function closeErr(script) { if (close(script) != 0) die("Error executing: " script) }
function dl(url, dest, verbose) {
function dl(url, dest, verbose,exCode) {
verbose = "VERBOSE" in ENVIRON
if (commandExists("wget")) {
if (!ok("wget " (verbose ? "" : "-q") " " quoteArg(url) " -O" quoteArg(dest)))
return "error with wget"
if ((exCode = system("wget " (verbose ? "" : "-q") " " quoteArg(url) " -O" quoteArg(dest) " --content-on-error")) != 0 && exCode != 8) # 404 gives 8, but it's OK for us since we need the content
return "error with wget: " exCode
} else if (commandExists("curl")) {
if (!ok("curl " (verbose ? "" : "-s") " " quoteArg(url) " -o " quoteArg(dest)))
return "error with curl"
Expand Down
29 changes: 18 additions & 11 deletions makesure_candidate
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,27 @@ function currentTimeMillis(res){
res=executeGetLine("date +%s%3N")
sub(/%?3N/,"000",res)
return +res}
function selfUpdate(url,tmp,err,newVer){
url="https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token="rand()
function selfUpdate(tmp,err,newVer,line,sha){
tmp=executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
err=dl(url,tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
err=dl("https://github.com/xonixx/makesure/commits/main",tmp)
if(!err){
newVer=executeGetLine(tmp" -v")
if(Version!=newVer){
if(!ok("cp "tmp" "quoteArg(Prog)))
err="can'\''t overwrite "Prog
else print"updated "Version" -> "newVer
}else print"you have latest version "Version" installed"}
while(getline line<tmp){
if(match(line,/\/xonixx\/makesure\/commit\/[0-9a-z]+/)){
sha=substr(line=substr(line,RSTART,RLENGTH),25)
break}}
if(!sha)err="unable to get the latest commit"
if(!err){
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"sha"/makesure",tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
if(!err){
newVer=executeGetLine(tmp" -v")
if(Version!=newVer){
if(!ok("cp "tmp" "quoteArg(Prog)))
err="can'\''t overwrite "Prog
else print"updated "Version" -> "newVer
}else print"you have latest version "Version" installed"}}}
rm(tmp)
if(err)die(err)}
if(err)die(err"\nPlease use manual update: https://makesure.dev/Installation.html")}
function renderDuration(deltaMillis,\
deltaSec,deltaMin,deltaHr,deltaDay,dayS,hrS,minS,secS,secSI,res){
deltaSec=deltaMillis/1000
Expand Down
53 changes: 23 additions & 30 deletions tests/200_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
@define D '/tmp/dirXXX with spaces'
#@define D '/tmp/dirXXX'

@goal makesure_prepared
@goal env_prepared
[[ -d "$D" ]] && rm -r "$D"
mkdir "$D"
awk -v X="$(cd "$MYDIR/.."; pwd)" '/AWK_DIR=/{ $0 = "AWK_DIR=" X } 1' "../$MAKESURE" > "$D/$MAKESURE"
chmod +x "$D/$MAKESURE"
# cat "$D/$MAKESURE"; exit

export NEXT_VERSION=XXX
if [[ "$("$D/$MAKESURE" --version)" != "XXX" ]]
then
# this is compiled version
awk '/^exec/ { sub(/Version=[0-9.]+/,"Version=XXX") } 1' "$D/$MAKESURE" > "$D/$MAKESURE"_1
cat "$D/$MAKESURE"_1 > "$D/$MAKESURE"
rm "$D/$MAKESURE"_1
fi

for cmd in awk mktemp rm cp dirname cat chmod
do
Expand All @@ -37,18 +25,30 @@
done

@lib
function prepare_makesure() {
awk -v X="$(cd "$MYDIR/.."; pwd)" '/AWK_DIR=/{ $0 = "AWK_DIR=" X } 1' "../$MAKESURE" > "$D/$MAKESURE"
chmod +x "$D/$MAKESURE"
}
function run_selfupdate() {
export PATH="$D"
export NEXT_VERSION=XXX

prepare_makesure
export NEXT_VERSION=0.9.22 # TODO calc by subtracting 1
"$D/$MAKESURE" --version
echo 'selfupdate 1'
"$D/$MAKESURE" --selfupdate

local latestVersion="$("$D/$MAKESURE" --version)"
prepare_makesure
export NEXT_VERSION="$latestVersion"
echo 'selfupdate 2'
"$D/$MAKESURE" --selfupdate
"$D/$MAKESURE" --version
rm -r "$D"
}

@goal test_err
@depends_on makesure_prepared
@depends_on env_prepared
@use_lib
run_selfupdate

Expand All @@ -62,26 +62,19 @@
@use_lib
run_selfupdate

# TODO is it possible to test via native wget if available?
@goal wget_prepared
@depends_on makesure_prepared
@depends_on env_prepared
cmd="wget"

echo $'#!/bin/sh
echo "running wget"
# fake wget with curl
exec awk -v CURL="'$(command -v curl)$'" -v a1="$1" -v a2="$2" -v a3="$3" \'
BEGIN {
sub(/-q/,"-s",a1)
sub(/-O/,"-o",a3)
system(CURL " " a1 " " a2 " " a3)
}\'
' > "$D/$cmd"

cmd1=`command -v $cmd`
{
echo "#!/bin/sh"
echo 'echo "running wget"'
echo "exec $cmd1 \"\$@\""
} > "$D/$cmd"
chmod +x "$D/$cmd"

@goal curl_prepared
@depends_on makesure_prepared
@depends_on env_prepared
cmd="curl"
cmd1=`command -v $cmd`
{
Expand Down
Loading

0 comments on commit 3618ef8

Please sign in to comment.