Skip to content

Commit 1cc0213

Browse files
authored
Use hashing instead of timestamps (#1)
* Use hashing instead of timestamps * change CI routines
1 parent f0e1c5a commit 1cc0213

File tree

10 files changed

+260
-24
lines changed

10 files changed

+260
-24
lines changed

.envrc

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

.github/workflows/ci.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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' }}
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
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
24+
SBT_NATIVE_CLIENT: "true"
25+
steps:
26+
- id: checkout
27+
uses: actions/checkout@v3
28+
with:
29+
fetch-depth: 100
30+
fetch-tags: true
31+
sparse-checkout-cone-mode: false
32+
33+
# set vars
34+
- name: set vars
35+
uses: whisklabs/gha-workflows/actions/set_vars@master
36+
with:
37+
clean_build: ${{ github.event.inputs.clean_build }}
38+
39+
- name: Setup Scala
40+
uses: actions/setup-java@v4
41+
with:
42+
java-version: "21"
43+
distribution: 'temurin'
44+
45+
- name: restore cache
46+
uses: whisklabs/gha-workflows/actions/scala_restore_cache@master
47+
with:
48+
clean_build: ${{ github.event.inputs.clean_build }}
49+
50+
- name: Setup M2 Credentials
51+
run: mkdir -p ~/.m2 && echo ${{secrets.M2_CREDENTIALS}} | base64 -d > ~/.m2/.credentials
52+
53+
- name: set branch
54+
run: |
55+
branch="$(echo -n ${{ github.event.ref }} | sed 's#refs/heads/##g; s#/#-#g' | tr '[:upper:]' '[:lower:]')"
56+
echo "branch=\"${branch}\"" >> $GITHUB_ENV
57+
58+
- name: set new version
59+
run: |
60+
if [[ ${{env.branch}} == "master" ]]; then
61+
version="$(date +'%Y.%m.%d')-${{github.run_number}}"
62+
else
63+
version="$(date +'%Y.%m.%d')-${branch}-${{github.run_number}}"
64+
fi
65+
version=$(echo $version | sed 's/"//g')
66+
echo "version=$version"
67+
echo "version=$version" >> $GITHUB_ENV
68+
69+
- run: |
70+
echo "version in ThisBuild := \"${{env.version}}\"" > version.sbt
71+
72+
- run: sbt +outboxProcessor/docker:publishLocal
73+
74+
- run: docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASS}} quay.io
75+
- run: docker push quay.io/whisk/outbox-processor:${{env.version}}
76+
- name: label vcs
77+
run: git tag $version && git push --tag
78+
- name: Save Scala Cache
79+
uses: whisklabs/gha-workflows/actions/scala_save_cache@master
80+

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ project/plugins/project/
2222
.scala_dependencies
2323
.worksheet
2424
metals.sbt
25+
26+
.direnv
27+
.share

build.sbt

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import sbt.Keys.publishMavenStyle
2+
13
name := "sbt-protoc"
24

5+
resolvers += "internal.repo.read" at "https://nexus.whisk-dev.com/repository/whisk-maven-group/"
6+
37
description := "SBT plugin for generating code from Protocol Buffer using protoc"
48

59
scalacOptions := Seq("-deprecation", "-unchecked", "-Xlint", "-Yno-adapted-args")
@@ -40,6 +44,15 @@ inThisBuild(
4044
4145
url("https://www.thesamet.com")
4246
)
43-
)
47+
),
48+
scmInfo := Some(
49+
ScmInfo(
50+
url("https://github.com/whisklabs/sbt-protoc"),
51+
"scm:git:github.com/whisklabs/sbt-protoc.git"
52+
)
53+
),
54+
publishMavenStyle := true,
55+
credentials += Credentials(Path.userHome / ".m2" / ".credentials"),
56+
publishTo := Some("internal.repo" at "https://nexus.whisk-dev.com/repository/whisk-maven2/")
4457
)
4558
)

flake.lock

