-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.sh
executable file
·142 lines (123 loc) · 3.77 KB
/
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
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
#!/bin/bash
# shellcheck disable=SC2024
set -o errexit -o pipefail -o nounset
pkgname=$INPUT_PKGNAME
pkgbuild=$INPUT_PKGBUILD
assets=$INPUT_ASSETS
updpkgsums=$INPUT_UPDPKGSUMS
test=$INPUT_TEST
read -r -a test_flags <<< "$INPUT_TEST_FLAGS"
post_process=$INPUT_POST_PROCESS
commit_username=$INPUT_COMMIT_USERNAME
commit_email=$INPUT_COMMIT_EMAIL
ssh_private_key=$INPUT_SSH_PRIVATE_KEY
commit_message=$INPUT_COMMIT_MESSAGE
allow_empty_commits=$INPUT_ALLOW_EMPTY_COMMITS
force_push=$INPUT_FORCE_PUSH
ssh_keyscan_types=$INPUT_SSH_KEYSCAN_TYPES
assert_non_empty() {
name=$1
value=$2
if [[ -z "$value" ]]; then
echo "::error::Invalid Value: $name is empty." >&2
exit 1
fi
}
assert_non_empty inputs.pkgname "$pkgname"
assert_non_empty inputs.pkgbuild "$pkgbuild"
assert_non_empty inputs.commit_username "$commit_username"
assert_non_empty inputs.commit_email "$commit_email"
assert_non_empty inputs.ssh_private_key "$ssh_private_key"
export HOME=/home/builder
# Ignore "." and ".." to prevent errors when glob pattern for assets matches hidden files
GLOBIGNORE=".:.."
echo '::group::Adding aur.archlinux.org to known hosts'
ssh-keyscan -v -t "$ssh_keyscan_types" aur.archlinux.org >>~/.ssh/known_hosts
echo '::endgroup::'
echo '::group::Importing private key'
echo "$ssh_private_key" >~/.ssh/aur
chmod -vR 600 ~/.ssh/aur*
ssh-keygen -vy -f ~/.ssh/aur >~/.ssh/aur.pub
echo '::endgroup::'
echo '::group::Checksums of SSH keys'
sha512sum ~/.ssh/aur ~/.ssh/aur.pub
echo '::endgroup::'
echo '::group::Configuring Git'
git config --global user.name "$commit_username"
git config --global user.email "$commit_email"
echo '::endgroup::'
echo '::group::Cloning AUR package into /tmp/local-repo'
git clone -v "https://aur.archlinux.org/${pkgname}.git" /tmp/local-repo
echo '::endgroup::'
echo '::group::Copying files into /tmp/local-repo'
{
echo "Copying $pkgbuild"
cp -r "$pkgbuild" /tmp/local-repo/
}
# shellcheck disable=SC2086
# Ignore quote rule because we need to expand glob patterns to copy $assets
if [[ -n "$assets" ]]; then
echo 'Copying' $assets
cp -rt /tmp/local-repo/ $assets
fi
echo '::endgroup::'
if [ "$updpkgsums" == "true" ]; then
echo '::group::Updating checksums'
cd /tmp/local-repo/
updpkgsums
echo '::endgroup::'
fi
if [ "$test" == "true" ]; then
echo '::group::Building package with makepkg'
cd /tmp/local-repo/
makepkg "${test_flags[@]}"
echo '::endgroup::'
fi
echo '::group::Generating .SRCINFO'
cd /tmp/local-repo
makepkg --printsrcinfo >.SRCINFO
echo '::endgroup::'
if [ -n "$post_process" ]; then
echo '::group::Executing post process commands'
cd /tmp/local-repo/
eval "$post_process"
echo '::endgroup::'
fi
echo '::group::Committing files to the repository'
if [[ -z "$assets" ]]; then
# When $assets are not set, we can add just PKGBUILD and .SRCINFO
# This is to prevent unintended behaviour and maintain backwards compatibility
git add -fv PKGBUILD .SRCINFO
else
# We cannot just re-use $assets because it contains absolute paths outside repository
# But we can just add all files in the repository which should also include all $assets
git add --all
fi
case "$allow_empty_commits" in
true)
git commit --allow-empty -m "$commit_message"
;;
false)
git diff-index --quiet HEAD || git commit -m "$commit_message" # use `git diff-index --quiet HEAD ||` to avoid error
;;
*)
echo "::error::Invalid Value: inputs.allow_empty_commits is neither 'true' nor 'false': '$allow_empty_commits'"
exit 2
;;
esac
echo '::endgroup::'
echo '::group::Publishing the repository'
git remote add aur "ssh://[email protected]/${pkgname}.git"
case "$force_push" in
true)
git push -v --force aur master
;;
false)
git push -v aur master
;;
*)
echo "::error::Invalid Value: inputs.force_push is neither 'true' nor 'false': '$force_push'"
exit 3
;;
esac
echo '::endgroup::'