Skip to content

Commit

Permalink
Add Windows to CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
austek committed Aug 30, 2024
1 parent abc10e8 commit 9bc0eb5
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 93 deletions.
74 changes: 60 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,35 @@ on:
tags: [v*]

env:
PACT_BROKER_BASE_URL: 'https://test.pactflow.io'
PACT_BROKER_USERNAME: dXfltyFMgNOFZAxr8io9wJ37iUpY42M
PACT_BROKER_PASSWORD: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [3.3.4-RC1]
os: [ubuntu-latest, macos-latest, windows-2019]
scala: [3.5.0]
java: [zulu@17, zulu@20]
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
if: contains(runner.os, 'windows')
shell: bash
run: git config --global core.autocrlf false

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/[email protected]
with:
minimum-size: 2GB
maximum-size: 8GB
disk-root: 'C:'

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand All @@ -52,28 +69,45 @@ jobs:
uses: sbt/setup-sbt@v1

- name: Check that workflows are up to date
shell: bash
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

- name: Start containers
run: docker compose -f docker-compose.yml up -d
- name: Set outputs
id: vars
shell: bash
run: |
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
echo "git_tag=$(git describe --tags)" >> $GITHUB_OUTPUT
- name: Pactflow Setup
uses: pactflow/actions@main

- name: Build project
shell: bash
run: sbt '++ ${{ matrix.scala }}' compile scalafmtCheckAll javafmtCheckAll plugin/test

- name: Test Consumer
shell: bash
run: sbt '++ ${{ matrix.scala }}' consumer/test

- name: Upload Consumer Pact
run: ./scripts/pact-publish.sh
- name: Pact publish Windows
if: contains(runner.os, 'windows')
shell: bash
run: pact-broker.bat publish "modules/examples/consumer/target/pacts" --consumer-app-version=${{ steps.vars.outputs.git_tag }}-${{ runner.os }} --tag=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}

- name: Pact publish *nix
if: '!contains(runner.os, ''windows'')'
shell: bash
run: pact-broker publish "modules/examples/consumer/target/pacts" --consumer-app-version=${{ steps.vars.outputs.git_tag }}-${{ runner.os }} --tag=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}

- name: Test Provider
env:
PACT_BROKER_TAG: ${{ steps.vars.outputs.git_tag }}-${{ runner.os }}
shell: bash
run: sbt '++ ${{ matrix.scala }}' provider/test

- name: Stop containers
if: always()
run: docker compose -f docker-compose.yml down

- name: Compress target directories
shell: bash
run: tar cf targets.tar target modules/plugin/target modules/examples/provider/target modules/examples/consumer/target project/target

- name: Upload target directories
Expand All @@ -89,10 +123,22 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [3.3.4-RC1]
scala: [3.5.0]
java: [zulu@17]
runs-on: ${{ matrix.os }}
steps:
- name: Ignore line ending differences in git
if: contains(runner.os, 'windows')
run: git config --global core.autocrlf false

- name: Configure pagefile for Windows
if: contains(runner.os, 'windows')
uses: al-cheb/[email protected]
with:
minimum-size: 2GB
maximum-size: 8GB
disk-root: 'C:'

- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
Expand All @@ -117,12 +163,12 @@ jobs:
- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Download target directories (3.3.4-RC1)
- name: Download target directories (3.5.0)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-3.3.4-RC1-${{ matrix.java }}
name: target-${{ matrix.os }}-3.5.0-${{ matrix.java }}

- name: Inflate target directories (3.3.4-RC1)
- name: Inflate target directories (3.5.0)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
6 changes: 0 additions & 6 deletions CODEOWNERS

This file was deleted.

41 changes: 30 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ import PublishSettings.*
import TestEnvironment.*

ThisBuild / scalaVersion := scalaV
//ThisBuild / conflictManager := ConflictManager.strict

