Skip to content

Commit

Permalink
Merge remote-tracking branch 'cloudforet-io/master' into refactor/ser…
Browse files Browse the repository at this point in the history
…vice-account-create

Signed-off-by: daeyeon ko <[email protected]>
  • Loading branch information
kkdy21 committed Dec 27, 2024
2 parents 5ea9da3 + b83402e commit 8bfa05d
Show file tree
Hide file tree
Showing 63 changed files with 1,019 additions and 510 deletions.
85 changes: 76 additions & 9 deletions .github/workflows/pull_request_code_warning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "[PR] Code Warning"
on:
pull_request:
types: [opened, synchronize, reopened]
path-ignores:
paths-ignore:
- '.github/**'
- '**/deploy/**'
- '**/Dockerfile'
Expand All @@ -19,7 +19,7 @@ on:
branches:
- master
- feature-*
workflow_dispatch:
workflow_dispatch:


jobs:
Expand All @@ -30,46 +30,113 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# checkout only the files we need
sparse-checkout: |
apps
packages
# fetch all history so we can check diff between PR and base branch
fetch-depth: 0

- name: Copy changed files to specific directory
run: |
mkdir -p changed_files
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }} | while read file; do
if [ -f "$file" ]; then
rsync -R "$file" changed_files/
else
echo "Skipping missing file: $file"
fi
done
- name: Display changed files
run: |
echo "Changed files copied to 'changed_files' directory:"
find changed_files -type f
- name: Check for TODOs
id: check_todo
working-directory: changed_files
run: |
echo "Checking for TODOs..."
TODO_FILES=$(grep -rl "TODO" apps/web/src --exclude-dir={node_modules,.github} || true)
TODO_FILES=$(grep -rl "// TODO" . --exclude-dir=.git --exclude=apps/web/public/lottie.js || true)
TODO_COUNT=0
if [ -n "$TODO_FILES" ]; then
echo "The following files contain TODO:"
echo "$TODO_FILES"
TODO_COUNT=$(echo "$TODO_FILES" | wc -l)
echo "::warning:: Found $TODO_COUNT file(s) with TODO."
else
echo "No TODOs found."
fi
echo "::warning:: Found $TODO_COUNT file(s) with TODO."
echo "todo_count=$TODO_COUNT" >> $GITHUB_ENV
- name: Check for console.log
id: check_console_log
working-directory: changed_files
run: |
echo "Checking for console.log..."
LOG_FILES=$(grep -rl "console.log" . --exclude-dir={node_modules,.git} || true)
LOG_FILES=$(find . -type f \
! -path "./.git/*" \
! -path "./**/tests/**/*.spec.ts" \
! -path "./**/__tests__/**/*.test.ts" \
! -path "./apps/web/build/*" \
! -path "./apps/web/public/*" \
! -path "./apps/web/vite.config.js" \
! -path "./apps/web/src/lib/site-analytics/*" \
! -path "./packages/mirinae/scripts/*" \
! -path "./packages/mirinae/cli/*" \
! -path "./**/*.stories.ts" \
-exec grep -l "console\.log" {} + || true)
LOG_COUNT=0
if [ -n "$LOG_FILES" ]; then
echo "The following files contain console.log:"
echo "$LOG_FILES"
LOG_COUNT=$(echo "$LOG_FILES" | wc -l)
echo "::warning:: Found $LOG_COUNT file(s) with console.log."
else
echo "No console.log found."
fi
echo "::warning:: Found $LOG_COUNT file(s) with console.log."
echo "console_log_count=$LOG_COUNT" >> $GITHUB_ENV
- name: Check for console.debug
id: check_console_debug
working-directory: changed_files
run: |
echo "Checking for console.debug..."
DEBUG_FILES=$(find . -type f \
! -path "./.git/*" \
! -path "./**/tests/**/*.spec.ts" \
! -path "./**/__tests__/**/*.test.ts" \
! -path "./apps/web/build/*" \
! -path "./apps/web/public/*" \
! -path "./apps/web/src/store/display/display-store.ts" \
! -path "./apps/web/src/lib/config/index.ts" \
! -path "./packages/mirinae/scripts/*" \
! -path "./packages/mirinae/cli/*" \
! -path "./packages/core-lib/src/space-connector/token-api.ts" \
! -path "./**/*.stories.ts" \
-exec grep -l "console\.debug" {} + || true)
DEBUG_COUNT=0
if [ -n "$DEBUG_FILES" ]; then
echo "The following files contain console.debug:"
echo "$DEBUG_FILES"
DEBUG_COUNT=$(echo "$DEBUG_FILES" | wc -l)
echo "::warning:: Found $DEBUG_COUNT file(s) with console.debug."
else
echo "No console.debug found."
fi
echo "console_debug_count=$DEBUG_COUNT" >> $GITHUB_ENV
- name: Fail if issues found
run: |
echo "TODO Count: $todo_count"
echo "console.log Count: $console_log_count"
if [ "$todo_count" -gt 0 ]; then
echo "::warning:: Workflow failed. TODO count: $todo_count, console.log count: $console_log_count"
echo "console.debug Count: $console_debug_count"
if [ "$todo_count" -gt 0 ] || [ "$console_log_count" -gt 0 ] || [ "$console_debug_count" -gt 0 ]; then
echo "::error:: Workflow failed. TODO count: $todo_count, console.log count: $console_log_count, console.debug count: $console_debug_count"
exit 1
else
echo "No issues found. Workflow passed."
Expand Down
134 changes: 134 additions & 0 deletions .github/workflows/pull_request_deploy_preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Deploy Vercel Preview on Comment

