Skip to content

Commit f429993

Browse files
author
Matthias Koeppe
committed
.ci/retrofit-worktree.sh: New, factored out from .github/workflows/build*.yml
1 parent 2f1a76d commit f429993

File tree

4 files changed

+42
-71
lines changed

4 files changed

+42
-71
lines changed

.ci/retrofit-worktree.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
if [ $# != 2 ]; then
3+
echo >&2 "usage: $0 WORKTREE_NAME WORKTREE_DIRECTORY"
4+
echo >&2 "Ensures that the current working directory is a git repository,"
5+
echo >&2 "then makes WORKTREE_DIRECTORY a git worktree named WORKTREE_NAME."
6+
fi
7+
WORKTREE_NAME="$1"
8+
WORKTREE_DIRECTORY="$2"
9+
10+
export GIT_AUTHOR_NAME="ci-sage workflow"
11+
export GIT_AUTHOR_EMAIL="[email protected]"
12+
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
13+
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
14+
15+
set -ex
16+
17+
# If actions/checkout downloaded our source tree using the GitHub REST API
18+
# instead of with git (because do not have git installed in our image),
19+
# we first make the source tree a repo.
20+
if [ ! -d .git ]; then git init && git add -A && git commit --quiet -m "new"; fi
21+
22+
# Tag this state of the source tree "new". This is what we want to build and test.
23+
git tag -f new
24+
25+
# Our container image contains a source tree in $WORKTREE_DIRECTORY with a full build of Sage.
26+
# But $WORKTREE_DIRECTORY is not a git repository.
27+
# We make $WORKTREE_DIRECTORY a worktree whose index is at tag "new".
28+
# We then commit the current sources and set the tag "old". (This keeps all mtimes unchanged.)
29+
# Then we update worktree and index with "git reset --hard new".
30+
# (This keeps mtimes of unchanged files unchanged and mtimes of changed files newer than unchanged files.)
31+
# Finally we reset the index to "old". (This keeps all mtimes unchanged.)
32+
# The changed files now show up as uncommitted changes.
33+
# The final "git add -N" makes sure that files that were added in "new" do not show
34+
# as untracked files, which would be removed by "git clean -fx".
35+
git worktree add --detach $WORKTREE_NAME
36+
rm -rf $WORKTREE_DIRECTORY/.git && mv $WORKTREE_NAME/.git $WORKTREE_DIRECTORY/
37+
rm -rf $WORKTREE_NAME && ln -s $WORKTREE_DIRECTORY $WORKTREE_NAME
38+
if [ ! -f $WORKTREE_NAME/.gitignore ]; then cp .gitignore $WORKTREE_NAME/; fi
39+
(cd $WORKTREE_NAME && git add -A && git commit --quiet --allow-empty -m "old" -a && git tag -f old && git reset --hard new && git reset --quiet old && git add -N . && git status)

.github/workflows/build.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,8 @@ jobs:
6969
id: worktree
7070
run: |
7171
set -ex
72-
git config --global user.email "[email protected]"
73-
git config --global user.name "Build & Test workflow"
7472
git config --global --add safe.directory $(pwd)
75-
# If actions/checkout downloaded our source tree using the GitHub REST API
76-
# instead of with git (because do not have git installed in our image),
77-
# we first make the source tree a repo.
78-
if [ ! -d .git ]; then git init && git add -A && git commit --quiet -m "new"; fi
79-
# Tag this state of the source tree "new". This is what we want to build and test.
80-
git tag -f new
81-
# Our container image contains a source tree in /sage with a full build of Sage.
82-
# But /sage is not a git repository.
83-
# We make /sage a worktree whose index is at tag "new".
84-
# We then commit the current sources and set the tag "old". (This keeps all mtimes unchanged.)
85-
# Then we update worktree and index with "git reset --hard new".
86-
# (This keeps mtimes of unchanged files unchanged and mtimes of changed files newer than unchanged files.)
87-
# Finally we reset the index to "old". (This keeps all mtimes unchanged.)
88-
# The changed files now show up as uncommitted changes.
89-
# The final "git add -N" makes sure that files that were added in "new" do not show
90-
# as untracked files, which would be removed by "git clean -fx".
91-
git worktree add --detach worktree-image
92-
rm -rf /sage/.git && mv worktree-image/.git /sage/
93-
rm -rf worktree-image && ln -s /sage worktree-image
94-
if [ ! -f worktree-image/.gitignore ]; then cp .gitignore worktree-image/; fi
95-
(cd worktree-image && git add -A && git commit --quiet --allow-empty -m "old" -a && git tag -f old && git reset --hard new && git reset --quiet old && git add -N . && git status)
73+
.ci/retrofit-worktree.sh worktree-image /sage
9674
9775
- name: Download upstream artifact
9876
uses: actions/download-artifact@v3

.github/workflows/doc-build-pdf.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,8 @@ jobs:
6262
- name: Add prebuilt tree as a worktree
6363
id: worktree
6464
run: |
65-
set -ex
66-
git config --global user.email "[email protected]"
67-
git config --global user.name "Build & Test workflow"
6865
git config --global --add safe.directory $(pwd)
69-
# If actions/checkout downloaded our source tree using the GitHub REST API
70-
# instead of with git (because do not have git installed in our image),
71-
# we first make the source tree a repo.
72-
if [ ! -d .git ]; then git init && git add -A && git commit --quiet -m "new"; fi
73-
# Tag this state of the source tree "new". This is what we want to build and test.
74-
git tag -f new
75-
# Our container image contains a source tree in /sage with a full build of Sage.
76-
# But /sage is not a git repository.
77-
# We make /sage a worktree whose index is at tag "new".
78-
# We then commit the current sources and set the tag "old". (This keeps all mtimes unchanged.)
79-
# Then we update worktree and index with "git reset --hard new".
80-
# (This keeps mtimes of unchanged files unchanged and mtimes of changed files newer than unchanged files.)
81-
# Finally we reset the index to "old". (This keeps all mtimes unchanged.)
82-
# The changed files now show up as uncommitted changes.
83-
# The final "git add -N" makes sure that files that were added in "new" do not show
84-
# as untracked files, which would be removed by "git clean -fx".
85-
git worktree add --detach worktree-image
86-
rm -rf /sage/.git && mv worktree-image/.git /sage/
87-
rm -rf worktree-image && ln -s /sage worktree-image
88-
if [ ! -f worktree-image/.gitignore ]; then cp .gitignore worktree-image/; fi
89-
(cd worktree-image && git add -A && git commit --quiet --allow-empty -m "old" -a && git tag -f old && git reset --hard new && git reset --quiet old && git add -N . && git status)
66+
.ci/retrofit-worktree.sh worktree-image /sage
9067
# Keep track of changes to built HTML
9168
new_version=$(cat src/VERSION.txt); (cd /sage/local/share/doc/sage/html/en && find . -name "*.html" | xargs sed -i '/class="sidebar-brand-text"/s/Sage [0-9a-z.]* /Sage '$new_version' /'; git init && (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; git add -A && git commit --quiet -m "old")
9269

.github/workflows/doc-build.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,8 @@ jobs:
5353
- name: Add prebuilt tree as a worktree
5454
id: worktree
5555
run: |
56-
set -ex
57-
git config --global user.email "[email protected]"
58-
git config --global user.name "Build & Test workflow"
5956
git config --global --add safe.directory $(pwd)
60-
# If actions/checkout downloaded our source tree using the GitHub REST API
61-
# instead of with git (because do not have git installed in our image),
62-
# we first make the source tree a repo.
63-
if [ ! -d .git ]; then git init && git add -A && git commit --quiet -m "new"; fi
64-
# Tag this state of the source tree "new". This is what we want to build and test.
65-
git tag -f new
66-
# Our container image contains a source tree in /sage with a full build of Sage.
67-
# But /sage is not a git repository.
68-
# We make /sage a worktree whose index is at tag "new".
69-
# We then commit the current sources and set the tag "old". (This keeps all mtimes unchanged.)
70-
# Then we update worktree and index with "git reset --hard new".
71-
# (This keeps mtimes of unchanged files unchanged and mtimes of changed files newer than unchanged files.)
72-
# Finally we reset the index to "old". (This keeps all mtimes unchanged.)
73-
# The changed files now show up as uncommitted changes.
74-
# The final "git add -N" makes sure that files that were added in "new" do not show
75-
# as untracked files, which would be removed by "git clean -fx".
76-
git worktree add --detach worktree-image
77-
rm -rf /sage/.git && mv worktree-image/.git /sage/
78-
rm -rf worktree-image && ln -s /sage worktree-image
79-
if [ ! -f worktree-image/.gitignore ]; then cp .gitignore worktree-image/; fi
80-
(cd worktree-image && git add -A && git commit --quiet --allow-empty -m "old" -a && git tag -f old && git reset --hard new && git reset --quiet old && git add -N . && git status)
57+
.ci/retrofit-worktree.sh worktree-image /sage
8158
# Keep track of changes to built HTML
8259
new_version=$(cat src/VERSION.txt); (cd /sage/local/share/doc/sage/html/en && find . -name "*.html" | xargs sed -i '/class="sidebar-brand-text"/s/Sage [0-9a-z.]* /Sage '$new_version' /'; git init && (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; git add -A && git commit --quiet -m "old")
8360

0 commit comments

Comments
 (0)