lazy val plugin = project
.in(file("modules/plugin"))
lazy val pactOptions: Seq[Tests.Argument] = Seq(
Some(sys.env.getOrElse("PACT_BROKER_BASE_URL", "http://localhost:9292")).map(s => s"-Dpactbroker.url=$s"),
sys.env.get("PACT_BROKER_USERNAME").map(s => s"-Dpactbroker.auth.username=$s"),
sys.env.get("PACT_BROKER_PASSWORD").map(s => s"-Dpactbroker.auth.password=$s"),
sys.env.get("PACT_BROKER_TAG").map(s => s"-Dpactbroker.consumerversionselectors.tags=$s"),
).flatten.map(o => Tests.Argument(jupiterTestFramework, o))

lazy val plugin = moduleProject("plugin", "plugin")
.enablePlugins(
GitHubPagesPlugin,
GitVersioning,
JavaAppPackaging,
// https://sbt-native-packager.readthedocs.io/en/stable/recipes/longclasspath.html#long-classpaths
LauncherJarPlugin
)
.settings(
git.useGitDescribe := true,
name := "plugin",
maintainer := "[email protected]",
basicSettings,
publishSettings,
testEnvSettings,
gitHubPagesOrgName := "austek",
Expand All @@ -28,29 +34,26 @@ lazy val plugin = project
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
),
libraryDependencies ++=
Dependencies.compile(apacheAvro, auPactMatchers, logback, pactCore, scalaLogging, scalaPBRuntime) ++
Dependencies.compile(apacheAvro, auPactMatchers, logback, scalaLogging, scalaPBRuntime) ++
Dependencies.protobuf(scalaPB) ++
Dependencies.test(scalaTest),
dependencyOverrides ++= Seq(grpcApi, grpcCore, grpcNetty)
)
lazy val pluginRef = LocalProject("plugin")

lazy val provider = project
.in(file("modules/examples/provider"))
lazy val provider = moduleProject("provider", "examples/provider")
.settings(
basicSettings,
Test / sbt.Keys.test := (Test / sbt.Keys.test).dependsOn(pluginRef / buildTestPluginDir).value,
Test / envVars := Map("PACT_PLUGIN_DIR" -> ((pluginRef / target).value / "plugin").absolutePath),
testOptions ++= pactOptions,
libraryDependencies ++=
Dependencies.compile(avroCompiler, logback, pulsar4sCore, pulsar4sAvro, scalacheck) ++
Dependencies.test(assertJCore, jUnitInterface, pactProviderJunit),
publish / skip := false
)

lazy val consumer = project
.in(file("modules/examples/consumer"))
lazy val consumer = moduleProject("consumer", "examples/consumer")
.settings(
basicSettings,
Compile / avroSource := (Compile / resourceDirectory).value / "avro",
Test / sbt.Keys.test := (Test / sbt.Keys.test).dependsOn(pluginRef / buildTestPluginDir).value,
Test / envVars := Map("PACT_PLUGIN_DIR" -> ((pluginRef / target).value / "plugin").absolutePath),
Expand All @@ -70,3 +73,19 @@ lazy val `pact-avro-plugin` = (project in file("."))
basicSettings,
publish / skip := false
)

def moduleProject(name: String, path: String): Project = {
Project(name, file(s"modules/$path"))
.enablePlugins(GitVersioning, ScalafmtPlugin)
.settings(
basicSettings,
moduleName := name,
git.useGitDescribe := true,
git.gitTagToVersionNumber := { tag: String =>
if(tag matches "v[0-9].*") {
Some(tag.drop(1).replaceAll("-[0-9]+-.+", ""))
}
else None
}
)
}
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
postgres:
image: postgres:15.2-alpine
image: postgres:16.4-alpine
platform: linux/amd64
healthcheck:
test: psql postgres --command "select 1" -U postgres
environment:
Expand All @@ -9,7 +10,8 @@ services:
POSTGRES_DB: postgres

pact-broker:
image: pactfoundation/pact-broker:2.113.0-pactbroker2.107.1-multi
image: pactfoundation/pact-broker
platform: linux/amd64
ports:
- "9292:9292"
depends_on:
Expand Down
51 changes: 38 additions & 13 deletions github-actions.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// sbt-github-actions

// Add windows-latest when https://github.com/sbt/sbt/issues/7082 is resolved
// Add macos-latest when step to install docker on it is done
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest")
ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest", "macos-latest", "windows-2019")
ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.zulu("17"),
JavaSpec.zulu("20")
)
ThisBuild / githubWorkflowTargetBranches := Seq("main")
ThisBuild / githubWorkflowTargetTags := Seq("v*")

