forked from cargo-bins/cargo-quickinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger-package-build.sh
executable file
·111 lines (94 loc) · 3.64 KB
/
trigger-package-build.sh
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
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")"
get_build_os() {
if [[ "$1" == "x86_64-apple-darwin" ]]; then
echo "macos-latest"
elif [[ "$1" == "x86_64-unknown-linux-gnu" ]]; then
echo "ubuntu-20.04"
elif [[ "$1" == "x86_64-pc-windows-msvc" ]]; then
echo "windows-latest"
else
echo "Unrecognised build OS: $1"
exit 1
fi
}
main() {
REPO_ROOT="$PWD"
BRANCH=$(git branch --show-current)
if [[ ${FORCE:-} == 1 ]]; then
ALLOW_EMPTY=--allow-empty
else
ALLOW_EMPTY=
fi
if ! git config user.name; then
git config user.email "alsuren+quickinstall@gmail.com"
git config user.name "trigger-package-build.sh"
fi
TARGETS="${TARGETS:-${TARGET:-x86_64-pc-windows-msvc x86_64-apple-darwin x86_64-unknown-linux-gnu}}"
for TARGET in $TARGETS; do
BUILD_OS=$(get_build_os "$TARGET")
rm -rf "/tmp/cargo-quickinstall-$TARGET"
git worktree remove -f "/tmp/cargo-quickinstall-$TARGET" || true
git branch -D "trigger/$TARGET" || true
git worktree add --force --force "/tmp/cargo-quickinstall-$TARGET"
cd "/tmp/cargo-quickinstall-$TARGET"
EXCLUDE_FILE="/tmp/cargo-quickinstall-$TARGET/exclude.txt"
if git fetch origin "trigger/$TARGET"; then
git checkout "origin/trigger/$TARGET" -B "trigger/$TARGET"
elif git checkout "trigger/$TARGET"; then
# pass
true
else
# New branch with no history. Credit: https://stackoverflow.com/a/13969482
git checkout --orphan "trigger/$TARGET"
git rm -r --force .
git commit -am "Initial Commit" --allow-empty
fi
if [[ "${RECHECK:-}" == "1" || "${REEXCLUDE:-}" == "1" || ! -f "$EXCLUDE_FILE" ]]; then
TARGET="$TARGET" "$REPO_ROOT/print-build-excludes.sh" >"$EXCLUDE_FILE"
git add "$EXCLUDE_FILE"
git --no-pager diff HEAD
git commit -m "Generate exclude.txt for $TARGET" || echo "exclude.txt already up to date. Skipping."
if [[ "${REEXCLUDE:-}" == "1" ]]; then
continue
fi
fi
if [[ -f package-info.txt && "${RECHECK:-}" != "1" ]]; then
START_AFTER_CRATE=$(grep -F '::set-output name=crate_to_build::' package-info.txt | sed 's/^.*:://')
else
START_AFTER_CRATE=''
fi
env START_AFTER_CRATE="$START_AFTER_CRATE" \
TARGET="$TARGET" \
EXCLUDE_FILE="$EXCLUDE_FILE" \
"$REPO_ROOT/next-unbuilt-package.sh" >package-info.txt
CRATE=$(
grep -F '::set-output name=crate_to_build::' package-info.txt |
sed 's/^.*:://'
)
mkdir -p .github/workflows/
# I like cat. Shut up.
# shellcheck disable=SC2002
cat "$REPO_ROOT/.github/workflows/build-package.yml.template" |
sed -e s/'[$]TARGET'/"$TARGET"/ \
-e s/'[$]BUILD_OS'/"$BUILD_OS"/ \
-e s/'[$]BRANCH'/"$BRANCH"/ \
>.github/workflows/build-package.yml
git add package-info.txt .github/workflows/build-package.yml
git --no-pager diff HEAD
if ! git commit $ALLOW_EMPTY -am "build $CRATE on $TARGET"; then
echo "looks like there's nothing to push"
continue
fi
if ! git push origin "trigger/$TARGET"; then
echo "
If you have updated .github/workflows/build-package.yml.template
then you will need to run trigger-package-build.sh on your local machine
first.
"
exit 1
fi
done
}
main