Skip to content

Commit 3ff2fe6

Browse files
committed
Added lab113.sh
1 parent 221b984 commit 3ff2fe6

File tree

5 files changed

+86
-21
lines changed

5 files changed

+86
-21
lines changed

README.adoc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
:nofooter:
77
ifdef::env-github,env-browser[:outfilesuffix: .adoc]
88

9-
Some labs demonstrating *Git*, *GitHub* or *GitLab* features or solutions.
10-
119
ifdef::env-github[]
12-
Please read the entire content of this link:README.adoc[] (and other link:docs[]) through the https://gitlab.com/paulojeronimo/git-labs[GitLab mirror of this project^]. +
13-
This is because https://github.com/github/markup/issues/1095[GitHub does not render `includes` in Asciidoc documents correctly^]. 😒
10+
<<labs,Some labs>> demonstrating *Git*, *GitHub* or *GitLab* features or solutions.
1411
endif::[]
15-
1612
ifndef::env-github[]
17-
// AsciiDoc URIs and Attributes (a shared project)
1813
include::asciidoc-una/uris.adoc[]
1914
include::asciidoc-una/attributes.adoc[]
2015

21-
Currently, these labs are written in {shell-script}, by trying to apply <<docs/tdd#,TDD>> in {Bash} and using command-line tools available in macOS and Linux distributions like {Git} (of course), {sed}, {awk}, {rsync}, {yq}, etc.
16+
<<labs,Some labs>> demonstrating {Git}, {GitHub} or {GitLab} features or solutions.
17+
endif::[]
18+
19+
ifdef::env-github[]
20+
Please read the entire content of this link:README.adoc[] (and other link:docs[]) through the site https://paulojeronimo.github.io/git-labs or by using the https://gitlab.com/paulojeronimo/git-labs[GitLab mirror of this project^]. +
21+
This is because https://github.com/github/markup/issues/1095[GitHub does not render `includes` in Asciidoc documents correctly^]. 😒
22+
endif::[]
23+
24+
ifndef::env-github[]
25+
Currently, <<labs,these labs>> are written in {shell-script}, by trying to apply <<docs/tdd#,TDD>> in {Bash} and using command-line tools available in macOS and Linux distributions like {Git} (of course), {sed}, {awk}, {rsync}, {yq}, etc.
2226

2327
*This is an {open-source} project ({MITLicense}).*
2428

@@ -30,8 +34,8 @@ Please, read the <<docs/contribution-guidelines#,contribution guidelines>>. +
3034
Fell free fork {uri-paulojeronimo-git-labs}[this repo^], add your lab, and {uri-github-creating-a-pull-request-from-a-fork}[make a pull request^] to add it.
3135

3236
WARNING: This HTML is generated by the link:README.adoc[] file which, in turn,
33-
is generated by link:build.sh[] script.
34-
So, do not edit it directly because it will be overwritten!
37+
is generated by link:build.sh[] script using the sources commited with id https://github.com/paulojeronimo/git-labs/commit/1c470b5[1c470b5^]. +
38+
Please, do not edit it directly because it will be overwritten!
3539

3640
ifdef::env-gitlab[]
3741
WARNING: This repo is a mirror of {uri-paulojeronimo-git-labs}.
@@ -54,9 +58,11 @@ To run a lab, type:
5458
. If you append the `-x` parameter you will see a detailed execution.
5559
====
5660

57-
Available labs:
61+
[[labs]] *Available labs*:
5862

5963
[%reversed]
64+
. link:lab113.sh[]: Publish a GitHub Pages branch (gh-pages) with the HTML content of this repo.
65+
.. Created in 2020-07-07T21:23:14-03:00
6066
. link:lab112.sh[]: A variant of link:lab111.sh[] producing a more detailed log (link:docs/lab112{outfilesuffix}[read more]).
6167
.. Created in 2020-06-20T12:37:13-03:00
6268
. link:lab111.sh[]: Testing `git merge --squash`.

docs/contribution-guidelines.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
include::../asciidoc-una/uris.adoc[]
99
include::../asciidoc-una/attributes.adoc[]
1010

11-
. Fork the repo {uri-paulojeronimo-git-labs}. {uri-github-fork-a-repo}[Read about forking^], if necessary.
11+
. Fork {uri-paulojeronimo-git-labs}[this repo^]. {uri-github-fork-a-repo}[Read about forking^], if necessary.
1212
. Name your lab as "lab<3 digits in <<utilities#base58,Base58>>".sh.
1313
.. The first digit will identify you (the contributor).
1414
.. Increment the last two digits as you add more labs.

functions/README.adoc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
:nofooter:
77
ifdef::env-github,env-browser[:outfilesuffix: .adoc]
88

9-
Some labs demonstrating *Git*, *GitHub* or *GitLab* features or solutions.
10-
119
ifdef::env-github[]
12-
Please read the entire content of this link:README.adoc[] (and other link:docs[]) through the https://gitlab.com/paulojeronimo/git-labs[GitLab mirror of this project^]. +
13-
This is because https://github.com/github/markup/issues/1095[GitHub does not render `includes` in Asciidoc documents correctly^]. 😒
10+
<<labs,Some labs>> demonstrating *Git*, *GitHub* or *GitLab* features or solutions.
1411
endif::[]
15-
1612
ifndef::env-github[]
17-
// AsciiDoc URIs and Attributes (a shared project)
1813
include::asciidoc-una/uris.adoc[]
1914
include::asciidoc-una/attributes.adoc[]
2015