ThisBuild / githubWorkflowEnv := Map(
"PACT_BROKER_BASE_URL" -> "https://test.pactflow.io",
"PACT_BROKER_USERNAME" -> "dXfltyFMgNOFZAxr8io9wJ37iUpY42M",
"PACT_BROKER_PASSWORD" -> "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1",
"GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}"
)
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Run(
name = Some("Start containers"),
commands = List("docker compose -f docker-compose.yml up -d")
name = Some("Set outputs"),
id = Some("vars"),
commands = List(
"""echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT""",
"""echo "git_tag=$(git describe --tags)" >> $GITHUB_OUTPUT"""
)
),
WorkflowStep.Use(
UseRef.Public("pactflow", "actions", "main"),
name = Some("Pactflow Setup")
),
WorkflowStep.Sbt(
name = Some("Build project"),
Expand All @@ -24,17 +37,29 @@ ThisBuild / githubWorkflowBuild := Seq(
commands = List("consumer/test")
),
WorkflowStep.Run(
name = Some("Upload Consumer Pact"),
commands = List("./scripts/pact-publish.sh")
name = Some("Pact publish Windows"),
commands = List("""pact-broker.bat publish
| "modules/examples/consumer/target/pacts"
| --consumer-app-version=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}
| --tag=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}
| """.stripMargin.replaceAll("\n", "")),
cond = Some("contains(runner.os, 'windows')")
),
WorkflowStep.Run(
name = Some("Pact publish *nix"),
commands = List("""pact-broker publish
| "modules/examples/consumer/target/pacts"
| --consumer-app-version=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}
| --tag=${{ steps.vars.outputs.git_tag }}-${{ runner.os }}
| """.stripMargin.replaceAll("\n", "")),
cond = Some("!contains(runner.os, 'windows')")
),
WorkflowStep.Sbt(
name = Some("Test Provider"),
commands = List("provider/test")
),
WorkflowStep.Run(
cond = Some("always()"),
name = Some("Stop containers"),
commands = List("docker compose -f docker-compose.yml down")
commands = List("provider/test"),
env = Map(
"PACT_BROKER_TAG" -> "${{ steps.vars.outputs.git_tag }}-${{ runner.os }}",
)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"type": "record",
"name": "OrderNewEvent",
"namespace": "com.collibra.event.client.examples.showcase.schema",
"namespace": "com.github.austek.event.client.examples.showcase.schema",
"fields": [
{
"name": "createdOn",
Expand All @@ -23,7 +23,7 @@
"items": {
"type": "record",
"name": "OrderItem",
"namespace": "com.collibra.event.client.examples.showcase.domain",
"namespace": "com.github.austek.event.client.examples.showcase.domain",
"fields": [
{
"name": "itemId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ class OrderConsumerController(config: ConsumerAppConfig) extends StrictLogging {
processOrderMessages(totalMessageCount + 1, f)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup;
import au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl;
import au.com.dius.pact.core.model.v4.MessageContents;
import com.collibra.event.client.examples.showcase.domain.OrderItem;
import com.collibra.event.client.examples.showcase.schema.OrderNewEvent;
import com.github.austek.event.client.examples.showcase.domain.OrderItem;
import com.github.austek.event.client.examples.showcase.schema.OrderNewEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -32,8 +34,14 @@
providerType = ProviderType.ASYNCH,
providerName = "OrderTopicV1")
class OrderV1ConsumerTest {
private final String schemasPath =
Objects.requireNonNull(getClass().getResource("/avro/order-v1.avsc")).getPath();
private final String schemasPath;

OrderV1ConsumerTest() throws URISyntaxException {
schemasPath =
Paths.get(Objects.requireNonNull(getClass().getResource("/avro/order-v1.avsc")).toURI())
.toFile()
.getAbsolutePath();
}

@Pact(consumer = "OrderTopicConsumer")
V4Pact configureRecordWithDependantRecord(PactBuilder builder) {
Expand Down
Loading

0 comments on commit 9bc0eb5

Please sign in to comment.