Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
106f9f54
Unverified
Commit
106f9f54
authored
Dec 17, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
⬆
updated git-update-ghpages script
parent
9eb5e2c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
194 additions
and
222 deletions
+194
-222
doc/Makefile
doc/Makefile
+1
-1
doc/scripts/git-update-ghpages
doc/scripts/git-update-ghpages
+193
-221
No files found.
doc/Makefile
View file @
106f9f54
...
@@ -63,7 +63,7 @@ doxygen: create_output create_links
...
@@ -63,7 +63,7 @@ doxygen: create_output create_links
$(SED)
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >@@g'
html/
*
.html
$(SED)
-i
's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >@@g'
html/
*
.html
upload
:
clean doxygen check_output
upload
:
clean doxygen check_output
cd
html
;
../scripts/git-update-ghpages nlohmann/json
scripts/git-update-ghpages nlohmann/json html
rm
-fr
html
rm
-fr
html
open http://nlohmann.github.io/json/
open http://nlohmann.github.io/json/
...
...
doc/scripts/git-update-ghpages
View file @
106f9f54
#!/usr/bin/env ruby
#!/usr/bin/env bash
# git update-ghpages user/repo -b gh-pages -p manual/ -i
set
-o
errexit
require
'fileutils'
copy_contents
()
{
require
'tmpdir'
local source
=
"
$1
"
status
"Copying contents from
$source
"
module
Params
if
[[
!
"
$dryrun
"
==
"1"
]]
;
then
def
extract
(
what
)
i
=
index
(
what
)
and
slice!
(
i
,
2
)[
1
]
end
;
(
cd
"
$source
"
>
/dev/null
&&
tar
c .
)
|
tar
xv
def
first_is
(
what
)
shift
if
what
.
include?
(
self
.
first
);
end
else
def
self
.
[]
(
*
what
)
what
.
extend
Params
;
end
_
"(cd
\"
$source
\"
>/dev/null && tar c .) | tar xv"
def
===
(
argv
)
argv
.
first_is
(
self
);
end
fi
end
}
# ============================================================================
# Sets git config
set_config
()
{
ARGV
.
extend
Params
if
[
-n
"
$GIT_NAME
"
]
;
then
_ git config user.name
"
$GIT_NAME
"
;
fi
if
[
-n
"
$GIT_EMAIL
"
]
;
then
_ git config user.email
"
$GIT_EMAIL
"
;
fi
class
CLI
}
# CLI options
attr_reader
:prefix
#=> "doc/"
# Runs the deployment
attr_reader
:input
#=> "/home/me/projects/foo"
run
()
{
attr_reader
:message
#=> "Updated"
if
[
!
-d
"
$source
"
]
;
then
attr_reader
:repo
#=> "git@github.com:me/project.git"
echo
"Source is not a directory:
$source
"
attr_reader
:url
#=> "http://me.github.com/project"
exit
1
attr_reader
:branch
#=> "gh-pages"
fi
def
verbose?
()
@verbose
;
end
local
tmpdir
=
"
$(
mktemp
-d
)
"
def
force?
()
@force
;
end
def
simulate?
()
@simulate
;
end
if
[[
"
$force
"
==
"1"
]]
;
then
_
cd
"
$tmpdir
"
def
initialize
_ git init
# Switches
_ git checkout
-b
"
$branch
"
@verbose
=
!!
(
ARGV
.
extract
(
'--verbose'
)
||
ARGV
.
delete
(
'-v'
))
copy_contents
"
$source
"
@simulate
=
!!
(
ARGV
.
extract
(
'--simulate'
)
||
ARGV
.
delete
(
'-s'
))
if
[[
"
$useenv
"
==
"1"
]]
;
then
set_config
;
fi
@force
=
!!
(
ARGV
.
delete
(
'--force'
)
||
ARGV
.
delete
(
'-f'
))
_ git add
-A
.
git_commit
# Stuff
git_push
--force
@prefix
=
ARGV
.
extract
(
'--prefix'
)
||
ARGV
.
extract
(
'-p'
)
||
''
else
@input
=
File
.
expand_path
(
ARGV
.
extract
(
'--input'
)
||
ARGV
.
extract
(
'-i'
)
||
'.'
)
_
cd
"
$tmpdir
"
@message
=
ARGV
.
extract
(
'--message'
)
||
ARGV
.
extract
(
'-m'
)
||
'Update'
_ git clone
"
$repo
"
.
-b
"
$branch
"
||
(
\
_ git init
&&
\
# Github info
_ git checkout
-b
"
$branch
"
)
branch
=
ARGV
.
extract
(
'--branch'
)
||
ARGV
.
extract
(
'-b'
)
||
nil
if
[[
"
$keep
"
==
"0"
]]
;
then
_
rm
-rf
./
*
;
fi
@repo
,
@url
,
@branch
=
get_github_info
(
ARGV
.
shift
,
branch
)
copy_contents
"
$source
"
end
if
[[
"
$useenv
"
==
"1"
]]
;
then
set_config
;
fi
_ git add
-A
.
def
git_current_branch
git_commit
||
true
`git rev-parse --abbrev-ref HEAD`
.
strip
git_push
end
fi
_
rm
-rf
"
$tmpdir
"
def
git_deploy
status_
"Done"
in_temp_path
do
|
temppath
|
}
status
"Cloning repository"
system
!
"git clone
#{
repo
}
-b
#{
branch
}
#{
temppath
}
"
git_commit
()
{
if
[
-z
"
$author
"
]
;
then
if
git_current_branch
!=
branch
_ git commit
-m
"
$message
"
status
"Warning: No
#{
branch
}
branch found in repo, creating one."
else
return
git_deploy_force
_ git commit
-m
"
$message
"
--author
"
$author
"
end
fi
}
copy_files
input
,
File
.
join
(
temppath
,
prefix
)
git_push
()
{
status
"Committing files"
if
[
-z
"
$GITHUB_TOKEN
"
]
;
then
system
!
"git add .; git add -u; git commit -m
#{
message
.
to_s
.
inspect
}
"
_ git push
"
${
repo
}
"
"
$branch
"
"
$@
"
else
unless
simulate?
status
"Pushing via
\$
GITHUB_TOKEN
$@
"
status
"Updating repo"
_ git push
"https://
${
GITHUB_TOKEN
}
@github.com/
${
repospec
}
.git"
"
$branch
"
"
$@
"
\
system
!
"git push origin
#{
branch
}
"
--quiet
>
/dev/null 2>&1
||
\
end
(
status_
"Failed to push"
;
exit
1
)
true
fi
end
}
end
status
()
{
def
git_deploy_force
echo
-e
"
\n\0
33[34m==>
\0
33[0;1m"
"
$@
\0
33[0m"
in_temp_path
do
|
temppath
|
}
status
"Creating new repository"
status_
()
{
system
!
"git init ."
echo
-e
"
\0
33[33;1m==>
\0
33[0m"
"
$@
"
system
!
"git checkout -b gh-pages"
}
copy_files
input
,
File
.
join
(
temppath
,
prefix
)
_
()
{
echo
""
status
"Committing files"
status_
"
$@
"
system
!
"git add . && git commit -m
#{
message
.
to_s
.
inspect
}
"
if
[[
!
"
$dryrun
"
==
"1"
]]
;
then
"
$@
"
;
fi
}
unless
simulate?
status
"Updating repo"
help
()
{
system
!
"git push
#{
repo
}
gh-pages:
#{
branch
}
--force"
local
cmd
=
"
$(
basename
$0
)
"
end
echo
'Usage:'
true
echo
"
$cmd
<REPO> <SOURCE>"
end
echo
''
end
echo
'Parameters:'
echo
" REPO repository to push to in 'user/repo' form"
def
get_github_info
(
repo
,
branch
=
nil
,
prefix
=
nil
)
echo
" SOURCE path to upload to repository's gh-pages branch"
if
github_format?
(
repo
)
echo
''
user
,
repo_name
=
repo
.
split
(
'/'
)
echo
'Options:'
r
=
"git@github.com:
#{
repo
}
.git"
echo
' -h, --help show help screen'
echo
' -f, --force force push'
# User page or project page?
echo
' -n, --dry-run run in simulation mode'
if
repo_name
=~
/\.github\.com/
echo
' -e, --use-env pick up arguments from environment variables'
[
r
,
"http://
#{
repo_name
}
/
#{
prefix
}
"
,
branch
||
'master'
]
echo
' -b, --branch use this branch name (default: gh-pages)'
else
echo
' -a, --author set the author'
[
r
,
"http://
#{
user
}
.github.com/
#{
repo_name
}
/
#{
prefix
}
"
,
branch
||
'gh-pages'
]
echo
' -k, --keep keep existing files in the repo'
end
echo
''
else
echo
'Env var options:'
[
repo
,
nil
,
branch
]
echo
' GITHUB_TOKEN if set, use this to push to the repo'
end
echo
''
end
echo
'Optional env vars:'
echo
" Run with '-e' to enable the use of these variables."
def
run!
echo
" GIT_NAME set this as the repos user.name"
unless
repo
echo
' GIT_EMAIL set this as the repos user.email'
print_help
echo
' GITHUB_REPO substitute as the REPO (1st argument)'
exit
128
echo
' GIT_SOURCE substitute as the SOURCE (2nd argument)'
end
echo
' GIT_BRANCH use this branch name (--branch)'
echo
''
status
"Deploying to
#{
repo
}
(branch
#{
branch
}
)"
echo
'Example:'
msg
"NOTE: Running in simulation mode."
if
simulate?
echo
"
$cmd
rstacruz/myproject doc"
msg
"WARNING: If the repository has gh-pages history, it with be overriden."
if
force?
&&
!
simulate?
echo
" # pushes './doc' into the gh-pages branch of rstacruz/myproject"
echo
''
result
=
force?
?
git_deploy_force
:
git_deploy
echo
" export GITHUB_REPO='xyz/abc'"
echo
" export GIT_SOURCE='docs'"
if
result
echo
"
$cmd
-e"
puts
""
echo
" # pushes './doc' into the gh-pages branch of xyz/abc"
status
"Done."
}
msg
"See:
#{
url
}
"
if
url
&&
!
simulate?
else
#
tip
"Failed."
# Defaults
exit
1
#
end
end
force
=
0
dryrun
=
0
def
status
(
str
)
repospec
=
puts
"
#{
c
(
'===>'
,
34
)
}
#{
c
(
str
,
32
)
}
"
source
=
end
branch
=
message
=
"Update"
def
msg
(
str
)
useenv
=
0
puts
"
#{
c
(
str
,
32
)
}
"
author
=
""
end
keep
=
0
def
c
(
str
,
color
)
#
"
\033
[
#{
color
}
m
#{
str
}
\033
[0m"
# Parse args
end
#
def
print_help
while
[[
"
$1
"
=
~ ^-
&&
!
"
$1
"
==
'--'
]]
;
do case
$1
in
tip
\
-h
|
--help
)
%{Usage: git update-ghpages username/repository [options]
help
exit
Flags:
;;
-f, --force Force an update (WARNING: kills the history!)
-b
|
--branch
)
-s, --simulate Creates the repository, but doesn't push.
shift
-v, --verbose Verbose mode
branch
=
"
$1
"
;;
Options:
-n
|
--dry-run
)
-p PATH, --prefix The prefix
dryrun
=
1
-i PATH, --input Input (defaults to current directory)
;;
-b BRANCH, --branch The branch to deploy to (defaults to gh-pages)
-e
|
--use-env
)
-m MSG, --message Commit message (defaults to 'Update')
useenv
=
1
;;
Examples:
-k
|
--keep
)
keep
=
1
Update the repo 'coffee' of github user 'james' with the files from the
;;
current directory. The files will be in http://james.github.com/coffee.
-a
|
--author
)
shift
$ git update-ghpages james/coffee
author
=
"
$1
"
;;
Same as above, but take the files from 'doc/'.
-f
|
--force
)
force
=
1
$ git update-ghpages james/coffee -i doc
;;
esac
;
shift
;
done
Same as the first, but the files will instead be in
if
[[
"
$1
"
==
'--'
]]
;
then
shift
;
fi
http://james.github.com/coffee/manual.
if
[[
"
$useenv
"
==
"1"
]]
&&
[[
-n
"
$GIT_BRANCH
"
]]
&&
[[
-z
"
$branch
"
]]
;
then
$ git update-ghpages james/coffee -i doc -p manual
branch
=
"
$GIT_BRANCH
"
}
.
gsub
(
/^ {4}/
,
''
)
fi
end
if
[[
"
$useenv
"
==
"1"
]]
&&
[[
-n
"
$GITHUB_REPO
"
]]
&&
[[
-n
"
$GIT_SOURCE
"
]]
&&
[[
-z
"
$2
"
]]
;
then
private
# Helpers
repospec
=
"
$GITHUB_REPO
"
source
=
"
$GIT_SOURCE
"
def
tip
(
msg
)
else
$stderr
.
write
"
#{
msg
}
\n
"
repospec
=
"
$1
"
end
source
=
"
$2
"
fi
def
github_format?
(
str
)
str
=~
/^([A-Za-z0-9\-_]+)\/([A-Za-z0-9\-_\.]+)$/
:
${
branch
:
=
"gh-pages"
}
end
if
[
-z
"
$source
"
]
;
then
# Performs actions inside a temp path.
help
def
in_temp_path
(
&
blk
)
exit
1
require
'tmpdir'
fi
Dir
.
mktmpdir
do
|
dir
|
Dir
.
chdir
(
dir
)
{
yield
dir
}
source
=
"
`
pwd
-LP
`
/
$source
"
end
repo
=
"https://github.com/
${
repospec
}
.git"
end
run
def
system!
(
str
)
puts
`
#{
str
}
2>&1`
.
strip
.
gsub
(
/^/
,
" "
)
raise
"Failed with exit code
#{
$?
.
to_i
}
"
unless
$?
.
to_i
==
0
end
# Returns the current branch name
def
git_branch
`git symbolic-ref HEAD`
.
strip
.
split
(
'/'
).
last
end
# Copy files from source folder to another
def
copy_files
(
from
,
to
)
status
"Copying files
#{
from
}
=>
#{
to
}
..."
if
verbose?
Dir
[
"
#{
from
}
/**/*"
].
each
do
|
f
|
next
unless
File
.
file?
(
f
)
target
=
File
.
join
(
to
,
f
.
gsub
(
/^
#{
Regexp
.
escape
from
}
/
,
''
))
FileUtils
.
mkdir_p
File
.
dirname
(
target
)
msg
"%20s => %-20s"
%
[
f
,
target
]
if
verbose?
FileUtils
.
cp
f
,
target
end
end
end
CLI
.
new
.
run!
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment