Skip to content

Commit

Permalink
Use hashing instead of timestamps (#1)
Browse files Browse the repository at this point in the history
* Use hashing instead of timestamps

* change CI routines
  • Loading branch information
fido-node authored Nov 5, 2024
1 parent f0e1c5a commit 1cc0213
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 24 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: ci
on:
push:
branches:
- '**'
workflow_dispatch:
inputs:
clean_build:
description: 'build all'
required: false
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref_name != 'master' }}

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 25
env:
# define Java options for both official sbt and sbt-extras
JAVA_OPTS: -XX:MinRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
JVM_OPTS: -XX:MinRAMPercentage=70.0 -XX:MaxRAMPercentage=70.0 -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
SBT_NATIVE_CLIENT: "true"
steps:
- id: checkout
uses: actions/checkout@v3
with:
fetch-depth: 100
fetch-tags: true
sparse-checkout-cone-mode: false

# set vars
- name: set vars
uses: whisklabs/gha-workflows/actions/set_vars@master
with:
clean_build: ${{ github.event.inputs.clean_build }}

- name: Setup Scala
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: 'temurin'

- name: restore cache
uses: whisklabs/gha-workflows/actions/scala_restore_cache@master
with:
clean_build: ${{ github.event.inputs.clean_build }}

- name: Setup M2 Credentials
run: mkdir -p ~/.m2 && echo ${{secrets.M2_CREDENTIALS}} | base64 -d > ~/.m2/.credentials

- name: set branch
run: |
branch="$(echo -n ${{ github.event.ref }} | sed 's#refs/heads/##g; s#/#-#g' | tr '[:upper:]' '[:lower:]')"
echo "branch=\"${branch}\"" >> $GITHUB_ENV
- name: set new version
run: |
if [[ ${{env.branch}} == "master" ]]; then
version="$(date +'%Y.%m.%d')-${{github.run_number}}"
else
version="$(date +'%Y.%m.%d')-${branch}-${{github.run_number}}"
fi
version=$(echo $version | sed 's/"//g')
echo "version=$version"
echo "version=$version" >> $GITHUB_ENV
- run: |
echo "version in ThisBuild := \"${{env.version}}\"" > version.sbt
- run: sbt +outboxProcessor/docker:publishLocal

- run: docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASS}} quay.io
- run: docker push quay.io/whisk/outbox-processor:${{env.version}}
- name: label vcs
run: git tag $version && git push --tag
- name: Save Scala Cache
uses: whisklabs/gha-workflows/actions/scala_save_cache@master

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ project/plugins/project/
.scala_dependencies
.worksheet
metals.sbt

.direnv
.share
15 changes: 14 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import sbt.Keys.publishMavenStyle

name := "sbt-protoc"

resolvers += "internal.repo.read" at "https://nexus.whisk-dev.com/repository/whisk-maven-group/"

description := "SBT plugin for generating code from Protocol Buffer using protoc"

scalacOptions := Seq("-deprecation", "-unchecked", "-Xlint", "-Yno-adapted-args")
Expand Down Expand Up @@ -40,6 +44,15 @@ inThisBuild(
"[email protected]",
url("https://www.thesamet.com")
)
)
),
scmInfo := Some(
ScmInfo(
url("https://github.com/whisklabs/sbt-protoc"),
"scm:git:github.com/whisklabs/sbt-protoc.git"
)
),
publishMavenStyle := true,
credentials += Credentials(Path.userHome / ".m2" / ".credentials"),
publishTo := Some("internal.repo" at "https://nexus.whisk-dev.com/repository/whisk-maven2/")
)
)
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
description = "A flake for getting started with Scala.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{ self
, nixpkgs
, flake-utils
,
}:
let
supportedSystems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
"x86_64-darwin"
];
in
flake-utils.lib.eachSystem supportedSystems (
system:
let
buildOverlays =
{ nixpkgs, system, ... }:
let
pkgs = import nixpkgs { inherit system; };
makeOverlays =
let
armOverlay =
_: prev:
let
pkgsForx86 = import nixpkgs { localSystem = "x86_64-darwin"; };
in
prev.lib.optionalAttrs (prev.stdenv.isDarwin && prev.stdenv.isAarch64) {
inherit (pkgsForx86) bloop;
};
ammoniteOverlay = final: prev: { ammonite = prev.ammonite.override { jre = pkgs.graalvm-ce; }; };
bloopOverlay = final: prev: { bloop = prev.bloop.override { jre = final.graalvm-ce; }; };
scalaCliOverlay = final: prev: { scala-cli = prev.scala-cli.override { jre = final.graalvm-ce; }; };
javaOverlay = final: _: {
jdk = pkgs.graalvm-ce;
jre = pkgs.graalvm-ce;
};
in
[
javaOverlay
armOverlay
bloopOverlay
scalaCliOverlay
ammoniteOverlay
];

makePackages =
let
overlays = makeOverlays;
in
import nixpkgs { inherit system overlays; };
default = makePackages;
in
{
inherit default;
};

pkgs = buildOverlays { inherit nixpkgs system; };
java = pkgs.default.graalvm-ce;
in
{
devShells.default = pkgs.default.mkShell {
buildInputs = with pkgs.default; [
ammonite
bloop
coursier
graalvm-ce
sbt
scala-cli
scalafmt
];
shellHook = ''
#SHOVE THIS JDK SOMEWHERE TO MAKE IDEA HAPPY
mkdir -p ./.share
if [ -L "./.share/java" ]; then
unlink "./.share/java"
fi
ln -sf ${java} ./.share/java
'';
};
formatter = pkgs.default.nixpkgs-fmt;
}
);
}
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0")

credentials += Credentials(Path.userHome / ".m2" / ".credentials")
resolvers += "internal.repo.read" at "https://nexus.whisk-dev.com/repository/whisk-maven-group/"
addSbtPlugin("com.whisk" % "whisk-sbt-plugin" % "2024.10.29-2357")
17 changes: 0 additions & 17 deletions shell.nix

This file was deleted.

12 changes: 6 additions & 6 deletions src/main/scala/sbtprotoc/ProtocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ object ProtocPlugin extends AutoPlugin {
val cached = FileFunction.cached(
streams.cacheDirectory / dep.name,
inStyle = FilesInfo.lastModified,
outStyle = FilesInfo.exists
outStyle = FilesInfo.hash
) { deps =>
IO.createDirectory(extractTarget)
deps.flatMap { dep =>
Expand Down Expand Up @@ -539,7 +539,7 @@ object ProtocPlugin extends AutoPlugin {
private[this] val classloaderCache =
new java.util.concurrent.ConcurrentHashMap[
BridgeArtifact,
(FilesInfo[ModifiedFileInfo], URLClassLoader)
(FilesInfo[HashFileInfo], URLClassLoader)
]

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

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

import CacheImplicits._
type Stamp = (Arguments, Seq[FilesInfo[ModifiedFileInfo]])
type Stamp = (Arguments, Seq[FilesInfo[HashFileInfo]])
val cachedCompile = Tracked.inputChanged[Stamp, Set[File]](
cacheFile / "input"
) { case (inChanged, _) =>
Expand Down Expand Up @@ -711,7 +711,7 @@ object ProtocPlugin extends AutoPlugin {
val sandboxedArtifactsStamps =
stampedClassLoadersByArtifact.values.map(_._1).toSeq
val inputStamp =
FileInfo.lastModified(schemas ++ arguments.includePaths.allPaths.get)
FileInfo.hash(schemas ++ arguments.includePaths.allPaths.get)
cachedCompile((arguments, sandboxedArtifactsStamps :+ inputStamp)).toSeq
}
}
Expand Down
1 change: 1 addition & 0 deletions version.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ThisBuild / version := sys.env.getOrElse("BUILD_VERSION", "0.1.0")

0 comments on commit 1cc0213

Please sign in to comment.