Skip to content

Commit

Permalink
CB-5228 feat: fast frontend unit tests (#2677)
Browse files Browse the repository at this point in the history
* fix: try to fix make docker container.sh

* fix: specify correct docker build scripts folder

* fix: validate branch to valid docker tag name

* feat: combined workflows

* feat: add readable names for github actions

* feat: add docker pull command comment

* fix: comment publishing comment with docker instructions

* feat: improve build & test performance

* feat: add option to skip cache

* fix: flush cache

* fix: flush cache

* feat: merge tests and build steps

* fix: github action outputs keys

* feat: add lint job

* feat: change file to trigger lint

* fix: omit webapp path

* fix: trigger lint

* fix: continue  on linting errors

* feat: add publishing container to github docker registry

* feat: add lint status

* chore: re-trigger-lint

* feat: add java checkstyle

* fix: java linting

* fix: github token

* fix: update jave checkstyle action

* chore: simplify frontend lint action

* chore: remove changed java files

* feat: revert lint trigger frontend

* feat: add docker credentials helper

* fix: remove credentials warning

* fix: tests and clean command

* CB-5228 feat: run frontend tests for every build

* fix: clean tasks

* feat: update cli tools
  • Loading branch information
Wroud authored May 31, 2024
1 parent 6077a52 commit 8eaabce
Show file tree
Hide file tree
Showing 124 changed files with 1,039 additions and 918 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/backend-build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
name: Backend Build

on:
# push:
# branches:
# - devel
# pull_request:
# branches:
# - devel
# paths-ignore:
# - "webapp/**"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand All @@ -18,6 +9,7 @@ on:

jobs:
build-backend:
name: Backend
runs-on: ubuntu-latest

steps:
Expand All @@ -30,7 +22,7 @@ jobs:
distribution: "temurin"
java-version: "17"
cache: maven

- uses: stCarolas/setup-maven@v5
with:
maven-version: 3.9.0
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/backend-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Backend Lint

on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Allows you to reuse workflows by referencing their YAML files
workflow_call:
inputs:
skip_cache:
required: false
type: string

jobs:
lint:
name: Backend
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Checkout checkstyle config repository
uses: actions/checkout@v4
with:
repository: dbeaver/dbeaver
path: dbeaver-config

- name: Copy checkstyle config
run: cp dbeaver-config/dbeaver-checkstyle-config.xml ./dbeaver-checkstyle-config.xml

- name: Remove checkstyle config directory
run: rm -rf dbeaver-config

- uses: dbelyaev/action-checkstyle@master
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
filter_mode: diff_context
checkstyle_config: ./dbeaver-checkstyle-config.xml
fail_on_error: true
57 changes: 57 additions & 0 deletions .github/workflows/common-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Cleanup checks

on:
pull_request:
types: [closed]

jobs:
delete-caches:
runs-on: ubuntu-latest
steps:
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

# delete-docker-image:
# name: Delete Docker Image
# if: github.event.pull_request.merged == true
# runs-on: ubuntu-latest

# steps:
# - name: Check out the repository
# uses: actions/checkout@v4

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Determine Docker Image Tag
# run: |
# REPO_NAME=$(basename ${{ github.repository }})
# IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/$REPO_NAME
# BRANCH_NAME=${{ github.event.pull_request.head.ref }}
# TAG_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
# echo "image=$IMAGE_NAME:$TAG_NAME" >> $GITHUB_ENV

# - name: Log in to GitHub Container Registry
# run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin

# - name: Delete Docker Image
# run: |
# docker rmi ${{ env.image }}
# echo "Deleted image: ${{ env.image }}"
56 changes: 56 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Check

on:
push:
branches:
- devel
pull_request:
branches:
- devel

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
skip_cache:
description: "Skip cache restoration"
required: false
default: "false"

jobs:
call-backend-build:
name: Build
uses: ./.github/workflows/backend-build.yml

call-frontend-build:
name: Build
uses: ./.github/workflows/frontend-build.yml
with:
skip_cache: ${{ github.event.inputs.skip_cache }}

call-frontend-lint:
name: Lint
needs: call-frontend-build
uses: ./.github/workflows/frontend-lint.yml

call-backend-lint:
name: Lint
uses: ./.github/workflows/backend-lint.yml

# call-frontend-tests:
# name: Frontend Unit Tests
# needs: call-frontend-build
# runs-on: ubuntu-latest
# steps:
# - name: Check if tests passed
# if: ${{ needs.call-frontend-build.outputs.test-status != 'success' }}
# run: |
# echo "Tests failed"
# exit 1
# - name: Continue if tests passed
# if: ${{ needs.call-frontend-build.outputs.test-status == 'success' }}
# run: echo "Tests passed"

# call-docker-build-and-push:
# name: Run
# needs: [call-backend-build, call-frontend-build]
# uses: ./.github/workflows/docker-build-and-push.yml
80 changes: 59 additions & 21 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
name: Build and Push Docker Image

on:
# push:
# branches:
# - devel
# pull_request:
# branches:
# - devel

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
call-backend-build:
uses: ./.github/workflows/backend-build.yml

call-frontend-build:
uses: ./.github/workflows/frontend-build.yml
# Allows you to reuse workflows by referencing their YAML files
workflow_call:

jobs:
build-and-push-docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [call-backend-build, call-frontend-build]

steps:
- name: Checkout repository
Expand All @@ -42,14 +32,62 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Run custom Docker build script
working-directory: ./deploy
run: ./make-docker-container.sh
shell: bash
run: |
chmod +x make-docker-container.sh
./make-docker-container.sh
working-directory: ./deploy/docker

- name: Tag Docker Image
run: |
IMAGE_NAME=dbeaver/cloudbeaver
TAG_NAME=${{ github.head_ref || github.ref_name }}
docker tag $IMAGE_NAME:dev $IMAGE_NAME:$TAG_NAME
REPO_NAME=$(basename ${{ github.repository }})
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/$REPO_NAME
BRANCH_NAME=${{ github.head_ref || github.ref_name }}
TAG_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
docker tag dbeaver/cloudbeaver:dev $IMAGE_NAME:$TAG_NAME
echo "image=$IMAGE_NAME:$TAG_NAME" >> $GITHUB_ENV
# - name: Install Docker Credential Helper
# run: |
# sudo apt-get update
# sudo apt-get install -y gnupg2 pass
# curl -fsSL https://github.com/docker/docker-credential-helpers/releases/download/v0.6.4/docker-credential-pass-v0.6.4-amd64.tar.gz -o docker-credential-pass.tar.gz
# tar xzvf docker-credential-pass.tar.gz
# sudo mv docker-credential-pass /usr/local/bin/docker-credential-pass
# sudo chmod +x /usr/local/bin/docker-credential-pass

# - name: Configure Docker to use Credential Helper
# run: |
# mkdir -p ~/.docker
# echo '{"credsStore":"pass"}' > ~/.docker/config.json

# - name: Initialize Password Store
# run: |
# gpg --batch --gen-key <<EOF
# %no-protection
# Key-Type: default
# Subkey-Type: default
# Name-Real: Docker Credential Helper
# Expire-Date: 0
# %commit
# EOF
# pass init "$(gpg --list-keys --with-colons | grep '^pub' | cut -d: -f5)"

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin

- name: Push Docker Image
run: docker push ${{ env.image }}

# - name: Comment on Pull Request
# if: github.event_name == 'pull_request'
# uses: actions/github-script@v6
# with:
# github-token: ${{ secrets.PAT }}
# script: |
# const tag = process.env.TAG_NAME;
# const commentBody = `The Docker image has been built and pushed to Docker Hub.\n\nYou can pull the image using the following command:\n\`\`\`\ndocker pull dbeaver/cloudbeaver:${tag}\n\`\`\``;
# github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: context.issue.number,
# body: commentBody
# });
42 changes: 32 additions & 10 deletions .github/workflows/frontend-build.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
name: Frontend Build

on:
# push:
# branches:
# - devel
# pull_request:
# branches:
# - devel
# paths:
# - "webapp/**"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Allows you to reuse workflows by referencing their YAML files
workflow_call:
outputs:
build-status:
description: "Build status"
value: ${{ jobs.frontend-build.outputs.build-status }}
test-status:
description: "Test status"
value: ${{ jobs.frontend-build.outputs.test-status }}
inputs:
skip_cache:
required: false
type: string

jobs:
frontend-build:
name: Frontend
runs-on: ubuntu-latest

outputs:
build-status: ${{ steps.build.outcome }}
test-status: ${{ steps.test.outcome }}

defaults:
run:
working-directory: ./webapp
Expand Down Expand Up @@ -49,18 +56,33 @@ jobs:
restore-keys: |
${{ runner.os }}-dist-
- name: yarn install
- name: yarn clean
if: env.skip_cache == 'true'
uses: borales/actions-yarn@v5
with:
dir: webapp
cmd: clean

- name: yarn install --frozen-lockfile
uses: borales/actions-yarn@v5
with:
dir: webapp
cmd: install

- name: build
id: build
uses: borales/actions-yarn@v5
with:
dir: webapp/packages/product-default
cmd: bundle

- name: test
id: test
uses: borales/actions-yarn@v5
with:
dir: webapp
cmd: test

- name: Archive build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
Loading

0 comments on commit 8eaabce

Please sign in to comment.