Skip to content

Commit 9a4cbd7

Browse files
committed
Adopt publishing and tagging
1 parent 23cf88d commit 9a4cbd7

File tree

16 files changed

+474
-129
lines changed

16 files changed

+474
-129
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/FUNDING.yml

-1
This file was deleted.
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
set -exo pipefail
3+
4+
### find previous sucessfull tag
5+
# shellcheck disable=SC2154
6+
if [[ ${branch} == "master" ]]; then
7+
prev_build=$(git describe --tags --abbrev=0 --first-parent --exclude='????.??.??-*-*')
8+
else
9+
prev_build=$(git describe --tags --abbrev=0 --first-parent)
10+
fi
11+
# if we have multiple tags on same commit, pick latest
12+
prev_build=$(git tag --points-at "${prev_build}" | sort | tail -n 1)
13+
git_prev_build_sha=$(git rev-list -n1 "${prev_build}")
14+
15+
function get_diff_count() {
16+
changed=$(git diff "${1}" --shortstat -- | awk '{print $1}')
17+
if [[ -z $changed ]]; then
18+
changed=0
19+
fi
20+
echo -n $changed
21+
}
22+
LAST_COMPLETED_JOB_SHA1=${git_prev_build_sha}
23+
24+
25+
# this needed as we have tag only healthy builds. And probably don't want to compare with unhealthy build
26+
master_tag=$(git describe --tags --abbrev=0 --first-parent --exclude='????.??.??-*-*' origin/master)
27+
master_sha=$(git rev-list -n1 "${master_tag}")
28+
changes_master=$(get_diff_count "${master_sha}")
29+
30+
changes_git_tag=$(get_diff_count "${git_prev_build_sha}")
31+
32+
changes_current_candidate=$(get_diff_count "${LAST_COMPLETED_JOB_SHA1}")
33+
34+
if [[ ${changes_current_candidate} -gt ${changes_master} ]]; then
35+
echo "as previuos will choose version from master ${master_tag}"
36+
LAST_COMPLETED_JOB_SHA1=${master_sha}
37+
changes_current_candidate=$(get_diff_count "${LAST_COMPLETED_JOB_SHA1}")
38+
elif [[ ${changes_current_candidate} -gt ${changes_git_tag} ]]; then
39+
echo "as previuos will choose version from git tag ${prev_build}"
40+
LAST_COMPLETED_JOB_SHA1=${git_prev_build_sha}
41+
changes_current_candidate=$(get_diff_count "${LAST_COMPLETED_JOB_SHA1}")
42+
fi
43+
echo "LAST_COMPLETED_JOB_SHA1=${LAST_COMPLETED_JOB_SHA1}" >> $GITHUB_ENV
44+
45+
46+
LATEST_CACHE_SHA1=${LAST_COMPLETED_JOB_SHA1}
47+
48+
49+
set +xo pipefail
50+
retrive_tag_num=30
51+
last_builds=$(git tag -l --sort='-authordate' | head -n "${retrive_tag_num}" | uniq)
52+
set -o pipefail
53+
last_builds_array=($last_builds)
54+
tmp_dir='/tmp/'
55+
# changes_current_candidate
56+
(get_diff_count "${LATEST_CACHE_SHA1}"; echo -n " ${LATEST_CACHE_SHA1}") > "$tmp_dir/current.diff" &
57+
# git tags
58+
for i in $(seq 0 "$((retrive_tag_num-1))"); do
59+
(get_diff_count "${last_builds_array[$i]}"; echo " ${last_builds_array[$i]}") > "$tmp_dir/$i.diff" &
60+
done
61+
wait
62+
cache_candidate=$(cat "$tmp_dir"/*.diff | sort -n | head -n 1)
63+
tag_with_min_changes=$(echo "$cache_candidate" | awk '{print $2}')
64+
min_changes=$(echo "$cache_candidate" | awk '{print $1}')
65+
66+
echo "as previous will choose version from commit ${tag_with_min_changes} with ${min_changes} changes"
67+
LATEST_CACHE_SHA1=$(git rev-list -n1 "${tag_with_min_changes}")
68+
changes_current_candidate=$(get_diff_count "${LATEST_CACHE_SHA1}")
69+
70+
echo "LATEST_CACHE_SHA1=${LATEST_CACHE_SHA1}" >> $GITHUB_ENV

.github/workflows/ci.yml

+73-74
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,77 @@
1-
name: CI
2-
3-
on: [push, pull_request]
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
workflow_dispatch:
7+
inputs:
8+
clean_build:
9+
description: 'build all'
10+
required: false
11+
default: false
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ github.ref_name != 'master' }}
415

516
jobs:
6-
build:
7-
runs-on: ${{matrix.os}}
8-
strategy:
9-
matrix:
10-
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
11-
12-
steps:
13-
- uses: actions/checkout@v4
14-
- uses: olafurpg/setup-scala@v14
15-
with:
16-
java-version: 8
17-
- name: Mount caches
18-
uses: actions/cache@v2
19-
with:
20-
path: |
21-
~/.sbt
22-
~/.ivy2/cache
23-
~/.cache/coursier
24-
key: ${{ runner.os }}-sbt-${{ hashFiles('**/*.sbt') }}
25-
- name: Remove native tests (Windows only)
26-
if: ${{ runner.os == 'Windows' }}
27-
run: |
28-
rm -rf examples/scalapb-crossproject
29-
shell: bash
30-
- name: Compile and test
31-
run: |
32-
sbt test
33-
cd examples
34-
for d in */ ; do cd "$d" && sbt test && cd ../ ; done
35-
shell: bash
36-
- name: Format check
37-
if: ${{ runner.os == 'Linux' }}
38-
run: |
39-
sbt scalafmtCheck test:scalafmtCheck scalafmtSbtCheck
40-
scripted:
41-
runs-on: ${{matrix.os}}
42-
strategy:
43-
fail-fast: false
44-
matrix:
45-
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
46-
scripted-sbt: ["1.2.8", "1.3.13", "project"]
47-
48-
steps:
49-
- uses: actions/checkout@v4
50-
- uses: olafurpg/setup-scala@v14
51-
with:
52-
java-version: 11
53-
- name: Mount caches
54-
uses: actions/cache@v2
55-
with:
56-
path: |
57-
~/.sbt
58-
~/.ivy2/cache
59-
~/.cache/coursier
60-
key: ${{ runner.os }}-sbt-${{ hashFiles('**/*.sbt') }}
61-
- name: Compile and run scripted tests with older version
62-
if: ${{ matrix.scripted-sbt != 'project' }}
63-
env:
64-
SCRIPTED_SBT: ${{ matrix.scripted-sbt }}
65-
run: |
66-
sbt "set scriptedSbt := \"$SCRIPTED_SBT\"" scripted
67-
shell: bash
68-
- name: Compile and run scripted tests with project version
69-
if: ${{ matrix.scripted-sbt == 'project' }}
70-
run: |
71-
sbt "set scriptedSbt := sbtVersion.value" scripted
72-
shell: bash
73-
# Single final job for mergify.
74-
ci-passed:
17+
test:
7518
runs-on: ubuntu-latest
76-
needs: [build, scripted]
19+
timeout-minutes: 25
20+
env:
21+
# define Java options for both official sbt and sbt-extras
22+
JAVA_OPTS: -XX:MinRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
23+
JVM_OPTS: -XX:MinRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
7724
steps:
78-
- run: ':'
25+
- id: checkout
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 100
29+
fetch-tags: true
30+
sparse-checkout-cone-mode: false
31+
32+
# set vars
33+
- name: set vars
34+
uses: ./.github/actions/set_vars
35+
with:
36+
clean_build: ${{ github.event.inputs.clean_build }}
37+
38+
- name: Setup Scala
39+
uses: actions/setup-java@v4
40+
with:
41+
java-version: "21"
42+
distribution: 'temurin'
43+
44+
- name: restore cache
45+
uses: ./.github/actions/scala_restore_cache
46+
with:
47+
clean_build: ${{ github.event.inputs.clean_build }}
48+
49+
- name: Setup M2 Credentials
50+
run: mkdir -p ~/.m2 && echo ${{secrets.M2_CREDENTIALS}} | base64 -d > ~/.m2/.credentials
51+
52+
- name: set branch
53+
run: |
54+
branch="$(echo -n ${{ github.event.ref }} | sed 's#refs/heads/##g; s#/#-#g' | tr '[:upper:]' '[:lower:]')"
55+
echo "branch=\"${branch}\"" >> $GITHUB_ENV
56+
57+
- name: set new version
58+
run: |
59+
if [[ ${{env.branch}} == "master" ]]; then
60+
version="$(date +'%Y.%m.%d')-${{github.run_number}}"
61+
else
62+
version="$(date +'%Y.%m.%d')-${branch}-${{github.run_number}}"
63+
fi
64+
version=$(echo $version | sed 's/"//g')
65+
echo "version=$version"
66+
echo "version=$version" >> $GITHUB_ENV
67+
68+
- run: |
69+
echo "version in ThisBuild := \"${{env.version}}\"" > version.sbt
70+
71+
- run: sbt publish
72+
73+
- name: label vcs
74+
run: git tag $version && git push --tag
75+
- name: Save Scala Cache
76+
uses: ./.github/actions/scala_save_cache
77+

0 commit comments

Comments
 (0)