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
Show 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
def
self
.
[]
(
*
what
)
what
.
extend
Params
;
end
def
===
(
argv
)
argv
.
first_is
(
self
);
end
end
# ============================================================================
ARGV
.
extend
Params
class
CLI
# CLI options
attr_reader
:prefix
#=> "doc/"
attr_reader
:input
#=> "/home/me/projects/foo"
attr_reader
:message
#=> "Updated"
attr_reader
:repo
#=> "git@github.com:me/project.git"
attr_reader
:url
#=> "http://me.github.com/project"
attr_reader
:branch
#=> "gh-pages"
def
verbose?
()
@verbose
;
end
def
force?
()
@force
;
end
def
simulate?
()
@simulate
;
end
def
initialize
# Switches
@verbose
=
!!
(
ARGV
.
extract
(
'--verbose'
)
||
ARGV
.
delete
(
'-v'
))
@simulate
=
!!
(
ARGV
.
extract
(
'--simulate'
)
||
ARGV
.
delete
(
'-s'
))
@force
=
!!
(
ARGV
.
delete
(
'--force'
)
||
ARGV
.
delete
(
'-f'
))
# Stuff
@prefix
=
ARGV
.
extract
(
'--prefix'
)
||
ARGV
.
extract
(
'-p'
)
||
''
@input
=
File
.
expand_path
(
ARGV
.
extract
(
'--input'
)
||
ARGV
.
extract
(
'-i'
)
||
'.'
)
@message
=
ARGV
.
extract
(
'--message'
)
||
ARGV
.
extract
(
'-m'
)
||
'Update'
# Github info
branch
=
ARGV
.
extract
(
'--branch'
)
||
ARGV
.
extract
(
'-b'
)
||
nil
@repo
,
@url
,
@branch
=
get_github_info
(
ARGV
.
shift
,
branch
)
end
def
git_current_branch
`git rev-parse --abbrev-ref HEAD`
.
strip
end
def
git_deploy
in_temp_path
do
|
temppath
|
status
"Cloning repository"
system
!
"git clone
#{
repo
}
-b
#{
branch
}
#{
temppath
}
"
if
git_current_branch
!=
branch
status
"Warning: No
#{
branch
}
branch found in repo, creating one."
return
git_deploy_force
end
copy_files
input
,
File
.
join
(
temppath
,
prefix
)
status
"Committing files"
system
!
"git add .; git add -u; git commit -m
#{
message
.
to_s
.
inspect
}
"
unless
simulate?
status
"Updating repo"
system
!
"git push origin
#{
branch
}
"
end
true
end
end
def
git_deploy_force
in_temp_path
do
|
temppath
|
status
"Creating new repository"
system
!
"git init ."
system
!
"git checkout -b gh-pages"
copy_files
input
,
File
.
join
(
temppath
,
prefix
)
status
"Committing files"
system
!
"git add . && git commit -m
#{
message
.
to_s
.
inspect
}
"
unless
simulate?
status
"Updating repo"
system
!
"git push
#{
repo
}
gh-pages:
#{
branch
}
--force"
end
true
end
end
def
get_github_info
(
repo
,
branch
=
nil
,
prefix
=
nil
)
if
github_format?
(
repo
)
user
,
repo_name
=
repo
.
split
(
'/'
)
r
=
"git@github.com:
#{
repo
}
.git"
# User page or project page?
if
repo_name
=~
/\.github\.com/
[
r
,
"http://
#{
repo_name
}
/
#{
prefix
}
"
,
branch
||
'master'
]
else
else
[
r
,
"http://
#{
user
}
.github.com/
#{
repo_name
}
/
#{
prefix
}
"
,
branch
||
'gh-pages'
]
_
"(cd
\"
$source
\"
>/dev/null && tar c .) | tar xv"
end
fi
}
# Sets git config
set_config
()
{
if
[
-n
"
$GIT_NAME
"
]
;
then
_ git config user.name
"
$GIT_NAME
"
;
fi
if
[
-n
"
$GIT_EMAIL
"
]
;
then
_ git config user.email
"
$GIT_EMAIL
"
;
fi
}
# Runs the deployment
run
()
{
if
[
!
-d
"
$source
"
]
;
then
echo
"Source is not a directory:
$source
"
exit
1
fi
local
tmpdir
=
"
$(
mktemp
-d
)
"
if
[[
"
$force
"
==
"1"
]]
;
then
_
cd
"
$tmpdir
"
_ git init
_ git checkout
-b
"
$branch
"
copy_contents
"
$source
"
if
[[
"
$useenv
"
==
"1"
]]
;
then
set_config
;
fi
_ git add
-A
.
git_commit
git_push
--force
else
else
[
repo
,
nil
,
branch
]
_
cd
"
$tmpdir
"
end
_ git clone
"
$repo
"
.
-b
"
$branch
"
||
(
\
end
_ git init
&&
\
_ git checkout
-b
"
$branch
"
)
def
run!
if
[[
"
$keep
"
==
"0"
]]
;
then
_
rm
-rf
./
*
;
fi
unless
repo
copy_contents
"
$source
"
print_help
if
[[
"
$useenv
"
==
"1"
]]
;
then
set_config
;
fi
exit
128
_ git add
-A
.
end
git_commit
||
true
git_push
status
"Deploying to
#{
repo
}
(branch
#{
branch
}
)"
fi
msg
"NOTE: Running in simulation mode."
if
simulate?
_
rm
-rf
"
$tmpdir
"
msg
"WARNING: If the repository has gh-pages history, it with be overriden."
if
force?
&&
!
simulate?
status_
"Done"
}
result
=
force?
?
git_deploy_force
:
git_deploy
git_commit
()
{
if
result
if
[
-z
"
$author
"
]
;
then
puts
""
_ git commit
-m
"
$message
"
status
"Done."
msg
"See:
#{
url
}
"
if
url
&&
!
simulate?
else
else
tip
"Failed."
_ git commit
-m
"
$message
"
--author
"
$author
"
exit
1
fi
end
}
end
def
status
(
str
)
puts
"
#{
c
(
'===>'
,
34
)
}
#{
c
(
str
,
32
)
}
"
end
def
msg
(
str
)
puts
"
#{
c
(
str
,
32
)
}
"
end
def
c
(
str
,
color
)
"
\033
[
#{
color
}
m
#{
str
}
\033
[0m"
end
def
print_help
tip
\
%{Usage: git update-ghpages username/repository [options]
Flags:
-f, --force Force an update (WARNING: kills the history!)
-s, --simulate Creates the repository, but doesn't push.
-v, --verbose Verbose mode
Options:
-p PATH, --prefix The prefix
-i PATH, --input Input (defaults to current directory)
-b BRANCH, --branch The branch to deploy to (defaults to gh-pages)
-m MSG, --message Commit message (defaults to 'Update')
Examples:
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.
$ git update-ghpages james/coffee
Same as above, but take the files from 'doc/'.
$ git update-ghpages james/coffee -i doc
Same as the first, but the files will instead be in
git_push
()
{
http://james.github.com/coffee/manual.
if
[
-z
"
$GITHUB_TOKEN
"
]
;
then
_ git push
"
${
repo
}
"
"
$branch
"
"
$@
"
$ git update-ghpages james/coffee -i doc -p manual
else
}
.
gsub
(
/^ {4}/
,
''
)
status
"Pushing via
\$
GITHUB_TOKEN
$@
"
end
_ git push
"https://
${
GITHUB_TOKEN
}
@github.com/
${
repospec
}
.git"
"
$branch
"
"
$@
"
\
--quiet
>
/dev/null 2>&1
||
\
private
# Helpers
(
status_
"Failed to push"
;
exit
1
)
fi
def
tip
(
msg
)
}
$stderr
.
write
"
#{
msg
}
\n
"
end
status
()
{
echo
-e
"
\n\0
33[34m==>
\0
33[0;1m"
"
$@
\0
33[0m"
def
github_format?
(
str
)
}
str
=~
/^([A-Za-z0-9\-_]+)\/([A-Za-z0-9\-_\.]+)$/
status_
()
{
end
echo
-e
"
\0
33[33;1m==>
\0
33[0m"
"
$@
"
}
# Performs actions inside a temp path.
def
in_temp_path
(
&
blk
)
_
()
{
require
'tmpdir'
echo
""
Dir
.
mktmpdir
do
|
dir
|
status_
"
$@
"
Dir
.
chdir
(
dir
)
{
yield
dir
}
if
[[
!
"
$dryrun
"
==
"1"
]]
;
then
"
$@
"
;
fi
end
}
end
help
()
{
def
system!
(
str
)
local
cmd
=
"
$(
basename
$0
)
"
puts
`
#{
str
}
2>&1`
.
strip
.
gsub
(
/^/
,
" "
)
echo
'Usage:'
raise
"Failed with exit code
#{
$?
.
to_i
}
"
unless
$?
.
to_i
==
0
echo
"
$cmd
<REPO> <SOURCE>"
end
echo
''
echo
'Parameters:'
# Returns the current branch name
echo
" REPO repository to push to in 'user/repo' form"
def
git_branch
echo
" SOURCE path to upload to repository's gh-pages branch"
`git symbolic-ref HEAD`
.
strip
.
split
(
'/'
).
last
echo
''
end
echo
'Options:'
echo
' -h, --help show help screen'
# Copy files from source folder to another
echo
' -f, --force force push'
def
copy_files
(
from
,
to
)
echo
' -n, --dry-run run in simulation mode'
status
"Copying files
#{
from
}
=>
#{
to
}
..."
if
verbose?
echo
' -e, --use-env pick up arguments from environment variables'
echo
' -b, --branch use this branch name (default: gh-pages)'
Dir
[
"
#{
from
}
/**/*"
].
each
do
|
f
|
echo
' -a, --author set the author'
next
unless
File
.
file?
(
f
)
echo
' -k, --keep keep existing files in the repo'
echo
''
target
=
File
.
join
(
to
,
f
.
gsub
(
/^
#{
Regexp
.
escape
from
}
/
,
''
))
echo
'Env var options:'
echo
' GITHUB_TOKEN if set, use this to push to the repo'
FileUtils
.
mkdir_p
File
.
dirname
(
target
)
echo
''
msg
"%20s => %-20s"
%
[
f
,
target
]
if
verbose?
echo
'Optional env vars:'
FileUtils
.
cp
f
,
target
echo
" Run with '-e' to enable the use of these variables."
end
echo
" GIT_NAME set this as the repos user.name"
end
echo
' GIT_EMAIL set this as the repos user.email'
echo
' GITHUB_REPO substitute as the REPO (1st argument)'
echo
' GIT_SOURCE substitute as the SOURCE (2nd argument)'
echo
' GIT_BRANCH use this branch name (--branch)'
echo
''
echo
'Example:'
echo
"
$cmd
rstacruz/myproject doc"
echo
" # pushes './doc' into the gh-pages branch of rstacruz/myproject"
echo
''
echo
" export GITHUB_REPO='xyz/abc'"
echo
" export GIT_SOURCE='docs'"
echo
"
$cmd
-e"
echo
" # pushes './doc' into the gh-pages branch of xyz/abc"
}
#
# Defaults
#
force
=
0
dryrun
=
0
repospec
=
source
=
branch
=
message
=
"Update"
useenv
=
0
author
=
""
keep
=
0
#
# Parse args
#
while
[[
"
$1
"
=
~ ^-
&&
!
"
$1
"
==
'--'
]]
;
do case
$1
in
-h
|
--help
)
help
exit
;;
-b
|
--branch
)
shift
branch
=
"
$1
"
;;
-n
|
--dry-run
)
dryrun
=
1
;;
-e
|
--use-env
)
useenv
=
1
;;
-k
|
--keep
)
keep
=
1
;;
-a
|
--author
)
shift
author
=
"
$1
"
;;
-f
|
--force
)
force
=
1
;;
esac
;
shift
;
done
if
[[
"
$1
"
==
'--'
]]
;
then
shift
;
fi
if
[[
"
$useenv
"
==
"1"
]]
&&
[[
-n
"
$GIT_BRANCH
"
]]
&&
[[
-z
"
$branch
"
]]
;
then
branch
=
"
$GIT_BRANCH
"
fi
if
[[
"
$useenv
"
==
"1"
]]
&&
[[
-n
"
$GITHUB_REPO
"
]]
&&
[[
-n
"
$GIT_SOURCE
"
]]
&&
[[
-z
"
$2
"
]]
;
then
repospec
=
"
$GITHUB_REPO
"
source
=
"
$GIT_SOURCE
"
else
repospec
=
"
$1
"
source
=
"
$2
"
fi
:
${
branch
:
=
"gh-pages"
}
if
[
-z
"
$source
"
]
;
then
help
exit
1
fi
end
source
=
"
`
pwd
-LP
`
/
$source
"
repo
=
"https://github.com/
${
repospec
}
.git"
CLI
.
new
.
run!
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