on:
issue_comment:
types: [created]

env:
VERCEL_TEAM_NAME: "cloudforet"
PROJECT_NAME: console
VERCEL_TOKEN: ${{ secrets.VERCEL_CLOUDFORET_TOKEN }}

jobs:
deploy-preview:
if: startsWith(github.event.comment.body, '/preview')
runs-on: ubuntu-latest

steps:
- name: Verify context
id: verify
run: |
if [[ "${{ github.event.issue.pull_request.url }}" == "" ]]; then
echo "🚫 This action only supports comments on PRs."
exit 1
fi
COMMENTER=${{ github.event.comment.user.login }}
echo "Commenter: $COMMENTER"
- name: Check organization membership
id: check_membership
uses: actions/github-script@v6
with:
script: |
const commenter = context.payload.comment.user.login;
try {
const { status } = await github.rest.orgs.checkMembershipForUser({
org: 'cloudforet-io',
username: commenter
});
if (status !== 204) {
throw new Error("User is not a member of the organization");
}
core.setOutput('is_member', true);
} catch (error) {
console.log(error.message);
core.setOutput('is_member', false);
core.setOutput('error_message', error.message);
}
result-encoding: string

- name: Comment and stop if not a member
if: steps.check_membership.outputs.is_member == 'false'
uses: actions/github-script@v6
with:
script: |
const errorMessage = `🚫 Commenter \`${context.payload.comment.user.login}\` is not a member of the organization and cannot trigger a preview deployment.`;
console.error(errorMessage);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: errorMessage
});
throw new Error(errorMessage);
- name: Get PR information
id: pr_info
uses: actions/github-script@v6
with:
script: |
const prNumber = context.issue.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
core.setOutput('reponame', pullRequest.head.repo.full_name);
core.setOutput('branch', pullRequest.head.ref);
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
repository: ${{ steps.pr_info.outputs.reponame }}
ref: ${{ steps.pr_info.outputs.branch }}

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Vercel CLI
run: npm install -g vercel

- name: Set up environment
run: sudo apt-get install jq

- name: Deploy to Vercel
id: deploy
run: |
BRANCH_NAME=${{ steps.pr_info.outputs.branch }}
echo "Deploying preview for branch $BRANCH_NAME"
echo "DEPLOY_URL=$DEPLOY_URL" >> $GITHUB_ENV
- name: Checkout Vercel Target Project
run: vercel link --yes --scope=${{ env.VERCEL_TEAM_NAME }} --project=${{ env.PROJECT_NAME }} --token=${{ env.VERCEL_TOKEN }}

- name: Pull Vercel Environment Information
run: vercel pull --yes --token=${{ env.VERCEL_TOKEN }}

- name: Pull Vercel Edge Config
run: vercel env pull ./apps/web/.env --yes --token=${{ env.VERCEL_TOKEN }}

- name: Build Project Artifacts
run: vercel build --yes --token=${{ env.VERCEL_TOKEN }}

- name: Deploy Project Artifacts to Vercel
run: |
DEPLOY_URL=$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }})
echo "DEPLOY_URL=$DEPLOY_URL" >> $GITHUB_ENV
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
const url = process.env.DEPLOY_URL;
const commentBody = `🚀 Preview deployed for branch \`${{ steps.pr_info.outputs.reponame }}:${{ steps.pr_info.outputs.branch }}\`: [View Preview](${url})`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ The final configuration file will be generated by merging the default configurat

| Name | Description | Required |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| CONSOLE_API | The endpoint of the Console API | O |
| CONSOLE_API_V2 | The endpoint of the Console API V2 | O |
| CONSOLE_API | The configuration for Console API, including the ENDPOINT (API URL) and TIMEOUT (request timeout in milliseconds). | O |
| CONSOLE_API_V2 | The configuration for Console API V2, including the ENDPOINT (API URL) and TIMEOUT (request timeout in milliseconds). | O |
| GTAG_ID | Google analytics Id | X |
| GTM_ID | Google tag manager Id | X |
| DOMAIN_NAME | Tenancy name | X |
Expand Down
3 changes: 2 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "2.0.0-dev248",
"version": "2.0.0-dev257",
"private": true,
"description": "Cloudforet Console Web Application",
"author": "Cloudforet",
Expand Down Expand Up @@ -52,6 +52,7 @@
"currency.js": "^2.0.4",
"dayjs": "^1.11.7",
"diff-match-patch": "^1.0.5",
"dompurify": "^3.2.3",
"echarts": "^5.5.0",
"ejs": "^3.1.10",
"hangul-js": "^0.2.6",
Expand Down
6 changes: 4 additions & 2 deletions apps/web/public/config/development.json.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"CONSOLE_API": {
"ENDPOINT": "http://127.0.0.1:8081"
"ENDPOINT": "http://127.0.0.1:8081",
"TIMEOUT": 3000
},
"CONSOLE_API_V2": {
"ENDPOINT": "http://127.0.0.1:8082"
"ENDPOINT": "http://127.0.0.1:8082",
"TIMEOUT": 3000
},
"GTAG_ID": "DISABLED",
"DOMAIN_NAME": "spaceone",
Expand Down
Loading

0 comments on commit 8bfa05d

Please sign in to comment.