diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 00000000..719f4944 --- /dev/null +++ b/.github/README.md @@ -0,0 +1,209 @@ +# Codelabz CI/CD Workflows + +This `README.md` is designed to provide a comprehensive overview of our CI/CD processes, making it easy for contributors to understand and engage with our workflows. Codelabz leverages a suite of GitHub Actions workflows to automate key aspects of project management, testing, and deployment. Each workflow is explained in detail below, covering its purpose, trigger events, and implementation guidelines. + +## Table of Contents + +- [1. Greetings Workflow](#1-greetings-workflow) +- [2. Close Stale Issues and Pull Requests Workflow](#2-close-stale-issues-and-pull-requests-workflow) +- [3. Issue Labeler Workflow](#3-issue-labeler-workflow) +- [4. Cypress End-to-End Tests Workflow](#4-cypress-end-to-end-tests-workflow) +- [5. Deploy to Firebase Hosting on Merge Workflow](#5-deploy-to-firebase-hosting-on-merge-workflow) +- [6. Deploy to Firebase Hosting on Pull Request Workflow](#6-deploy-to-firebase-hosting-on-pull-request-workflow) +- [7. Pull Request Labeler Workflow](#7-pull-request-labeler-workflow) +- [8. Pull Request Target Workflow](#8-pull-request-target-workflow) +- [Secrets Management](#secrets-management) + - [Environment Variables](#environment-variables) +- [Conclusion](#conclusion) + +--- + +## 1. Greetings Workflow + +**File:** `.github/workflows/greetings.yml` + +This workflow sends a personalized greeting message to users when they open a new issue or pull request. + +**Trigger Events:** + +- `pull_request`: Triggered when a pull request is opened. +- `issues`: Triggered when an issue is opened. + +**Usage:** + +- Welcomes new contributors to the project and encourages participation. +- Enhances the onboarding experience and fosters a positive community environment. + +**Example:** + +```markdown +👋 Hello! Welcome to our project! We're glad you're here. Please provide detailed information about your issue or pull request so we can assist you effectively. Thank you for your contribution! 🚀 +``` + +--- + +## 2. Close Stale Issues and Pull Requests Workflow + +**File:** `.github/workflows/stale.yml` + +This workflow automatically marks issues and pull requests as stale after a period of inactivity and closes them if there is no further activity. + +**Trigger Events:** + +- `schedule`: Runs daily at 6:30 PM UTC (12:00 AM IST). + +**Usage:** + +- Helps maintain the cleanliness of the issue tracker by closing inactive issues and pull requests. +- Sends reminders and notifications to contributors about inactive issues and pull requests. + +--- + +## 3. Issue Labeler Workflow + +**File:** `.github/workflows/label_issues.yml` + +This workflow automatically labels issues based on predefined criteria specified in the `labeler-v1.yml` file. + +**Trigger Events:** + +- `issues`: Triggered when an issue is opened or edited. + +**Usage:** + +- Labels issues based on patterns defined in the `labeler-v1.yml` configuration file. +- Provides consistent labeling for improved project management. + +--- + +## 4. Cypress End-to-End Tests Workflow + +**File:** `.github/workflows/cypress.yml` + +This workflow conducts end-to-end tests using Cypress, ensuring the quality and functionality of the application. + +**Trigger Events:** + +- `pull_request`: Triggered on pull requests to any branch. +- `push`: Triggered on pushes to any branch. + +**Usage:** + +- Executes tests in parallel on multiple containers, enhancing efficiency and saving time. +- Deploys Firebase emulators for testing with environment variables. +- Records test results in Cypress Cloud for analysis. +- Prints Cypress Cloud URL for result visualization. +- Handles failures by uploading artifacts and notifying contributors. + +--- + +## 5. Deploy to Firebase Hosting on Merge Workflow + +**File:** `.github/workflows/firebase-hosting-merge.yml` + +This workflow automatically deploys the application to Firebase Hosting upon merging changes into the master branch. + +**Trigger Events:** + +- `push`: Triggered on pushes to the master branch. + +**Usage:** + +- Checks out the repository and sets up the Node.js environment. +- Creates a `.env` file with secrets required for Firebase authentication. +- Installs dependencies and builds the application. +- Deploys the application to Firebase Hosting using Firebase Hosting Deploy action. + +--- + +## 6. Deploy to Firebase Hosting on Pull Request Workflow + +**File:** `.github/workflows/firebase-hosting-pull-request.yml` + +This workflow deploys a preview of the application to Firebase Hosting for every pull request targeting the master branch. + +**Trigger Events:** + +- `pull_request`: Triggered on pull requests to the master branch. + +**Usage:** + +- Checks out the repository and sets up the Node.js environment. +- Creates a `.env` file with secrets required for Firebase authentication. +- Installs dependencies and builds the application. +- Deploys the application to a preview channel on Firebase Hosting for testing and review purposes. + +--- + +## 7. Pull Request Labeler Workflow + +**File:** `.github/workflows/label-pull-requests.yml` + +This workflow automatically assigns labels to pull requests based on changes made in the pull request files or their originating branches. + +**Trigger Events:** + +- `pull_request_target`: Triggered when a pull request is opened or synchronized, and its base branch is not on the repository. + +**Usage:** + +- Automatically assigns labels to pull requests to categorize them based on the changes made or their nature. +- Enhances organization and consistency in pull request management. + +**Configuration File:** `labeler.yml` + +This file contains the rules used by the Pull Request Labeler Workflow to determine which labels to apply to pull requests based on specific criteria. + +--- + +## 8. Pull Request Target Workflow + +**File:** `.github/workflows/pull-request-target.yml` + +This workflow adds a standardized comment to pull requests to guide contributors through the review process. + +**Trigger Events:** + +- `pull_request_target`: When a pull request is targeted against a branch. + +**Usage:** + +- Provides guidelines for contributors to ensure their pull requests adhere to project standards and facilitate a smooth review process. +- Adds a comment to the pull request outlining testing requirements, reviewer assignments, contribution guidelines, and closing procedures. + +--- + +## Secrets Management + +Properly configuring the necessary secrets in your repository settings is crucial for smooth workflow execution. These include: + +- `GITHUB_TOKEN`: Automatically provided by GitHub Actions for authentication. +- `FIREBASE_SERVICE_ACCOUNT`: JSON key file for Firebase service account authentication. + +### Environment Variables + +Ensure the following environment variables are set correctly: + +- `VITE_APP_FIREBASE_PROJECT_ID`: Unique identifier for your Firebase project. +- `VITE_APP_FIREBASE_API_KEY`: API key to interact with Firebase services. +- `VITE_APP_FIREBASE_AUTH_DOMAIN`: Domain for Firebase authentication. +- `VITE_APP_FIREBASE_DATABASE_URL`: URL of your Firebase Realtime Database. +- `VITE_APP_FIREBASE_STORAGE_BUCKET`: Cloud storage bucket URL. +- `VITE_APP_FIREBASE_MESSAGING_SENDER_ID`: Sender ID for Firebase Cloud Messaging. +- `VITE_APP_FIREBASE_APP_ID`: Unique identifier for your Firebase app. +- `VITE_APP_FIREBASE_MEASUREMENTID`: Identifier for Google Analytics. +- `VITE_APP_FIREBASE_FCM_VAPID_KEY`: Public key for Firebase Cloud Messaging. +- `CYPRESS_PROJECT_ID`: Identifier for the Cypress project. +- `CYPRESS_RECORD_KEY`: Key to record Cypress test results. + +**Note:** Ensure thorough configuration of these secrets within your repository settings to prevent any workflow errors. They play a crucial role in authenticating Firebase deployments and accessing the Firebase project. It's imperative to maintain their security and avoid exposing them within your forked repo. + +--- + +## Conclusion + +This CI/CD setup aims to automate various project management, testing, and deployment tasks, making the development process more efficient and streamlined. If you have any questions or need further customization, feel free to reach out on our Slack channel or open an issue. Happy coding! 🚀 + +--- + +By providing this detailed guide, we hope to facilitate a smooth and productive experience for all contributors, ensuring that our project remains robust, efficient, and welcoming to all. diff --git a/.github/labeler-v1.yml b/.github/labeler-v1.yml new file mode 100644 index 00000000..43914112 --- /dev/null +++ b/.github/labeler-v1.yml @@ -0,0 +1,80 @@ +# Labels for issues +bug: +- pattern: "(?i)bug" + color: "d73a4a" + description: "Something isn't working" + +chore: +- pattern: "(?i)chore" + color: "fef2c0" + description: "Routine tasks, maintenance, or housekeeping" + +documentation: +- pattern: "(?i)documentation|docs" + color: "0075ca" + description: "Improvements or additions to documentation" + +firebase: +- pattern: "(?i)firebase|firestore|emulator|storage" + color: "ffca28" + description: "Issues related to Firebase services" + +UI/UX: +- pattern: "(?i)ui|ux|screen|width|icon|height|button|page|css|margin|padding" + color: "cfd3d7" + description: "User interface and experience related issues" + +help wanted: +- pattern: "(?i)help wanted" + color: "008672" + description: "Extra attention is needed" + +good first issue: +- pattern: "(?i)good first issue|beginner friendly" + color: "7057ff" + description: "Good for newcomers" + +CI/CD: +- pattern: "(?i)CI/CD" + color: "a2eeef" + description: "Continuous Integration and Deployment" + +dependency: +- pattern: "(?i)dependency|dependencies|npm" + color: "fbca04" + description: "Dependency-related issues" + +Urgent: +- pattern: "(?i)urgent|important|critical" + color: "b60205" + description: "Critical or high priority" + +broken: +- pattern: "(?i)broken|not working|error" + color: "e99695" + description: "Broken functionality" + +feat: +- pattern: "(?i)feat|feature|add|enhancement|improvement" + color: "0e8a16" + description: "New feature or request" + +question: +- pattern: "(?i)question|help|doubt|confusion" + color: "d876e3" + description: "Further information is requested" + +other: +- pattern: "(?i)other|miscellaneous" + color: "5319e7" + description: "Other issues that do not fit in the above categories" + +approved: +- pattern: "(?i)approved|accepted|approved" + color: "28a745" + description: "Issue has been approved for implementation" + +unapproved: +- pattern: "(?i)unapproved|rejected|unapproved" + color: "cb2431" + description: "Issue has been unapproved or rejected for implementation" diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..dba5d35b --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,42 @@ +root: +- changed-files: + - any-glob-to-any-file: '*' + +Documentation: +- changed-files: + - any-glob-to-any-file: ['CONTRIBUTING.md', 'ISSUE_TEMPLATE/*', 'TESTDATA.md', 'code_of_conduct.md', 'database.rules.json', 'firebase.json', 'firestore.rules', 'firestore.indexes.json', 'LICENSE', 'README.md'] + +feature: +- head-branch: ['^feature', 'feature'] + +release: +- base-branch: 'master' + +security: +- changed-files: + - any-glob-to-any-file: 'firebase.json' + - any-glob-to-any-file: 'firestore.rules' + - any-glob-to-any-file: 'firestore.indexes.json' + +CI/CD: +- changed-files: + - any-glob-to-any-file: '.github/workflows/*' + - any-glob-to-any-file: '**/*.yml' + +testing: +- changed-files: + - any-glob-to-any-file: 'cypress/**/*.js' + +design: +- changed-files: + - any-glob-to-any-file: 'designs/**/*.css' + - any-glob-to-any-file: 'designs/**/*.scss' + - any-glob-to-any-file: 'designs/**/*.html' + +component: +- changed-files: + - any-glob-to-any-file: 'src/components/**/*' + +css: +- changed-files: + - any-glob-to-any-file: 'src/css/**/*' diff --git a/.github/labels.yml b/.github/labels.yml deleted file mode 100644 index 5709fbd2..00000000 --- a/.github/labels.yml +++ /dev/null @@ -1,22 +0,0 @@ -bug: - - "(bug|Bug)" -documentation: - - "(documentation|Documentation)" -firebase: - - "(firebase|Firebase|firestore|Firestore|emulator|Emulator|storage|Storage)" -UI/UX: - - "(UI|ui|UX|ux|screen|width|icon|height|button|page|css|CSS|margin|padding)" -help wanted: - - "help" -good first issue: - - "good first issue" -CI/CD: - - "CI/CD" -dependency: - - "(dependency|dependencies|npm)" -Urgent: - - "(Urgent|urgent|important)" -broken: - - "(broken|Broken|not working)" -feature: - - (Feature|feature|add|Add|ADD) diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 5d7e58c1..eb2ae270 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -9,8 +9,14 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/first-interaction@v1 + - name: Send Greeting Message + id: send-greeting + uses: actions/first-interaction@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: "Hello 👋🏻 @${{ github.actor }}! Thankyou for creating an issue!" - pr-message: " Thank you @${{ github.actor }} for creating your first pull request. It will be reviewed soon" + issue-message: "Hello @${{ github.actor }}! 👋 Welcome to the project! 🎉 Your issue is the first step towards making this project better, and we appreciate it. We will review it as soon as possible. In the meantime, feel free to explore the project and contribute more. Happy coding! 🚀" + pr-message: "Congratulations @${{ github.actor }}! 🎉 Your first pull request is a milestone! 🏁 You're officially a contributor now. We appreciate your effort and your contribution will be reviewed shortly. Keep up the good work, and happy coding! 🚀" + + - name: Check if Greeting Sent + if: steps.send-greeting.outputs.issue-message == 'sent' || steps.send-greeting.outputs.pr-message == 'sent' + run: echo "Greeting message sent successfully." diff --git a/.github/workflows/label-pull-requests.yml b/.github/workflows/label-pull-requests.yml new file mode 100644 index 00000000..38e2c4a7 --- /dev/null +++ b/.github/workflows/label-pull-requests.yml @@ -0,0 +1,20 @@ +name: "Pull Request Labeler" +on: + - pull_request_target + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run labeler for PRs + uses: actions/labeler@v5 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + configuration-path: .github/labeler.yml + sync-labels: true diff --git a/.github/workflows/label_issues.yml b/.github/workflows/label_issues.yml index 448d0382..450b6aa0 100644 --- a/.github/workflows/label_issues.yml +++ b/.github/workflows/label_issues.yml @@ -2,21 +2,26 @@ name: "Issue Labeler" on: issues: types: [opened, edited] - pull_request: - types: [opened, edited] + +permissions: + issues: write + contents: read jobs: - triage: + apply-labels: runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write steps: - - uses: actions/checkout@v2 - - uses: github/issue-labeler@v3.0 + - name: Checkout code + uses: actions/checkout@v2 + + - name: Label Issues + uses: github/issue-labeler@v3.4 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" - configuration-path: .github/labels.yml - enable-versioned-regex: 0 + configuration-path: .github/labeler-v1.yml + enable-versioned-regex: 1 + versioned-regex: 'issue_labeler_regex_version=(\d+)' + body-missing-regex-label: "broken-template" include-title: 1 - body-missing-regex-label: "no-body" + include-body: 1 + sync-labels: 1 diff --git a/.github/workflows/pull-request-target.yml b/.github/workflows/pull-request-target.yml new file mode 100644 index 00000000..4b974d99 --- /dev/null +++ b/.github/workflows/pull-request-target.yml @@ -0,0 +1,61 @@ +name: PR Target Workflow +on: + pull_request_target: + +jobs: + PR-Greeting: + name: Pull Request Target + runs-on: ubuntu-latest + steps: + - name: Add the PR Review Policy + uses: thollander/actions-comment-pull-request@v2 + + with: + comment_tag: pr_review_policy + message: | + # Pull Request Approval Process 🎉 + + Welcome and thank you for your contribution! Please ensure your PR adheres to the following guidelines to facilitate a smooth review process: + + ## Testing Your Code ✅ + + Before submitting your PR, please make sure your code passes all tests. Our CI system will check for: + + - **Code Coverage:** No reduction in overall code coverage below the target threshold. + - **File Coverage:** No individual file in the PR with code coverage below the threshold. + - **Merge Conflicts:** No merge conflicts. + + ## Reviewers 👥 + + Do not assign reviewers. Our project maintainers will review your PR and assign reviewers. You can communicate with your assigned reviewers through: + + - **Comments:** In this PR. + - **Slack:** Our Slack channel. + + ## Reviewing Your Code 🔍 + + Your assigned reviewers will: + + - Review your code. + - Mediate future discussions about the validity of your changes. + - Evaluate the validity of your work. + - Verify related issues that should be closed. + - Provide guidance on fixing your tests. + + ## CONTRIBUTING.md 📖 + + Please read our [CONTRIBUTING.md](../../CONTRIBUTING.md) file. Important points include: + + - **Issue Assignment:** PRs without assigned issues will be closed by the reviewer. + - **Issue References:** Make sure the first comment in the PR includes references to automatically close related issues upon merging. + + ## Other Guidelines 📌 + + - **Respect Volunteers' Time:** Be considerate of our volunteers' time. Avoid contacting the person who assigned reviewers unless they request your input. + - **Code of Conduct:** Follow the project's [Code of Conduct](../../code_of_conduct.md) in all interactions. + + ## Closing Your PR 🛑 + + If you need to close your PR, please comment with the reason for closure. This helps us understand why you decided to close the PR. + + Thank you for your understanding and cooperation. 🙏 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index d5cd3cf1..a858ce11 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,22 +1,29 @@ -name: Close inactive issues +name: "Close stale issues and Pull Requests" on: schedule: - - cron: "30 1 * * *" + - cron: "30 18 * * *" jobs: - close-issues: + stale: runs-on: ubuntu-latest permissions: issues: write pull-requests: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v9 with: - days-before-issue-stale: 30 - days-before-issue-close: 14 - stale-issue-label: "stale" - stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." - close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." - days-before-pr-stale: -1 - days-before-pr-close: -1 + days-before-stale: 30 + days-before-close: 180 + stale-issue-label: "no-issue-activity" + stale-issue-message: "Hey there! 👋 This issue seems to be a bit stale, as it has been open for 30 days without any activity. Could you take a moment to review it and provide any updates if necessary? If it's no longer relevant, no worries, but we'll need to close it in 180 days if we don't hear back." + close-issue-message: "Oops! 🚨 This issue has been inactive for 180 days, so we're closing it now. If the problem still exists, feel free to reopen or create a new issue. Thanks for your understanding and for helping us keep things tidy!" + stale-pr-message: "Hi! 🌟 This pull request has been open for 30 days without any activity. Could you please check if it still applies or needs any updates? If everything looks good, great! Otherwise, let us know if you need assistance or if someone else can take over. It'll be closed in 180 days if we don't hear from you." + close-pr-message: "Uh-oh! 🚀 This pull request has been idle for 180 days and is now closed. If you still need this change, please feel free to reopen the PR or create a new one. Thank you for your contribution!" + stale-pr-label: "no-pr-activity" + exempt-issue-labels: "awaiting-approval, work-in-progress" + exempt-pr-labels: "awaiting-approval, work-in-progress" + only-labels: "awaiting-feedback, awaiting-answers" + exempt-pr-milestones: "bugfix, improvement" + exempt-issue-milestones: "bugfix, improvement" + operations-per-run: 30 repo-token: ${{ secrets.GITHUB_TOKEN }}