Skip to content

Commit

Permalink
[DRAFT] Chore(Wren-ui): add github action script for CI (#72)
Browse files Browse the repository at this point in the history
GitHub action to release image
  • Loading branch information
onlyjackfrost authored Apr 9, 2024
1 parent 70c8141 commit 7e69acb
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ui-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# create the github action to run the yarn lint when PR created or pushed to main branch
#

name: Wren-UI Lint

on:
push:
paths:
- 'wren-ui/**'
pull_request:
types: [ labeled ]

permissions:
contents: read

concurrency:
# avoid mis-canceling the ci runs while other labels are added to the PR, so we add the label name as the condition
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.label.name == 'ci/ui' && github.event.number || github.sha }}
cancel-in-progress: true

defaults:
run:
working-directory: wren-ui

jobs:
eslint:
# run this job only if the PR is labeled with "ci/ui"
if: ${{ github.event.label.name == 'ci/ui' || github.event_name == 'push'}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: | # should cache node_modules as well
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: yarn list
- name: Install Node.js dependencies
run: yarn install
- name: Run lint
run: yarn lint

37 changes: 37 additions & 0 deletions .github/workflows/ui-release-image-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Wren-UI Release stable image

on:
workflow_dispatch:
inputs:
version:
description: Give a version for this release
type: string
required: true

defaults:
run:
working-directory: wren-ui

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ui:${{ github.event.inputs.version }} \
--tag ghcr.io/canner/wren-ui:latest \
--file ./Dockerfile \
--push .
47 changes: 47 additions & 0 deletions .github/workflows/ui-release-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Wren-UI Release image

on:
workflow_dispatch:
inputs:
docker_image_tag_name:
description: Docker image tag name (optional, default branch name/tag name replaced with hyphens)
type: string

defaults:
run:
working-directory: wren-ui

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare tag name
id: tag-preparation
run: |
if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then
tag_name=${{ github.event.inputs.docker_image_tag_name }}
else
tag_name=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')-$(git log -1 --pretty=%h)
fi
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image
env:
TAG_NAME: ${{ steps.tag-preparation.outputs.TAG_NAME }}
run: |
echo "Building image with tag:$TAG_NAME"
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ui:$TAG_NAME \
--file ./Dockerfile \
--push .
53 changes: 53 additions & 0 deletions .github/workflows/ui-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# create the github action to run the UI tests when PR created

name: Wren-UI Test

on:
push:
paths:
- 'wren-ui/**'
pull_request:
types: [ labeled ]

permissions:
contents: read

concurrency:
# avoid mis-canceling the ci runs while other labels are added to the PR, so we add the label name as the condition
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.label.name == 'ci/ui' && github.event.number || github.sha }}
cancel-in-progress: true

defaults:
run:
working-directory: wren-ui

jobs:
unit-test:
# run this job only if the PR is labeled with "ci/ui"
if: ${{ github.event.label.name == 'ci/ui' || github.event_name == 'push'}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: | # should cache node_modules as well
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- if: ${{ steps.yarn-cache.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: yarn list
- name: Install dependencies
run: yarn
- name: Run tests
run: yarn test
3 changes: 1 addition & 2 deletions wren-ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* ./
RUN yarn --frozen-lockfile
RUN yarn install --frozen-lockfile --network-timeout 100000

# Rebuild the source code only when needed
FROM base AS builder
Expand All @@ -19,7 +19,6 @@ COPY src ./src
COPY .eslintrc.json ./
COPY .eslintignore ./
COPY .prettierrc ./
COPY next-env.d.ts ./
COPY next.config.js ./
COPY tsconfig.json ./
COPY yarn.lock ./
Expand Down
2 changes: 2 additions & 0 deletions wren-ui/src/apollo/server/mdl/test/mdlBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe('MDLBuilder', () => {
type: 'customer',
isCalculated: false,
relationship: 'OrderCustomer',
properties: null,
notNull: false,
},
],
Expand All @@ -168,6 +169,7 @@ describe('MDLBuilder', () => {
isCalculated: false,
relationship: 'OrderCustomer',
notNull: false,
properties: null,
},
],
primaryKey: '',
Expand Down

0 comments on commit 7e69acb

Please sign in to comment.