|
| 1 | +# h/t to @jimhester and @yihui for this parse block: |
| 2 | +# https://github.com/yihui/knitr/blob/dc5ead7bcfc0ebd2789fe99c527c7d91afb3de4a/Makefile#L1-L4 |
| 3 | +# Note the portability change as suggested in the manual: |
| 4 | +# https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Writing-portable-packages |
| 5 | +export PKGNAME=`sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION` |
| 6 | +export PKGVERS=`sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION` |
| 7 | +export DATETIME=`date +%Y-%m-%d\ %H:%M:%S` |
| 8 | +export DATETIMEUTC=`date -u +%Y-%m-%d\ %H:%M:%S` |
| 9 | +export DATE=`date +%Y.%-m.%-d` |
| 10 | + |
| 11 | +#export PWD=$(abspath $(lastword $(MAKEFILE_LIST))) |
| 12 | + |
| 13 | +all: build |
| 14 | + |
| 15 | +.ONESHELL: |
| 16 | +fix_description_version: |
| 17 | + sed -i "s/^Version: .*/Version: $(DATE)/" DESCRIPTION |
| 18 | + sed -i '/Date\/Publication:/d' DESCRIPTION # delete if exists |
| 19 | + echo "Date/Publication: $(DATETIMEUTC) UTC" >> DESCRIPTION #append to bottom |
| 20 | + sudo chmod -R 777 .. |
| 21 | + |
| 22 | +.ONESHELL: |
| 23 | +build_data: |
| 24 | + sudo podman run --rm --privileged \ |
| 25 | + -v $(shell pwd):/rpkg \ |
| 26 | + docker.io/fhix/rfhiverse:latest /bin/bash -c \ |
| 27 | + 'Rscript -e "devtools::load_all(\"/rpkg/\"); gen_data_all(\"/rpkg/data\")"' |
| 28 | + sudo chmod -R 777 .. |
| 29 | + |
| 30 | +.ONESHELL: |
| 31 | +build_package: |
| 32 | + sudo rm -rf ../built |
| 33 | + mkdir ../built |
| 34 | + sudo podman run --rm --privileged \ |
| 35 | + -v $(shell pwd):/rpkg \ |
| 36 | + -v $(shell pwd)/../built:/built \ |
| 37 | + docker.io/fhix/rfhiverse:latest /bin/bash -c \ |
| 38 | + ' \ |
| 39 | + cd /; \ |
| 40 | + R CMD build /rpkg; \ |
| 41 | + cp *.tar.gz /built/; \ |
| 42 | + ' |
| 43 | + sudo chown -R go ../built |
| 44 | + sudo chmod -R 777 .. |
| 45 | + |
| 46 | +.ONESHELL: |
| 47 | +check_package: |
| 48 | + sudo podman run --rm --privileged \ |
| 49 | + -v $(shell pwd):/rpkg \ |
| 50 | + -v $(shell pwd)/../built:/built \ |
| 51 | + docker.io/fhix/rfhiverse:latest /bin/bash -c \ |
| 52 | + ' \ |
| 53 | + R CMD check --no-manual /built/*.tar.gz; \ |
| 54 | + mv *.Rcheck /built/; \ |
| 55 | + ' |
| 56 | + |
| 57 | + sudo chmod -R 777 .. |
| 58 | + |
| 59 | + if grep -Fq "WARNING" ../built/*.Rcheck/00check.log |
| 60 | + then |
| 61 | + # code if found |
| 62 | + exit 1 |
| 63 | + else |
| 64 | + # code if not found |
| 65 | + echo "NO WARNINGs" |
| 66 | + fi |
| 67 | + |
| 68 | + if grep -Fq "ERROR" ../built/*.Rcheck/00check.log |
| 69 | + then |
| 70 | + # code if found |
| 71 | + exit 1 |
| 72 | + else |
| 73 | + # code if not found |
| 74 | + echo "NO ERRORs" |
| 75 | + fi |
| 76 | + |
| 77 | +.ONESHELL: |
| 78 | +drat: |
| 79 | + git -C .. clone [email protected]:folkehelseinstituttet/drat.git --branch gh-pages |
| 80 | + sudo podman run --rm --privileged \ |
| 81 | + -v $(shell pwd):/rpkg \ |
| 82 | + -v $(shell pwd)/../built:/built \ |
| 83 | + -v $(shell pwd)/../drat:/drat \ |
| 84 | + docker.io/fhix/rfhiverse:latest /bin/bash -c 'Rscript -e "drat::insertPackage(fs::dir_ls(\"/built/\", regexp=\".tar.gz\$\"), repodir = \"/drat\")"' |
| 85 | + |
| 86 | + sed -i "/## News/a - **$(PKGNAME) $(PKGVERS)** (linux) inserted at $(DATETIME)" ../drat/README.md |
| 87 | + sed -i '1001,\\\$ d' ../drat/README.md # only keep first 1000 lines of readme |
| 88 | + |
| 89 | + git config --global user.email " [email protected]" |
| 90 | + git config --global user.name "sykdomspulsen" |
| 91 | + |
| 92 | + git -C ../drat add -A |
| 93 | + git -C ../drat commit -am "gocd $(PKGNAME) $(PKGVERS)" #Committing the changes |
| 94 | + git -C ../drat push -f origin gh-pages #pushes to master branch |
| 95 | + |
| 96 | + sudo chmod -R 777 .. |
| 97 | + |
| 98 | +.ONESHELL: |
| 99 | +pkgdown: |
| 100 | + sudo podman run --rm --privileged \ |
| 101 | + -v $(shell pwd):/rpkg \ |
| 102 | + -v $(shell pwd)/../built:/built \ |
| 103 | + -v $(shell pwd)/../drat:/drat \ |
| 104 | + docker.io/fhix/rfhiverse:latest /bin/bash -c 'Rscript -e "devtools::install(\"/rpkg\", dependencies = TRUE, upgrade = FALSE); pkgdown::build_site(\"/rpkg\")"' |
| 105 | + |
| 106 | + git add . |
| 107 | + git commit -am "Pkgdown built" |
| 108 | + git subtree split --prefix docs -b gh-pages # create a local gh-pages branch containing the splitted output folder |
| 109 | + git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin |
| 110 | + git branch -D gh-pages # delete the local gh-pages because you will need it: ref |
| 111 | + |
| 112 | + sudo chmod -R 777 .. |
| 113 | + |
| 114 | +.ONESHELL: |
| 115 | +drat_prune_history: |
| 116 | + cd /tmp |
| 117 | + git clone "[email protected]:folkehelseinstituttet/drat.git" |
| 118 | + cd drat |
| 119 | + git config user.name "Sykdomspulsen" |
| 120 | + git config user.email "[email protected]" |
| 121 | + git config push.default simple |
| 122 | + git checkout gh-pages |
| 123 | + |
| 124 | + git checkout --orphan latest_branch |
| 125 | + git add -A |
| 126 | + git commit -am "Cleaning history" #Committing the changes |
| 127 | + git branch -D gh-pages #Deleting master branch |
| 128 | + git branch -m gh-pages #renaming branch as master |
| 129 | + git -C /tmp/drat push -f origin gh-pages #pushes to master branch |
0 commit comments