Skip to content

Commit 11d5fb1

Browse files
authored
Adopt and use hashes (#2)
* Use hashing instead of timestamps * change CI routines * Inline actions
1 parent 1cc0213 commit 11d5fb1

File tree

4 files changed

+154
-3
lines changed

4 files changed

+154
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: restore-sbt-cache
2+
description: 'cache sbt deps and compiled classes'
3+
author: 'Dmitry Muzyka'
4+
inputs:
5+
clean_build:
6+
description: 'build all'
7+
required: false
8+
default: "false"
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Make cache key files
13+
shell: bash
14+
run: |
15+
echo "${LAST_COMPLETED_JOB_SHA1}" > last-completed-job.sha1
16+
echo "${GITHUB_SHA}" > current.sha1
17+
echo "${LATEST_CACHE_SHA1}" > latest-maybe-failed.sha1
18+
date +%Y-%m > current_month
19+
20+
- name: Restore compilation cache
21+
if: ${{ inputs.clean_build != 'true' }}
22+
uses: actions/cache/restore@v3
23+
with:
24+
path: |
25+
build_cache
26+
key: v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('current.sha1') }}
27+
restore-keys: |
28+
v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('current.sha1') }}
29+
v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('latest-maybe-failed.sha1') }}
30+
v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('last-completed-job.sha1') }}
31+
v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-
32+
33+
- name: Apply compilation cache
34+
if: ${{ inputs.clean_build != 'true' }}
35+
shell: bash
36+
run: |
37+
RUNNER_TRACKING_ID="" && tar -xf build_cache/targets.tar 2>/dev/null &
38+
39+
- name: cleanup sbt cache once per month
40+
shell: bash
41+
run: |
42+
mkdir -p ~/.cache
43+
test -f ~/.cache/.timecreated || touch ~/.cache/.timecreated
44+
if test "$(find ~/.cache/.timecreated -mtime +30)"; then
45+
echo "run cleanup"
46+
find ~/.cache ~/.ivy2 -type f -mtime +30 -delete
47+
find ~/.cache ~/.ivy2 -type d -empty -delete
48+
mkdir -p ~/.cache
49+
touch ~/.cache/.timecreated
50+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: save-sbt-cache
2+
description: 'cache sbt deps and compiled classes'
3+
author: 'Dmitry Muzyka'
4+
inputs:
5+
clean_build:
6+
description: 'build all'
7+
required: false
8+
default: "false"
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Build cache directory
13+
shell: bash
14+
run: |
15+
targets=$(git clean -ndx | cut -c14- | grep /$ | grep -E -v '(build_cache|persist|test_results)')
16+
tar -cf build_cache/targets.tar --exclude=*/target/test-reports/*.xml --exclude=*.log --exclude=*/target/scoverage-report --exclude=*/target/coverage-report --exclude=project/target/active.json $targets || :
17+
18+
- name: Make cache key file
19+
shell: bash
20+
run: |
21+
echo "${GITHUB_SHA}" > current.sha1
22+
date +%Y-%m > current_month
23+
24+
- name: check if compilation cache exists
25+
id: check-compilation-cache
26+
uses: actions/cache/restore@v3
27+
with:
28+
path: |
29+
build_cache
30+
key: v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('current.sha1') }}
31+
lookup-only: 'true'
32+
33+
- name: Save compilation cache
34+
if: steps.check-compilation-cache.outputs.cache-hit != 'true'
35+
uses: actions/cache/save@v3
36+
with:
37+
path: |
38+
build_cache
39+
key: v2-build-cache-${{ github.job }}-${{ hashFiles('current_month') }}-${{ hashFiles('current.sha1') }}
40+
41+
- name: Clean up
42+
shell: bash
43+
run: rm -rf build_cache current.sha1
44+
# / save sbt cache

.github/actions/set_vars/action.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: set-ci-vars
2+
description: 'set ci vars.'
3+
author: 'Dmitry Muzyka'
4+
inputs:
5+
clean_build:
6+
description: 'build all'
7+
required: false
8+
default: "false"
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: "set git config"
13+
shell: bash
14+
run: |
15+
git config --global --add safe.directory "$(pwd)"
16+
git fetch origin master
17+
git describe --tags --abbrev=0 --first-parent
18+
19+
# set vars
20+
- name: set branch
21+
shell: bash
22+
run: |
23+
branch="$(echo -n ${{ github.event.ref }} | sed 's#refs/heads/##g; s#/#-#g' | tr '[:upper:]' '[:lower:]')"
24+
echo "branch=\"${branch}\"" >> $GITHUB_ENV
25+
26+
- name: set new version
27+
shell: bash
28+
run: |
29+
if [[ ${{env.branch}} == "master" ]]; then
30+
version="$(date +'%Y.%m.%d')-${{github.run_number}}"
31+
else
32+
version="$(date +'%Y.%m.%d')-${branch}-${{github.run_number}}"
33+
fi
34+
version=$(echo $version | sed 's/"//g')
35+
echo "version=$version"
36+
echo "version=$version" >> $GITHUB_ENV
37+
38+
- name: Set LAST_COMPLETED_JOB_SHA1
39+
shell: bash
40+
run: |
41+
if [[ '${{ inputs.clean_build }}' == 'true' ]]; then
42+
echo "clean build, will bundle & test all"
43+
echo "LAST_COMPLETED_JOB_SHA1=None" >> $GITHUB_ENV
44+
else
45+
.github/helpers/set-last-completed-job-sha1.sh
46+
fi
47+
48+
- name: print debug info
49+
shell: bash
50+
run: |
51+
echo "previous successful build sha: ${LAST_COMPLETED_JOB_SHA1}"
52+
echo "previous successful version: $(git tag --points-at ${LAST_COMPLETED_JOB_SHA1})"
53+
echo "latest cache sha: ${LATEST_CACHE_SHA1}"
54+
echo "branch: ${branch}"
55+
echo "version: ${version}"
56+
57+
# /set vars

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
# set vars
3434
- name: set vars
35-
uses: whisklabs/gha-workflows/actions/set_vars@master
35+
uses: ./.github/actions/set_vars
3636
with:
3737
clean_build: ${{ github.event.inputs.clean_build }}
3838

@@ -43,7 +43,7 @@ jobs:
4343
distribution: 'temurin'
4444

4545
- name: restore cache
46-
uses: whisklabs/gha-workflows/actions/scala_restore_cache@master
46+
uses: ./.github/actions/scala_restore_cache
4747
with:
4848
clean_build: ${{ github.event.inputs.clean_build }}
4949

@@ -76,5 +76,5 @@ jobs:
7676
- name: label vcs
7777
run: git tag $version && git push --tag
7878
- name: Save Scala Cache
79-
uses: whisklabs/gha-workflows/actions/scala_save_cache@master
79+
uses: ./.github/actions/scala_save_cache
8080

0 commit comments

Comments
 (0)