Skip to content

Commit 93d005f

Browse files
author
Release Manager
committed
gh-36442: CI: Refactor `build*.yml` through a new script `.ci/retrofit-worktree.sh` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> Removes some duplicated code, no changes in functionality. Also preparation for merging 3 workflows into one, as proposed in #36349 (comment) <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36442 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
2 parents 31d8d5b + 94c8b88 commit 93d005f

File tree

4 files changed

+44
-69
lines changed

4 files changed

+44
-69
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: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,10 @@ jobs:
6262
- name: Add prebuilt tree as a worktree
6363
id: worktree
6464
run: |
65-
set -ex
65+
git config --global --add safe.directory $(pwd)
6666
git config --global user.email "[email protected]"
6767
git config --global user.name "Build & Test workflow"
68-
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)
68+
.ci/retrofit-worktree.sh worktree-image /sage
9069
# Keep track of changes to built HTML
9170
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")
9271

.github/workflows/doc-build.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,10 @@ jobs:
5353
- name: Add prebuilt tree as a worktree
5454
id: worktree
5555
run: |
56-
set -ex
56+
git config --global --add safe.directory $(pwd)
5757
git config --global user.email "[email protected]"
5858
git config --global user.name "Build & Test workflow"
59-
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)
59+
.ci/retrofit-worktree.sh worktree-image /sage
8160
# Keep track of changes to built HTML
8261
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")
8362

0 commit comments

Comments
 (0)