@@ -59,30 +59,50 @@ jobs:
59
59
run : ./setup-environment.sh
60
60
61
61
- name : Gather build summary
62
+ id : build-info
63
+ env :
64
+ MANUAL_INPUT_PACKAGES : ${{ github.event.inputs.packages }}
62
65
run : |
66
+ # We are intentionally not using .commits[0].id and .commits[-1].id as github seems to
67
+ # only send 20 commits in the payload for github action runs instead of the 2048 documented
68
+ # limit. Perhaps 2048 is the limit just for webhooks, where they haven't documented
69
+ # properly that the limit for github actions is only 20:
70
+ #
71
+ # https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
72
+ OLD_COMMIT="${{ github.event.before }}"
73
+ HEAD_COMMIT="${{ github.event.after }}"
63
74
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
64
- BASE_COMMIT=$(jq --raw-output .pull_request.base.sha "$GITHUB_EVENT_PATH")
65
- OLD_COMMIT=$(jq --raw-output .commits[0].id "$GITHUB_EVENT_PATH")
66
- HEAD_COMMIT=$(jq --raw-output .commits[-1].id "$GITHUB_EVENT_PATH")
67
- if [ "$BASE_COMMIT" = "null" ]; then
68
- if [ "$OLD_COMMIT" = "$HEAD_COMMIT" ]; then
69
- # Single-commit push.
70
- echo "Processing commit: ${HEAD_COMMIT}"
71
- CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${HEAD_COMMIT}")
72
- else
73
- # Multi-commit push.
74
- OLD_COMMIT="${OLD_COMMIT}~1"
75
- echo "Processing commit range: ${OLD_COMMIT}..${HEAD_COMMIT}"
76
- CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${OLD_COMMIT}" "${HEAD_COMMIT}")
75
+ BASE_REF="${{ github.event.pull_request.base.ref }}"
76
+ git fetch origin "${BASE_REF:-master}" 2>/dev/null
77
+ BASE_COMMIT="$(git merge-base "origin/${BASE_REF:-master}" "HEAD")"
78
+ if [ -z "${{ github.event.pull_request.base.sha }}" ]; then
79
+ if ! git log "$OLD_COMMIT" > /dev/null; then
80
+ if [ "$(git branch --show-current)" = "master" ]; then
81
+ echo "Force push detected on master branch. Unable to proceed."
82
+ exit 1
83
+ else
84
+ OLD_COMMIT=$(git fetch origin master >&2; git merge-base origin/master $HEAD_COMMIT)
85
+ fi
77
86
fi
87
+ echo "Processing commit range: ${OLD_COMMIT}..${HEAD_COMMIT}"
88
+ CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${OLD_COMMIT}" "${HEAD_COMMIT}")
78
89
else
79
90
# Pull requests.
80
- echo "Processing pull request #$(jq --raw-output . pull_request.number "$GITHUB_EVENT_PATH") : ${BASE_COMMIT}..HEAD"
91
+ echo "Processing pull request #${{ github.event. pull_request.number }} : ${BASE_COMMIT}..HEAD"
81
92
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${BASE_COMMIT}" "HEAD")
82
93
fi
83
94
fi
84
95
mkdir -p ./artifacts ./debs
85
96
touch ./debs/.placeholder
97
+
98
+ if [[ "${{ github.event_name }}" == "pull_request" && -n "$(git rev-list --merges "$(git fetch origin master >&2; git merge-base origin/master $HEAD_COMMIT)..$HEAD_COMMIT")" ]]; then
99
+ # Github does not allow multiline errors, but it will interpret the escape sequence %0A as a line break.
100
+ echo "::error ::Merge commits are not allowed in pull requests.%0AYou should rebase your commits or squash them.%0Ahttps://docs.github.com/en/get-started/using-git/using-git-rebase-on-the-command-line"
101
+ exit 1
102
+ fi
103
+
104
+ GITHUB_OUTPUT="$GITHUB_OUTPUT" OLD_COMMIT="$OLD_COMMIT" HEAD_COMMIT="$HEAD_COMMIT" GITHUB_TOKEN="${{ secrets.GH_TOKEN }}" scripts/utils/termux_reuse_pr_build_artifacts.sh "${{ github.event_name }}" "${{ matrix.target_arch }}" || true
105
+
86
106
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
87
107
# Process tag '%ci:no-build' that may be added as line to commit message.
88
108
# Forces CI to cancel current build with status 'passed'
@@ -134,7 +154,10 @@ jobs:
134
154
done<<<${CHANGED_FILES}
135
155
done
136
156
else
137
- for pkg in ${{ github.event.inputs.packages }}; do
157
+ # Ensure MANUAL_INPUT_PACKAGES is newline free, and put it
158
+ # into an array
159
+ read -a PACKAGES <<< "${MANUAL_INPUT_PACKAGES//$'\n'/ }"
160
+ for pkg in "${PACKAGES[@]}"; do
138
161
repo_paths=$(jq --raw-output 'keys | .[]' repo.json)
139
162
found=false
140
163
for repo_path in $repo_paths; do
@@ -168,14 +191,6 @@ jobs:
168
191
mv ./deleted_${repo}_packages.txt.tmp ./deleted_${repo}_packages.txt
169
192
fi
170
193
done
171
- - name : Free additional disk space (if necessary)
172
- run : |
173
- if grep -Eq "^($(paste -s -d '|' ./big-pkgs.list))$" ./built_tur_packages.txt; then
174
- sudo apt purge -yq $(dpkg -l | grep '^ii' | awk '{ print $2 }' | grep -P '(aspnetcore|cabal-|dotnet-|ghc-|libmono|mongodb-|mysql-|php)') \
175
- firefox google-chrome-stable microsoft-edge-stable mono-devel mono-runtime-common monodoc-manual ruby
176
- sudo apt autoremove -yq
177
- sudo rm -rf /opt/hostedtoolcache /usr/local /usr/share/dotnet /usr/share/swift
178
- fi
179
194
- name : Lint packages
180
195
run : |
181
196
declare -a package_recipes
@@ -188,7 +203,17 @@ jobs:
188
203
if [ ! -z "$package_recipes" ]; then
189
204
./scripts/lint-packages.sh $package_recipes
190
205
fi
206
+ - name : Free additional disk space (if necessary)
207
+ if : ${{ steps.build-info.outputs.skip-building != 'true' }}
208
+ run : |
209
+ if grep -Eq "^($(paste -s -d '|' ./big-pkgs.list))$" ./built_tur_packages.txt; then
210
+ sudo apt purge -yq $(dpkg -l | grep '^ii' | awk '{ print $2 }' | grep -P '(aspnetcore|cabal-|dotnet-|ghc-|libmono|mongodb-|mysql-|php)') \
211
+ firefox google-chrome-stable microsoft-edge-stable mono-devel mono-runtime-common monodoc-manual ruby
212
+ sudo apt autoremove -yq
213
+ sudo rm -rf /opt/hostedtoolcache /usr/local /usr/share/dotnet /usr/share/swift
214
+ fi
191
215
- name : Build packages
216
+ if : ${{ steps.build-info.outputs.skip-building != 'true' }}
192
217
run : |
193
218
declare -a packages
194
219
for repo_path in $(jq --raw-output 'keys | .[]' repo.json); do
0 commit comments