21-
Currently, these labs are written in {shell-script}, by trying to apply <<docs/tdd#,TDD>> in {Bash} and using command-line tools available in macOS and Linux distributions like {Git} (of course), {sed}, {awk}, {rsync}, {yq}, etc.
16+
<<labs,Some labs>> demonstrating {Git}, {GitHub} or {GitLab} features or solutions.
17+
endif::[]
18+
19+
ifdef::env-github[]
20+
Please read the entire content of this link:README.adoc[] (and other link:docs[]) through the site https://paulojeronimo.github.io/git-labs or by using the https://gitlab.com/paulojeronimo/git-labs[GitLab mirror of this project^]. +
21+
This is because https://github.com/github/markup/issues/1095[GitHub does not render `includes` in Asciidoc documents correctly^]. 😒
22+
endif::[]
23+
24+
ifndef::env-github[]
25+
Currently, <<labs,these labs>> are written in {shell-script}, by trying to apply <<docs/tdd#,TDD>> in {Bash} and using command-line tools available in macOS and Linux distributions like {Git} (of course), {sed}, {awk}, {rsync}, {yq}, etc.
2226

2327
*This is an {open-source} project ({MITLicense}).*
2428

@@ -30,8 +34,8 @@ Please, read the <<docs/contribution-guidelines#,contribution guidelines>>. +
3034
Fell free fork {uri-paulojeronimo-git-labs}[this repo^], add your lab, and {uri-github-creating-a-pull-request-from-a-fork}[make a pull request^] to add it.
3135

3236
WARNING: This HTML is generated by the link:README.adoc[] file which, in turn,
33-
is generated by link:build.sh[] script.
34-
So, do not edit it directly because it will be overwritten!
37+
is generated by link:build.sh[] script using the sources commited with id https://github.com/paulojeronimo/git-labs/commit/COMMIT_ID[COMMIT_ID^]. +
38+
Please, do not edit it directly because it will be overwritten!
3539

3640
ifdef::env-gitlab[]
3741
WARNING: This repo is a mirror of {uri-paulojeronimo-git-labs}.
@@ -54,4 +58,4 @@ To run a lab, type:
5458
. If you append the `-x` parameter you will see a detailed execution.
5559
====
5660

57-
Available labs:
61+
[[labs]] *Available labs*:

functions/generate-docs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# References:
44
# Ref1: https://stackoverflow.com/a/46083970[Insert newline (\n) using sed^]
55
# Ref2: https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
6+
# Ref3: https://stackoverflow.com/questions/1967967/git-command-to-display-head-commit-id/1968001
67
#
78

89
generate-included-files() {
@@ -18,9 +19,18 @@ generate-included-files() {
1819
done
1920
}
2021

22+
stamp-the-commit-id() {
23+
mkdir -p tmp
24+
# Ref3
25+
git rev-parse --short HEAD > tmp/SOURCE.id
26+
local commit_id=$(cat tmp/SOURCE.id)
27+
sed "s/COMMIT_ID/$commit_id/g" README.adoc | sponge README.adoc
28+
}
29+
2130
generate-docs() {
2231
local adoc_args=$@
2332
cp functions/README.adoc README.adoc
33+
stamp-the-commit-id
2434
cat >> README.adoc <<EOF
2535
2636
[%reversed]

lab113.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# Purpose: Publish a GitHub Pages branch (gh-pages) with the HTML content of this repo.
3+
# References:
4+
# Ref1: https://www.tldp.org/LDP/abs/html/subshells.html
5+
# Ref2: https://stackoverflow.com/questions/42871542/how-can-i-create-a-git-repository-with-the-default-branch-name-other-than-maste
6+
#
7+
main() {
8+
# Generate HTML:
9+
"$BASE_DIR"/build.sh --html
10+
11+
# Copy origin files to this directory in parallel
12+
declare -i id=-1
13+
for f in $(find .. -type f \( \
14+
-name '*.html' -o \
15+
-name '*.sh' \))
16+
do
17+
(cd ..; rsync -R ${f#*/} $OLDPWD/) &
18+
done
19+
20+
# Ref1: wait for all rsync child process to finish
21+
wait
22+
23+
git init
24+
25+
# Ref2: set default branch name as gh-pages
26+
git checkout -b gh-pages
27+
28+
# Copy origin from sources
29+
origin=$(cd ..; git remote get-url origin)
30+
git remote add origin $origin
31+
32+
# User and repo comes from origin
33+
local user_repo=$(echo $origin | sed 's/\(.*:\)\(.*\).git/\2/')
34+
35+
# Generate a README with a link to
36+
cat > README.adoc <<EOF
37+
http://${user_repo%/*}.github.io/${user_repo#*/}
38+
EOF
39+
40+
git add .
41+
git commit -m "Published from source code commited with id `cat ../tmp/SOURCE.id`"
42+
43+
# Push this branch (forcing override)
44+
git push -f origin gh-pages
45+
}

0 commit comments

Comments
 (0)