From 7e69acbd2107793873987dbd6205ddded0581537 Mon Sep 17 00:00:00 2001 From: Andy Yen <38731840+onlyjackfrost@users.noreply.github.com> Date: Tue, 9 Apr 2024 20:49:09 +0800 Subject: [PATCH] [DRAFT] Chore(Wren-ui): add github action script for CI (#72) GitHub action to release image --- .github/workflows/ui-lint.yaml | 55 +++++++++++++++++++ .../workflows/ui-release-image-stable.yaml | 37 +++++++++++++ .github/workflows/ui-release-image.yaml | 47 ++++++++++++++++ .github/workflows/ui-test.yaml | 53 ++++++++++++++++++ wren-ui/Dockerfile | 3 +- .../apollo/server/mdl/test/mdlBuilder.test.ts | 2 + 6 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ui-lint.yaml create mode 100644 .github/workflows/ui-release-image-stable.yaml create mode 100644 .github/workflows/ui-release-image.yaml create mode 100644 .github/workflows/ui-test.yaml diff --git a/.github/workflows/ui-lint.yaml b/.github/workflows/ui-lint.yaml new file mode 100644 index 000000000..030ad8319 --- /dev/null +++ b/.github/workflows/ui-lint.yaml @@ -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 + \ No newline at end of file diff --git a/.github/workflows/ui-release-image-stable.yaml b/.github/workflows/ui-release-image-stable.yaml new file mode 100644 index 000000000..1ca1914af --- /dev/null +++ b/.github/workflows/ui-release-image-stable.yaml @@ -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 . diff --git a/.github/workflows/ui-release-image.yaml b/.github/workflows/ui-release-image.yaml new file mode 100644 index 000000000..6ffea5169 --- /dev/null +++ b/.github/workflows/ui-release-image.yaml @@ -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 . \ No newline at end of file diff --git a/.github/workflows/ui-test.yaml b/.github/workflows/ui-test.yaml new file mode 100644 index 000000000..760a344f2 --- /dev/null +++ b/.github/workflows/ui-test.yaml @@ -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 \ No newline at end of file diff --git a/wren-ui/Dockerfile b/wren-ui/Dockerfile index 6aa9e0ce0..bf3ac5c96 100644 --- a/wren-ui/Dockerfile +++ b/wren-ui/Dockerfile @@ -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 @@ -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 ./ diff --git a/wren-ui/src/apollo/server/mdl/test/mdlBuilder.test.ts b/wren-ui/src/apollo/server/mdl/test/mdlBuilder.test.ts index d6afccfa3..28a1f7e4b 100644 --- a/wren-ui/src/apollo/server/mdl/test/mdlBuilder.test.ts +++ b/wren-ui/src/apollo/server/mdl/test/mdlBuilder.test.ts @@ -142,6 +142,7 @@ describe('MDLBuilder', () => { type: 'customer', isCalculated: false, relationship: 'OrderCustomer', + properties: null, notNull: false, }, ], @@ -168,6 +169,7 @@ describe('MDLBuilder', () => { isCalculated: false, relationship: 'OrderCustomer', notNull: false, + properties: null, }, ], primaryKey: '',