Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Migrate the CI/CD pipeline from CircleCI to GitHub Actions #920

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

cheton
Copy link
Member

@cheton cheton commented Sep 8, 2024

PR Type

enhancement, configuration changes


Description

  • Migrated CI/CD pipeline from CircleCI to GitHub Actions with new workflows for branches, pull requests, tags, and publishing.
  • Enhanced the GitHub issue comment CLI by adding options for a GitHub token and a search pattern, and updated the comment search logic.
  • Removed the BASE_PATH variable from environment configuration files.
  • Updated package dependencies by removing lodash.find.

Changes walkthrough 📝

Relevant files
Enhancement
cli.js
Enhance CLI with token and pattern options                             

scripts/github-issue-comment-cli/bin/cli.js

  • Added options for GitHub token and pattern.
  • Updated comment search logic.
  • Removed lodash.find dependency.
  • +14/-6   
    Configuration changes
    ci-branch.yml
    Add branch CI workflow using GitHub Actions                           

    .github/workflows/ci-branch.yml

  • Added GitHub Actions workflow for branch CI.
  • Configured environment variables and build steps.
  • Included artifact upload and deployment steps.
  • +129/-0 
    ci-pr.yml
    Add pull request CI workflow using GitHub Actions               

    .github/workflows/ci-pr.yml

  • Added GitHub Actions workflow for pull request CI.
  • Configured environment variables and build steps.
  • Included artifact upload and deployment steps.
  • +150/-0 
    ci-publish.yml
    Add publish workflow using GitHub Actions                               

    .github/workflows/ci-publish.yml

  • Added GitHub Actions workflow for publishing.
  • Configured Node.js setup and package installation.
  • +34/-0   
    ci-tag.yml
    Add tag-based CI workflow using GitHub Actions                     

    .github/workflows/ci-tag.yml

  • Added GitHub Actions workflow for tag-based CI.
  • Configured environment variables and build steps.
  • Included artifact upload and deployment steps.
  • +131/-0 
    .env
    Remove BASE_PATH from environment configuration                   

    packages/react-docs/.env

    • Removed BASE_PATH variable.
    +0/-1     
    .env.production
    Remove BASE_PATH from production environment configuration

    packages/react-docs/.env.production

    • Removed BASE_PATH variable.
    +0/-1     
    Dependencies
    package.json
    Update package dependencies                                                           

    scripts/github-issue-comment-cli/package.json

    • Removed lodash.find dependency.
    +0/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    codesandbox bot commented Sep 8, 2024

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders

    Open Preview

    Copy link

    changeset-bot bot commented Sep 8, 2024

    ⚠️ No Changeset found

    Latest commit: 02b969c

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    @cheton cheton added the 🏗️ work in progress Work in progress label Sep 8, 2024
    Copy link

    codesandbox-ci bot commented Sep 8, 2024

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Sep 9, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit 02b969c)

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive information exposure:
    In the file '.github/workflows/ci-pr.yml', the GitHub token is being used directly in a command line argument (line 150). This could potentially expose the token if the logs are accessible. It's recommended to use GitHub's built-in secrets handling mechanism instead.

    ⚡ Key issues to review

    Security Concern
    The workflow is using a secret (TONIC_UI_PR_ACCESS_TOKEN) directly in a command, which could potentially expose sensitive information.

    Possible Bug
    The BASE_PATH variable has been replaced with TONIC_UI_REACT_DOCS_BASE_PATH, which might cause issues if not properly updated throughout the codebase.

    Configuration Change
    The basePath and distDir configurations have been modified, which could affect the build and deployment process.

    @cheton cheton force-pushed the tonic-ui-917 branch 3 times, most recently from 30b6dbf to 1b55cd2 Compare September 9, 2024 07:19
    @trendmicro-frontend-bot
    Copy link
    Contributor

    trendmicro-frontend-bot commented Sep 9, 2024

    Tonic UI Demo

    On 2024-09-10 09:49:21 +0000, PR #920 (02b969c) was successfully deployed. You can view it at the following link:
    https://trendmicro-frontend.github.io/tonic-ui-demo/react-docs/pr-920/

    @cheton cheton force-pushed the tonic-ui-917 branch 2 times, most recently from d89b3d0 to 58193f6 Compare September 9, 2024 07:40
    Copy link

    codecov bot commented Sep 9, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 77.21%. Comparing base (65f8570) to head (02b969c).
    Report is 1 commits behind head on v2.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##               v2     #920      +/-   ##
    ==========================================
    + Coverage   77.20%   77.21%   +0.01%     
    ==========================================
      Files         396      396              
      Lines        6409     6409              
    ==========================================
    + Hits         4948     4949       +1     
    + Misses       1461     1460       -1     
    Flag Coverage Δ
    -base ?
    -github ?
    -hooks ?
    -icons ?
    -system ?
    codemod ?
    react ?
    theme ?
    utils ?

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @cheton
    Copy link
    Member Author

    cheton commented Sep 10, 2024

    /improve

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Sep 10, 2024

    PR Code Suggestions ✨

    Latest suggestions up to 02b969c

    CategorySuggestion                                                                                                                                    Score
    Performance
    Add caching for dependencies to improve workflow execution time

    Consider adding a step to cache dependencies to speed up the workflow execution time
    in subsequent runs.

    .github/workflows/ci-branch.yml [53-56]

    +- name: Cache dependencies
    +  uses: actions/cache@v3
    +  with:
    +    path: ~/.yarn
    +    key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
    +    restore-keys: |
    +      ${{ runner.os }}-yarn-
     - name: Install packages
       run: |
         yarn up
         yarn install
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding caching for dependencies can significantly reduce workflow execution time, which is a valuable performance improvement for CI processes.

    9
    Enhancement
    Simplify the comment finding logic using Array.find() method

    Instead of using a find function with a side effect (modifying a variable outside
    its scope), consider using Array.find() method for better readability and
    maintainability.

    scripts/github-issue-comment-cli/bin/cli.js [50-54]

    -const comment = comments.find(comment => {
    -  if (comment.body.includes(argv.pattern)) {
    -    return true;
    -  }
    -});
    +const comment = comments.find(comment => comment.body.includes(argv.pattern));
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion simplifies the code by using the Array.find() method, improving readability and maintainability without changing the logic.

    8
    Best practice
    Add YAML validation step to catch potential workflow syntax errors early

    Consider adding a step to validate the YAML syntax of the workflow file itself to
    catch potential errors early in the CI process.

    .github/workflows/ci-pr.yml [1-11]

     name: ci-pr
     
     on:
       pull_request:
         types:
           - opened
           - reopened
           - synchronize
         branches:
           - v2
     
    +jobs:
    +  validate-yaml:
    +    runs-on: ubuntu-latest
    +    steps:
    +      - uses: actions/checkout@v4
    +      - name: YAML Lint
    +        uses: ibiqlik/action-yamllint@v3
    +        with:
    +          file_or_dir: .github/workflows/*.yml
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a YAML validation step is a good practice that helps catch syntax errors early in the CI process, improving reliability and maintainability of the workflow files.

    8
    Error handling
    Improve error handling with more specific error messages

    Consider using a more specific error handling mechanism instead of a generic if
    (err) check. This could involve using try-catch blocks or handling specific error
    types.

    scripts/github-issue-comment-cli/bin/cli.js [43-47]

     ghissue.comments((err, result) => {
       if (err) {
    -    console.error(err);
    +    console.error('Failed to fetch comments:', err.message);
         process.exit(1);
       }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves error handling by providing a more specific error message, which enhances debugging and readability. However, it does not introduce a more specific error handling mechanism as suggested.

    7

    Previous suggestions

    Suggestions up to commit e7d0064
    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Simplify the comment search logic and add null checks using optional chaining

    Consider using optional chaining (?.) when accessing nested properties of the
    comment object to prevent potential errors if the property is undefined.

    scripts/github-issue-comment-cli/bin/cli.js [50-54]

    -const comment = comments.find(comment => {
    -  if (comment.body.includes(argv.pattern)) {
    -    return true;
    -  }
    -});
    +const comment = comments.find(comment => comment?.body?.includes(argv.pattern));
     
    Suggestion importance[1-10]: 8

    Why: The suggestion improves code robustness by preventing potential runtime errors when accessing nested properties that might be undefined, which is a significant enhancement.

    8
    Simplify the version extraction process from package.json using Node.js

    Consider using a more efficient method to extract the version from package.json,
    such as using jq or node -p, instead of the current grep and awk approach.

    .github/workflows/ci-tag.yml [36-41]

    -TONIC_UI_REACT_VERSION=$(cat packages/react/package.json \
    -  | grep version \
    -  | head -1 \
    -  | awk -F: '{ print $2 }' \
    -  | sed 's/[",]//g' \
    -  | tr -d '[[:space:]]')
    +TONIC_UI_REACT_VERSION=$(node -p "require('./packages/react/package.json').version")
     
    Suggestion importance[1-10]: 6

    Why: The suggestion provides a more efficient and cleaner method to extract the version, improving maintainability and readability, though it is not critical.

    6
    Performance
    Add caching for yarn dependencies to improve workflow performance

    Consider adding a step to cache the yarn dependencies to speed up the workflow
    execution time in subsequent runs.

    .github/workflows/ci-pr.yml [53-55]

    +- name: Get yarn cache directory path
    +  id: yarn-cache-dir-path
    +  run: echo "::set-output name=dir::$(yarn cache dir)"
    +
    +- uses: actions/cache@v3
    +  id: yarn-cache
    +  with:
    +    path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
    +    key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
    +    restore-keys: |
    +      ${{ runner.os }}-yarn-
    +
     - name: Install packages
       run: |
         yarn up
         yarn install
     
    Suggestion importance[1-10]: 7

    Why: Caching yarn dependencies can significantly reduce workflow execution time, which is beneficial for performance, especially in CI/CD environments.

    7
    Best practice
    Specify a more precise Node.js version in the workflow configuration

    Consider using a more specific Node.js version (e.g., '18.x') instead of just '18'
    to ensure consistency across different environments and potential future updates.

    .github/workflows/ci-branch.yml [25-27]

     - name: Setup Node.js
       uses: actions/setup-node@v3
       with:
    -    node-version: 18
    +    node-version: '18.x'
     
    Suggestion importance[1-10]: 5

    Why: While specifying a more precise Node.js version can help ensure consistency, it is a minor improvement and not crucial for the functionality of the workflow.

    5

    @cheton
    Copy link
    Member Author

    cheton commented Sep 10, 2024

    /review

    Copy link
    Contributor

    Persistent review updated to latest commit 02b969c

    @cheton cheton merged commit e8f66c2 into v2 Sep 10, 2024
    7 checks passed
    @cheton cheton deleted the tonic-ui-917 branch September 10, 2024 13:07
    cheton added a commit that referenced this pull request Sep 18, 2024
    * ci: Migrate the CI/CD pipeline from CircleCI to GitHub Actions
    
    * ci: fetch the entire Git history to access the latest tag release
    cheton added a commit that referenced this pull request Sep 18, 2024
    * ci: Migrate the CI/CD pipeline from CircleCI to GitHub Actions
    
    * ci: fetch the entire Git history to access the latest tag release
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants