From 32c27a4f82b06aed405bd548d5daa37992983450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kapica?= Date: Sat, 22 Jun 2024 20:33:36 +0200 Subject: [PATCH 1/3] Setup basic CI using github workflows --- .github/workflows/ci.yaml | 74 +++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..da93e36 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,74 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: { } + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/api + +jobs: + test-api: + name: Test API + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: 'api' + - run: "find ./api -maxdepth 1 -mindepth 1 -exec mv {} . \\; && rm -r ./api" + - name: Setup JDK + uses: actions/setup-java@v3 + with: + distribution: corretto + java-version: 21 + cache: sbt + - name: Install sbt + run: | + sudo apt-get update + sudo apt-get install apt-transport-https curl gnupg -yqq + echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list + echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list + curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo -H gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --import + sudo chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpg + sudo apt-get update + sudo apt-get install sbt + - name: Build and Test + run: sbt -v +test + + build-api-image: + name: Build API Image + needs: test-api + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: 'api' + - run: "find ./api -maxdepth 1 -mindepth 1 -exec mv {} . \\; && rm -r api" + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0bec053..1ee53af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env *.iml .idea/* !.idea/codeStyles From d12d5fc5be0bd634629372c7397949eab720fdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kapica?= Date: Sat, 22 Jun 2024 21:34:24 +0200 Subject: [PATCH 2/3] Add checking for scalafmt conformance --- .github/workflows/ci.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index da93e36..a3a0612 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,6 +28,12 @@ jobs: with: sparse-checkout: 'api' - run: "find ./api -maxdepth 1 -mindepth 1 -exec mv {} . \\; && rm -r ./api" + - name: Check for scalafmt conformance + run: | + curl -fL "https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz" | gzip -d > cs + chmod +x cs + cs install scalafmt + ./cs scalafmt --check - name: Setup JDK uses: actions/setup-java@v3 with: From 6efbc12b38c6c1c1e70f33fc251623225a6a7b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kapica?= Date: Sat, 22 Jun 2024 21:39:02 +0200 Subject: [PATCH 3/3] Add checking for scalafmt conformance --- .github/workflows/ci.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a3a0612..221b3e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,12 +28,15 @@ jobs: with: sparse-checkout: 'api' - run: "find ./api -maxdepth 1 -mindepth 1 -exec mv {} . \\; && rm -r ./api" + - uses: coursier/cache-action@v6.3 + - uses: VirtusLab/scala-cli-setup@v0.1 - name: Check for scalafmt conformance run: | - curl -fL "https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz" | gzip -d > cs - chmod +x cs - cs install scalafmt - ./cs scalafmt --check + scala-cli fmt --check . || ( + echo "To format code run" + echo " scala-cli fmt ." + exit 1 + ) - name: Setup JDK uses: actions/setup-java@v3 with: