Skip to content

Commit

Permalink
Use scala.js for executable and docker image (#531)
Browse files Browse the repository at this point in the history
* WIP

* More WIP

* More WIP

* Remove

* Remove

* More WIP

* WIP

* More WIP

* WIP

* We are compiling!

* more WIP

* WIP

* Things run now

* more WIP

* cleanup

* trying this but no luck

* delete logs file

* snapshots

* fs2-io

* fmt

* add map file, enable source maps

* don't rename file

* fix jvmopts

* Update java version

* More fixes for GHA

* More fixes

* fix

* Only run integration tests on JS CI

* More fixes

* Publish steps

* Fix linking steps, add compile step

* New FS2 snapshot, re-add logback to integration tests

* We are up and running!!

* efficiency

* Doc Updates

* Make scalafix happy

* Increase timeout

* Update docker push

* Support publishing to NPM

* enable binary

* Fix CI

* FullOpt, retry unit tests

* Dont load source maps in docker image

* Retry integration tests, add keywords

* Set scope

* properly scope package

* fmt

* fix CI

* Bump http4s

* Bump FS2

* Update LibraryDependencies.scala
  • Loading branch information
etspaceman committed Jul 31, 2023
1 parent df542e2 commit 78a63c4
Show file tree
Hide file tree
Showing 301 changed files with 6,639 additions and 1,708 deletions.
318 changes: 318 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
pull_request:
branches: ['**', '!update/**', '!pr/**']
push:
branches: ['**', '!update/**', '!pr/**']

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.11]
java: [temurin@17]
cbor_enabled: [true, false]
service_port: [4567, 4568]
project: [root-jvm-213, root-js-213]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v3
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

- name: Compile
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' cpl

- name: Link JS
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest' && startsWith(matrix.project, 'root-js')
run: sbt 'project ${{ matrix.project }}' fastLinkJS

- name: Link Test JS
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest' && startsWith(matrix.project, 'root-js')
run: sbt 'project ${{ matrix.project }}' Test/fastLinkJS

- name: Unit Tests
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
uses: nick-fields/retry@v2
with:
timeout_minutes: 15
max_attempts: 3
command: sbt 'project ${{ matrix.project }}' unit-tests/test
retry_on: error

- name: Docker Compose Up
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest' && startsWith(matrix.project, 'root-js')
uses: nick-fields/retry@v2
with:
timeout_minutes: 15
retry_on: error
command: sbt 'project ${{ matrix.project }}' dockerComposeUp
on_retry_command: sbt 'project ${{ matrix.project }}' dockerComposeDown
max_attempts: 3

- name: Integration Tests
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest' && startsWith(matrix.project, 'root-js')
uses: nick-fields/retry@v2
with:
timeout_minutes: 15
max_attempts: 3
command: sbt 'project ${{ matrix.project }}' integration-tests/test
retry_on: error

- name: Print docker logs and container listing
if: ${{ failure() }}
run: sbt 'project ${{ matrix.project }}' dockerComposePs dockerComposeLogs

- name: Remove docker containers
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest' && startsWith(matrix.project, 'root-js')
run: sbt 'project ${{ matrix.project }}' dockerComposeDown

- name: Check scalafix lints
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' fixCheck

publishDocker:
name: Publish Docker Image
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v3
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Compile
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' cpl

- name: Link JS
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' fullLinkJS

- name: Build Docker Image
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' kinesis-mockJS/buildDockerImage

- name: Login to registry
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Push to registry
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: 'docker push ghcr.io/etspaceman/kinesis-mock:${{ github.event.release.tag_name }}'

publishJSAssets:
name: Publish JS Assets
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v3
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Compile
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' cpl

- name: Link JS
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' fullLinkJS

- name: Upload main.js
env:
GITHUB_TOKEN: '{{ secrets.GITHUB_TOKEN }}'
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./docker/image/lib/main.js
asset_name: main.js
asset_content_type: text/javascript

- name: Upload main.js.map
env:
GITHUB_TOKEN: '{{ secrets.GITHUB_TOKEN }}'
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./docker/image/lib/main.js.map
asset_name: main.js.map
asset_content_type: application/json

publishNPM:
name: Publish To NPM
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v3
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Compile
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' cpl

- name: Link JS
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' fullLinkJS

- name: Setup Node
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
env:
GITHUB_TOKEN: '{{ secrets.GITHUB_TOKEN }}'
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install artifacts to NPM
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' npmPackageInstall

- name: Publish artifacts to NPM
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: sbt '++ ${{ matrix.scala }}' npmPackageNpmrc npmPackagePublish
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$
# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT
# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do
# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")
# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE
# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do
# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done

0 comments on commit 78a63c4

Please sign in to comment.