From 8ece70be0b758a4474e149fb1a78b8f9db544d67 Mon Sep 17 00:00:00 2001 From: Hien To Date: Thu, 19 Oct 2023 15:09:23 +0700 Subject: [PATCH] Refactor cicd --- .github/workflows/jan-docs-test.yml | 29 -------------- .../{deploy-jan-docs.yml => jan-docs.yml} | 12 +++++- .../{build-app.yml => jan-electron-build.yml} | 2 +- ...t.yml => jan-electron-linter-and-test.yml} | 4 +- ...sh-plugin-core.yml => jan-plugin-core.yml} | 13 ++++++- .../{publish-plugins.yml => jan-plugins.yml} | 16 ++++++-- .github/workflows/quality-gate.yml | 39 ------------------- 7 files changed, 37 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/jan-docs-test.yml rename .github/workflows/{deploy-jan-docs.yml => jan-docs.yml} (82%) rename .github/workflows/{build-app.yml => jan-electron-build.yml} (99%) rename .github/workflows/{linter-and-test.yml => jan-electron-linter-and-test.yml} (96%) rename .github/workflows/{publish-plugin-core.yml => jan-plugin-core.yml} (84%) rename .github/workflows/{publish-plugins.yml => jan-plugins.yml} (86%) delete mode 100644 .github/workflows/quality-gate.yml diff --git a/.github/workflows/jan-docs-test.yml b/.github/workflows/jan-docs-test.yml deleted file mode 100644 index 941111b9fe..0000000000 --- a/.github/workflows/jan-docs-test.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Jan Docs Test Build - -on: - pull_request: - branches: - - main - paths: - - 'docs/**' - - '.github/workflows/deploy-jan-docs.yml' - - '.github/workflows/jan-docs-test.yml' - -jobs: - deploy: - name: Test Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: 'yarn' - cache-dependency-path: './docs/yarn.lock' - - - name: Install dependencies - run: yarn install - working-directory: docs - - name: Test Build Command - run: sed -i '/process.env.DEBUG = namespaces;/c\// process.env.DEBUG = namespaces;' ./node_modules/debug/src/node.js && yarn build - working-directory: docs \ No newline at end of file diff --git a/.github/workflows/deploy-jan-docs.yml b/.github/workflows/jan-docs.yml similarity index 82% rename from .github/workflows/deploy-jan-docs.yml rename to .github/workflows/jan-docs.yml index c0dd9656a4..4aeb89df23 100644 --- a/.github/workflows/deploy-jan-docs.yml +++ b/.github/workflows/jan-docs.yml @@ -1,4 +1,4 @@ -name: Deploy to GitHub Pages +name: Jan Docs on: push: @@ -6,7 +6,13 @@ on: - main paths: - 'docs/**' - - '.github/workflows/deploy-jan-docs.yml' + - '.github/workflows/jan-docs.yml' + pull_request: + branches: + - main + paths: + - 'docs/**' + - '.github/workflows/jan-docs.yml' # Review gh actions docs if you want to further define triggers, paths, etc # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on @@ -30,11 +36,13 @@ jobs: working-directory: docs - name: Add Custome Domain file + if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository run: echo "${{ vars.DOCUSAURUS_DOMAIN }}" > ./docs/build/CNAME # Popular action to deploy to GitHub Pages: # Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus - name: Deploy to GitHub Pages + if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build-app.yml b/.github/workflows/jan-electron-build.yml similarity index 99% rename from .github/workflows/build-app.yml rename to .github/workflows/jan-electron-build.yml index 38093eba8d..8483df303d 100644 --- a/.github/workflows/build-app.yml +++ b/.github/workflows/jan-electron-build.yml @@ -1,4 +1,4 @@ -name: Jan Build MacOS App +name: Jan Build Electron App on: push: diff --git a/.github/workflows/linter-and-test.yml b/.github/workflows/jan-electron-linter-and-test.yml similarity index 96% rename from .github/workflows/linter-and-test.yml rename to .github/workflows/jan-electron-linter-and-test.yml index c8c214faa0..e9e3f091a0 100644 --- a/.github/workflows/linter-and-test.yml +++ b/.github/workflows/jan-electron-linter-and-test.yml @@ -1,11 +1,11 @@ -name: Linter & Test +name: Jan Electron Linter & Test on: push: branches: - main paths: - 'electron/**' - - .github/workflows/linter-and-test.yml + - .github/workflows/jan-electron-linter-and-test.yml - 'web/**' - 'package.json' - 'node_modules/**' diff --git a/.github/workflows/publish-plugin-core.yml b/.github/workflows/jan-plugin-core.yml similarity index 84% rename from .github/workflows/publish-plugin-core.yml rename to .github/workflows/jan-plugin-core.yml index 0ce1f36e1a..6ede3e2d2f 100644 --- a/.github/workflows/publish-plugin-core.yml +++ b/.github/workflows/jan-plugin-core.yml @@ -1,11 +1,18 @@ -name: Publish plugin core Package to npmjs +name: Plugin Core on: push: branches: - main paths: - "core/**" - - ".github/workflows/publish-core.yml" + - ".github/workflows/jan-plugin-core.yml" + - "!core/package.json" + pull_request: + branches: + - main + paths: + - "core/**" + - ".github/workflows/jan-plugin-core.yml" - "!core/package.json" jobs: build-and-publish-plugins: @@ -50,11 +57,13 @@ jobs: - run: npm install && npm run build working-directory: ./core - run: npm publish --access public + if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} working-directory: ./core - name: "Commit new version to main and create tag" + if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository run: | version=$(jq -r '.version' core/package.json) git config --global user.email "service@jan.ai" diff --git a/.github/workflows/publish-plugins.yml b/.github/workflows/jan-plugins.yml similarity index 86% rename from .github/workflows/publish-plugins.yml rename to .github/workflows/jan-plugins.yml index 1c4be6b0e5..e1e303f64e 100644 --- a/.github/workflows/publish-plugins.yml +++ b/.github/workflows/jan-plugins.yml @@ -1,11 +1,18 @@ -name: Publish plugins/$dir Package to npmjs +name: Jan Default Plugins on: push: branches: - main paths: - "plugins/**" - - ".github/workflows/publish-plugins.yml" + - ".github/workflows/jan-plugins.yml" + - "!plugins/*/package.json" + pull_request: + branches: + - main + paths: + - "plugins/**" + - ".github/workflows/jan-plugins.yml" - "!plugins/*/package.json" jobs: build: @@ -69,13 +76,16 @@ jobs: echo $dir cd $dir npm install && npm run build - npm publish --access public + if [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME != $GITHUB_REPOSITORY ]]; then + npm publish --access public + fi cd .. done env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: "Commit new version to main and create tag" + if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository run: | for dir in $(cat /tmp/change_dir.txt) do diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml deleted file mode 100644 index f49f19abed..0000000000 --- a/.github/workflows/quality-gate.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Linter & Sonarqube scanner -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - test-lint: - runs-on: ubuntu-latest - steps: - - name: Getting the repo - uses: actions/checkout@v2 - - - name: create sonar properties file - run: | - echo "Branch Name ${GITHUB_REF#refs/heads/}" - echo -e "sonar.sources = ." > sonar-project.properties - echo -e "sonar.projectKey = ${{ secrets.PROJECT_KEY }}" >> sonar-project.properties - if [[ "${{ github.event_name }}" == "push" ]]; then - echo -e "sonar.branch.name = ${GITHUB_REF#refs/heads/}" >> sonar-project.properties - fi - - - name: SonarQube Scan - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - # Check the Quality Gate status. - - name: SonarQube Quality Gate check - id: sonarqube-quality-gate-check - uses: sonarsource/sonarqube-quality-gate-action@master - # Force to fail step after specific time. - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} #OPTIONAL