-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
181 lines (147 loc) · 4.66 KB
/
Copy pathpublish.sh
File metadata and controls
181 lines (147 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
# THIS SCRIPT MUST BE STARTED IN THE PACKAGE GIT REPOSITORY
# '/c/path/to/my/typst/package/repository'
#
# Example run scenario:
# ```
# cd '/c/path/to/my/typst/package/repository'
# /path/to/publish.sh
# ```
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "ERROR: This script must be run from the root of your package git repository."
exit 1
fi
# ---
# Use a VERSION file to retrieve version numbers.
if [ ! -f "VERSION" ]; then
echo "ERROR: 'VERSION' file not found."
exit 1
fi
version=$(<VERSION)
# OR write the version number directly.
# version="0.0.0"
# ---
# The username which owns the package repository on GitHub.
username="neuralpain"
# Your package name on Typst Universe.
package_name="edgeframe"
# The package repository name on GitHub.
# Change this if the repository name is different from the package name.
repository=$package_name
# The name set for your fork of the `typst/packages` repository on GitHub.
# Default name is `packages`. Change this to match the name of your fork.
packages_fork_name="typst-packages"
# ---
# Access URL & Protocol
ssh="git@github.com:"
http="https://github.com/"
# Set `upstream` to use either `ssh` or `http` based on your preference.
upstream="${http}typst/packages"
# Set the fork address to use either `ssh` or `http` based on your preference.
packages_fork_address="${http}$username/$packages_fork_name"
current_dir=$(basename "$PWD")
if [ "$current_dir" != "$repository" ]; then
echo "WARN: Current directory '$current_dir' does not match repository name '$repository'."
# read -p "Continue anyway? (y/n) " -n 1 -r
# echo
# if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
# fi
fi
# ---
# This will clone the latest commit on your `typst/packages` fork.
echo "======== Create partial clone ======================="
cd ..
if [ -d "$packages_fork_name" ]; then
rm -rf "$packages_fork_name"
fi
git clone --depth 1 --no-checkout --filter="tree:0" "$packages_fork_address" || {
echo "ERROR: Failed to clone fork. Check your username and fork name."
if [ -d "$packages_fork_name" ]; then
rm -rf "$packages_fork_name"
fi
exit 1
}
cd "$packages_fork_name"
git sparse-checkout init
git sparse-checkout set packages/preview/$package_name
git remote add upstream $upstream
git config remote.upstream.partialclonefilter tree:0
git checkout main
# This will update the your local clone with the latest commit from upstream.
echo "======== Update with latest commit =================="
git log -n 1
git fetch upstream --depth=1
git reset --hard upstream/main
git log -n 1
echo "======== Create new branch =========================="
new_branch=$package_name-$version
commit_message=$package_name:$version
git branch $new_branch
git switch $new_branch
cd ..
echo "======== Copy new files ============================="
# Destination directory for the new version
dest="$packages_fork_name/packages/preview/$package_name/$version"
mkdir -pv "$dest"
required_files=(
"lib.typ"
"LICENSE"
"README.md"
"typst.toml"
)
for file in "${required_files[@]}"; do
if [ ! -f "$repository/$file" ]; then
echo "ERROR: Required file '$file' missing in $repository"
exit 1
fi
cp -v "$repository/$file" "$dest"
done
folders=(
"examples"
"src"
# Add more folders...
)
for folder in "${folders[@]}"; do
if [ ! -d "$repository/$folder" ]; then
echo "WARN: Folder '$folder' missing in $repository"
else
# Create directories for the new version.
# Empty folders are not committed to git.
mkdir -pv "$dest/$folder"
cp -rv "$repository/$folder" "$dest"
fi
done
# ---
# Delete unnecessary files.
cleanup() {
find "$dest" -name "$1" -delete -print
}
echo "======== Remove PDFs ================================"
cleanup "*.pdf"
echo "======== Remove Backup files ========================"
cleanup "*.bak"
cleanup "*.bkp"
echo "======== Remove Temporary files ====================="
cleanup "*.tmp"
cleanup "*.temp"
echo "======== Remove Test files =========================="
cleanup "*temp*"
cleanup "*test*"
cleanup "test"
echo "======== Remove other files ========================="
# cleanup "*.<file-extension>"
echo "======== Commit changes on new branch ==============="
cd "$packages_fork_name"
git add .
git commit -m "$commit_message"
git log -n 1
echo "======== Push new branch upstream ==================="
# NOTE: This is a test. Remove `--dry-run` to actually push your code upstream.
git push --dry-run origin $new_branch # --force # <-- Overwrite branch on origin.
cd ..
echo "======== Done ======================================="
echo
echo "Go to <${http}$username/$packages_fork_name/tree/$new_branch> to review and create a pull request."
# Return to local package directory
cd $repository