Skip to content

Commit

Permalink
Extend KERL_AUTOCLEAN to Git-based builds (#511)
Browse files Browse the repository at this point in the history
* Extend auto-clean to git builds too

These were unconditionally getting removed on failure

* Save and restore build logfiles upon either git or normal build

We were just doing this for normal builds

* Prevent CI waste

On pull request we're already also pushing (and this is the same for
the main branch)

`concurrency` prevents having to wait for a previous push'
CI to completely run, by cancelling it when a new push is done
  • Loading branch information
paulo-ferraz-oliveira committed Feb 26, 2024
1 parent ab74f44 commit 60fb7ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
@@ -1,6 +1,10 @@
---
name: CI
'on': [push, pull_request]
'on':
- push
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
env:
ERLC_USE_SERVER: true
KERL_DEBUG: 'yes'
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
@@ -1,6 +1,10 @@
---
name: Lint
'on': [push, pull_request]
'on':
- push
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
lint:
name: Lint
Expand Down
31 changes: 23 additions & 8 deletions kerl
Expand Up @@ -199,16 +199,9 @@ autoclean() {
if [ "${KERL_AUTOCLEAN:=1}" -eq 1 ]; then
notice "Auto cleaning all artifacts except the log file..."
tip "(use KERL_AUTOCLEAN=0 to keep build on failure, if desired)"
# Save LOGFILE
tmplf="$(mktemp "$TMP_DIR"/kerl.XXXXXX)"
test -f "$BUILD_LOGFILE" && cp -f "$BUILD_LOGFILE" "$tmplf"
# Cleaning current build
cd - 1>/dev/null 2>&1 || return 0
test -n "$1" && ${_KERL_SCRIPT} cleanup "$1"
# Copy BUILD_LOGFILE back to keep track of all attempts until success
mkdir -p "$(dirname "$BUILD_LOGFILE")"
mv -f "$tmplf" "$BUILD_LOGFILE"
unset tmplf
else
warn "auto cleaning (on failure) disabled!"
fi
Expand Down Expand Up @@ -650,11 +643,16 @@ exit_build() {
error "$1"
fi

tmp=$(save_logfile)

if [ -n "$2" ]; then
rm -Rf "${KERL_BUILD_DIR:?}/$2"
if [ "${KERL_AUTOCLEAN:=1}" -eq 1 ]; then
rm -Rf "${KERL_BUILD_DIR:?}/$2"
fi
fi

unlock_build
restore_logfile "$tmp"

exit 1
}
Expand Down Expand Up @@ -988,12 +986,27 @@ probe_pkgs() {
fi
}

save_logfile() {
tmp="$(mktemp "$TMP_DIR"/kerl.XXXXXX)"
test -f "$BUILD_LOGFILE" && cp -f "$BUILD_LOGFILE" "$tmp"
echo "$tmp"
}

restore_logfile() {
# $1: logfile to restore

mkdir -p "$(dirname "$BUILD_LOGFILE")"
test -n "$BUILD_LOGFILE" && mv -f "$1" "$BUILD_LOGFILE"
rm -f "$1"
}

fail_do_build() {
# $1: error message
# $2: build name
# $3: release

show_build_logfile "$1"
tmp=$(save_logfile)

if [ -n "$2" ]; then
autoclean "$2"
Expand All @@ -1002,6 +1015,8 @@ fail_do_build() {
if [ -n "$3" ]; then
list_remove builds "$3 $2"
fi

restore_logfile "$tmp"
}

uname_r_label() {
Expand Down

0 comments on commit 60fb7ce

Please sign in to comment.