+60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
description = "A flake for getting started with Scala.";
3+
inputs = {
4+
nixpkgs.url = "github:nixos/nixpkgs";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
};
7+
outputs =
8+
{ self
9+
, nixpkgs
10+
, flake-utils
11+
,
12+
}:
13+
let
14+
supportedSystems = [
15+
"aarch64-darwin"
16+
"aarch64-linux"
17+
"x86_64-linux"
18+
"x86_64-darwin"
19+
];
20+
in
21+
flake-utils.lib.eachSystem supportedSystems (
22+
system:
23+
let
24+
buildOverlays =
25+
{ nixpkgs, system, ... }:
26+
let
27+
pkgs = import nixpkgs { inherit system; };
28+
makeOverlays =
29+
let
30+
armOverlay =
31+
_: prev:
32+
let
33+
pkgsForx86 = import nixpkgs { localSystem = "x86_64-darwin"; };
34+
in
35+
prev.lib.optionalAttrs (prev.stdenv.isDarwin && prev.stdenv.isAarch64) {
36+
inherit (pkgsForx86) bloop;
37+
};
38+
ammoniteOverlay = final: prev: { ammonite = prev.ammonite.override { jre = pkgs.graalvm-ce; }; };
39+
bloopOverlay = final: prev: { bloop = prev.bloop.override { jre = final.graalvm-ce; }; };
40+
scalaCliOverlay = final: prev: { scala-cli = prev.scala-cli.override { jre = final.graalvm-ce; }; };
41+
javaOverlay = final: _: {
42+
jdk = pkgs.graalvm-ce;
43+
jre = pkgs.graalvm-ce;
44+
};
45+
in
46+
[
47+
javaOverlay
48+
armOverlay
49+
bloopOverlay
50+
scalaCliOverlay
51+
ammoniteOverlay
52+
];
53+
54+
makePackages =
55+
let
56+
overlays = makeOverlays;
57+
in
58+
import nixpkgs { inherit system overlays; };
59+
default = makePackages;
60+
in
61+
{
62+
inherit default;
63+
};
64+
65+
pkgs = buildOverlays { inherit nixpkgs system; };
66+
java = pkgs.default.graalvm-ce;
67+
in
68+
{
69+
devShells.default = pkgs.default.mkShell {
70+
buildInputs = with pkgs.default; [
71+
ammonite
72+
bloop
73+
coursier
74+
graalvm-ce
75+
sbt
76+
scala-cli
77+
scalafmt
78+
];
79+
shellHook = ''
80+
#SHOVE THIS JDK SOMEWHERE TO MAKE IDEA HAPPY
81+
mkdir -p ./.share
82+
if [ -L "./.share/java" ]; then
83+
unlink "./.share/java"
84+
fi
85+
ln -sf ${java} ./.share/java
86+
'';
87+
};
88+
formatter = pkgs.default.nixpkgs-fmt;
89+
}
90+
);
91+
}

project/plugins.sbt

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
33
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
44

55
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0")
6+
7+
credentials += Credentials(Path.userHome / ".m2" / ".credentials")
8+
resolvers += "internal.repo.read" at "https://nexus.whisk-dev.com/repository/whisk-maven-group/"
9+
addSbtPlugin("com.whisk" % "whisk-sbt-plugin" % "2024.10.29-2357")

shell.nix

-17
This file was deleted.

src/main/scala/sbtprotoc/ProtocPlugin.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ object ProtocPlugin extends AutoPlugin {
484484
val cached = FileFunction.cached(
485485
streams.cacheDirectory / dep.name,
486486
inStyle = FilesInfo.lastModified,
487-
outStyle = FilesInfo.exists
487+
outStyle = FilesInfo.hash
488488
) { deps =>
489489
IO.createDirectory(extractTarget)
490490
deps.flatMap { dep =>
@@ -539,7 +539,7 @@ object ProtocPlugin extends AutoPlugin {
539539
private[this] val classloaderCache =
540540
new java.util.concurrent.ConcurrentHashMap[
541541
BridgeArtifact,
542-
(FilesInfo[ModifiedFileInfo], URLClassLoader)
542+
(FilesInfo[HashFileInfo], URLClassLoader)
543543
]
544544

545545
private[this] def schemasTask(key: TaskKey[_]): Def.Initialize[Task[Set[File]]] = Def.task {
@@ -612,7 +612,7 @@ object ProtocPlugin extends AutoPlugin {
612612
// stamped and compared with the previous stamp to reload the classloader upon changes. Artifact resolution is
613613
// memoized across invocations for the entire sbt session, unless cacheArtifactResolution is false.
614614
val stampedClassLoadersByArtifact
615-
: Map[BridgeArtifact, (FilesInfo[ModifiedFileInfo], ClassLoader)] =
615+
: Map[BridgeArtifact, (FilesInfo[HashFileInfo], ClassLoader)] =
616616
targets
617617
.collect { case Target(SandboxedJvmGenerator(_, artifact, _, _), _, _) => artifact }
618618
.distinct
@@ -622,7 +622,7 @@ object ProtocPlugin extends AutoPlugin {
622622
{ (_, prevValue) =>
623623
def stampClasspath(files: Seq[File]) =
624624
// artifact paths can be JARs or directories, so a recursive stamp is needed
625-
FileInfo.lastModified(files.toSet[File].allPaths.get.toSet)
625+
FileInfo.hash(files.toSet[File].allPaths.get.toSet)
626626

627627
if (prevValue == null) {
628628
// first time this classpath is requested since the start of sbt
@@ -681,7 +681,7 @@ object ProtocPlugin extends AutoPlugin {
681681
}
682682

683683
import CacheImplicits._
684-
type Stamp = (Arguments, Seq[FilesInfo[ModifiedFileInfo]])
684+
type Stamp = (Arguments, Seq[FilesInfo[HashFileInfo]])
685685
val cachedCompile = Tracked.inputChanged[Stamp, Set[File]](
686686
cacheFile / "input"
687687
) { case (inChanged, _) =>
@@ -711,7 +711,7 @@ object ProtocPlugin extends AutoPlugin {
711711
val sandboxedArtifactsStamps =
712712
stampedClassLoadersByArtifact.values.map(_._1).toSeq
713713
val inputStamp =
714-
FileInfo.lastModified(schemas ++ arguments.includePaths.allPaths.get)
714+
FileInfo.hash(schemas ++ arguments.includePaths.allPaths.get)
715715
cachedCompile((arguments, sandboxedArtifactsStamps :+ inputStamp)).toSeq
716716
}
717717
}

version.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ThisBuild / version := sys.env.getOrElse("BUILD_VERSION", "0.1.0")

0 commit comments

Comments
 (0)