|
2 | 2 | set -euo pipefail |
3 | 3 | shopt -s extglob |
4 | 4 |
|
| 5 | + |
| 6 | +## Set some global configuration options, but allow users to override them |
| 7 | + |
5 | 8 | ## If we're running in debug mode, be REALLY VERBOSE: |
6 | 9 | if [[ "${BUILDKITE_PLUGIN_JULIA_DEBUG_PLUGIN:-false}" == "true" ]]; then |
| 10 | + PS4="> " |
7 | 11 | set -x |
8 | 12 | fi |
9 | 13 |
|
10 | 14 | CACHE_DIR=${BUILDKITE_PLUGIN_JULIA_CACHE_DIR:-${HOME}/.cache/julia-buildkite-plugin} |
11 | 15 |
|
12 | 16 | echo "--- :broom: Performing clean-up" |
13 | 17 |
|
| 18 | +if [[ "${BUILDKITE_PLUGIN_JULIA_SUCCESS:-false}" != "true" ]]; then |
| 19 | + echo "Skipping clean-up since the plugin did not successfully run." |
| 20 | + exit 0 |
| 21 | +fi |
| 22 | + |
14 | 23 |
|
15 | 24 | ### Step 1: Remove any code coverage files. |
16 | 25 |
|
|
23 | 32 |
|
24 | 33 | # Some packages check coverage files in, so only remove writable ones |
25 | 34 | if [[ "${BUILDKITE_PLUGIN_JULIA_ISOLATED_DEPOT:-true}" == "true" && \ |
26 | | - -d "${JULIA_DEPOT_PATH}"/packages ]]; then |
27 | | - find "${JULIA_DEPOT_PATH}"/packages -name "*.jl.*.cov" -type f -perm -200 -delete |
| 35 | + -d "${DEPOT_DIR}"/packages ]]; then |
| 36 | + find "${DEPOT_DIR}"/packages -name "*.jl.*.cov" -type f -perm -200 -delete |
28 | 37 | fi |
29 | 38 |
|
30 | 39 |
|
31 | 40 | ### Step 2: Reduce the size of our depot by removing old precompilation files. |
32 | 41 |
|
| 42 | +echo "Removing old precompilation files" |
| 43 | + |
33 | 44 | # Julia does not track when a precompilation file was last used, so we simply |
34 | 45 | # remove files in the `compiled` directory until we are below the limit. |
35 | 46 |
|
36 | 47 | # default limit: 1 GiB |
37 | 48 | COMPILED_LIMIT="${BUILDKITE_PLUGIN_JULIA_COMPILED_SIZE_LIMIT:-1073741824}" |
38 | 49 |
|
39 | 50 | if [[ "${BUILDKITE_PLUGIN_JULIA_ISOLATED_DEPOT:-true}" == "true" ]]; then |
40 | | - COMPILED_DIR="${JULIA_DEPOT_PATH}/compiled" |
| 51 | + COMPILED_DIR="${DEPOT_DIR}/compiled" |
41 | 52 | if [[ -d "${COMPILED_DIR}" ]]; then |
42 | 53 | COMPILED_SIZE_HUMAN=$(du -h -s "${COMPILED_DIR}" | cut -f 1) |
43 | 54 | # `-k` gives consistently the number of kilobytes on macOS and Linux, |
|
87 | 98 |
|
88 | 99 | ### Step 3: Reduce the size of our depot by removing old artifacts. |
89 | 100 |
|
| 101 | +echo "Removing old artifacts" |
| 102 | + |
90 | 103 | # This is normally done by `Pkg.gc`, however, since manifests are ephemeral |
91 | 104 | # (and logs directories may not even persist) that doesn't work well. |
92 | 105 | # So instead we remove directories based on their creation time. |
|
95 | 108 | ARTIFACTS_LIMIT="${BUILDKITE_PLUGIN_JULIA_ARTIFACTS_SIZE_LIMIT:-10737418240}" |
96 | 109 |
|
97 | 110 | if [[ "${BUILDKITE_PLUGIN_JULIA_ISOLATED_DEPOT:-true}" == "true" ]]; then |
98 | | - ARTIFACTS_DIR="${JULIA_DEPOT_PATH}/artifacts" |
| 111 | + ARTIFACTS_DIR="${DEPOT_DIR}/artifacts" |
99 | 112 | if [[ -d "${ARTIFACTS_DIR}" ]]; then |
100 | 113 | ARTIFACTS_SIZE_HUMAN=$(du -h -s "${ARTIFACTS_DIR}" | cut -f 1) |
101 | 114 | # `-k` gives consistently the number of kilobytes on macOS and Linux, |
@@ -151,22 +164,27 @@ DEPOT_LIMIT_DEFAULT=$(($COMPILED_LIMIT+$ARTIFACTS_LIMIT+10737418240)) |
151 | 164 | DEPOT_LIMIT="${BUILDKITE_PLUGIN_JULIA_DEPOT_SIZE_LIMIT:-${DEPOT_LIMIT_DEFAULT}}" |
152 | 165 |
|
153 | 166 | if [[ "${BUILDKITE_PLUGIN_JULIA_ISOLATED_DEPOT:-true}" == "true" ]]; then |
154 | | - DEPOT_SIZE_HUMAN=$(du -h -s "${JULIA_DEPOT_PATH}" | cut -f 1) |
155 | | - # `-k` gives consistently the number of kilobytes on both macOS and Linux, |
156 | | - # without it BSD `du` would give the number of multiples of 512 bytes. |
157 | | - DEPOT_SIZE=$(($(du -k -s "${JULIA_DEPOT_PATH}" | cut -f 1) * 1024)) |
158 | | - echo "The depot size is: ${DEPOT_SIZE_HUMAN}" |
159 | | - |
160 | | - if [[ ${DEPOT_SIZE} -gt ${DEPOT_LIMIT} ]]; then |
161 | | - echo "This is greater than the limit (${DEPOT_SIZE} > ${DEPOT_LIMIT} bytes), so we will clear the entire depot" |
162 | | - rm -rf "${JULIA_DEPOT_PATH}" |
163 | | - mkdir -p "${JULIA_DEPOT_PATH}" |
| 167 | + echo "Checking overall depot size at ${DEPOT_DIR}" |
| 168 | + if [[ -d "${DEPOT_DIR}" ]]; then |
| 169 | + DEPOT_SIZE_HUMAN=$(du -h -s "${DEPOT_DIR}" | cut -f 1) |
| 170 | + # `-k` gives consistently the number of kilobytes on both macOS and Linux, |
| 171 | + # without it BSD `du` would give the number of multiples of 512 bytes. |
| 172 | + DEPOT_SIZE=$(($(du -k -s "${DEPOT_DIR}" | cut -f 1) * 1024)) |
| 173 | + echo "The depot size is: ${DEPOT_SIZE_HUMAN}" |
| 174 | + |
| 175 | + if [[ ${DEPOT_SIZE} -gt ${DEPOT_LIMIT} ]]; then |
| 176 | + echo "This is greater than the limit (${DEPOT_SIZE} > ${DEPOT_LIMIT} bytes), so we will clear the entire depot" |
| 177 | + rm -rf "${DEPOT_DIR}" |
| 178 | + mkdir -p "${DEPOT_DIR}" |
| 179 | + fi |
164 | 180 | fi |
165 | 181 | fi |
166 | 182 |
|
167 | 183 |
|
168 | 184 | ### Step 5: Remove old depots. |
169 | 185 |
|
| 186 | +echo "Removing old depots" |
| 187 | + |
170 | 188 | # We mark a depot as in-use by `touch`ing it at the start of the pipeline, |
171 | 189 | # so we can remove any depots that are older than a certain age. |
172 | 190 |
|
|
0 commit comments