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

Enhancements to GitHub Actions Workflows #142

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
209 changes: 209 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -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.
80 changes: 80 additions & 0 deletions .github/labeler-v1.yml
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -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/**/*'
22 changes: 0 additions & 22 deletions .github/labels.yml

This file was deleted.

12 changes: 9 additions & 3 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
20 changes: 20 additions & 0 deletions .github/workflows/label-pull-requests.yml
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading