Skip to content

Commit

Permalink
chore: merge branch qa into feat/providers
Browse files Browse the repository at this point in the history
-e 

Signed-off-by: Brian Chebon <[email protected]>
  • Loading branch information
brian-chebon committed Dec 8, 2024
2 parents 7d25030 + 0219403 commit 0713a39
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 70 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/coverage-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow valides that branch and commit names are standardized for better workflow.

name: Coverage Workflow

on:
workflow_call: # Makes the workflow reusable
inputs:
branch_name:
required: true
type: string
event_name:
required: true
type: string

jobs:
upload-coverage:
runs-on: ubuntu-latest
needs: test-and-upload
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
slug: open-feature/dart-server-sdk
files: ./coverage/lcov.info
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
jobs:
main:
permissions:
pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs
pull-requests: write # for sticky-pull-request-comment to common on a PR
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
name: Validate PR title
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Notifications

on:
issue_comment:
types: [created, edited, deleted]
push:
branches: [main]
pull_request:
types: [opened, edited, closed, reopened, synchronize]
deployment_status:
release:

jobs:
notify:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'

steps:
- id: 'notify_google_chat'
uses: 'google-github-actions/[email protected]'
with:
webhook_url: '${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}'
92 changes: 47 additions & 45 deletions .github/workflows/parent-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ on:
branches-ignore:
- test

pull_request:
branches:
- '*' # Matches pull requests to any branch
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
determine-workflow:
Expand All @@ -35,48 +37,48 @@ jobs:
branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
event_name: ${{ needs.determine-workflow.outputs.event_name }}

trigger-contributor-workflow:
name: Trigger Contributor Workflow
needs: trigger-validation
if: |
github.event_name == 'push' &&
needs.determine-workflow.outputs.branch_name != 'main' &&
needs.determine-workflow.outputs.branch_name != 'qa' &&
needs.determine-workflow.outputs.branch_name != 'beta'
uses: ./.github/workflows/contributor-workflow.yml
with:
branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
event_name: ${{ needs.determine-workflow.outputs.event_name }}
# trigger-contributor-workflow:
# name: Trigger Contributor Workflow
# needs: trigger-validation
# if: |
# github.event_name == 'push' &&
# needs.determine-workflow.outputs.branch_name != 'main' &&
# needs.determine-workflow.outputs.branch_name != 'qa' &&
# needs.determine-workflow.outputs.branch_name != 'beta'
# uses: ./.github/workflows/contributor-workflow.yml
# with:
# branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
# event_name: ${{ needs.determine-workflow.outputs.event_name }}

trigger-qa-workflow:
name: Trigger QA Workflow
needs: trigger-validation
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'qa'
uses: ./.github/workflows/qa-workflow.yml
with:
branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
event_name: ${{ needs.determine-workflow.outputs.event_name }}
# trigger-qa-workflow:
# name: Trigger QA Workflow
# needs: trigger-validation
# if: |
# github.event_name == 'pull_request' &&
# github.base_ref == 'qa'
# uses: ./.github/workflows/qa-workflow.yml
# with:
# branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
# event_name: ${{ needs.determine-workflow.outputs.event_name }}

trigger-beta-workflow:
name: Trigger Beta Workflow
needs: trigger-validation
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'beta'
uses: ./.github/workflows/beta-workflow.yml
with:
branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
event_name: ${{ needs.determine-workflow.outputs.event_name }}
# trigger-beta-workflow:
# name: Trigger Beta Workflow
# needs: trigger-validation
# if: |
# github.event_name == 'pull_request' &&
# github.base_ref == 'beta'
# uses: ./.github/workflows/beta-workflow.yml
# with:
# branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
# event_name: ${{ needs.determine-workflow.outputs.event_name }}

trigger-main-workflow:
name: Trigger Main Workflow
needs: trigger-validation
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'main'
uses: ./.github/workflows/main-workflow.yml
with:
branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
event_name: ${{ needs.determine-workflow.outputs.event_name }}
# trigger-main-workflow:
# name: Trigger Main Workflow
# needs: trigger-validation
# if: |
# github.event_name == 'pull_request' &&
# github.base_ref == 'main'
# uses: ./.github/workflows/main-workflow.yml
# with:
# branch_name: ${{ needs.determine-workflow.outputs.branch_name }}
# event_name: ${{ needs.determine-workflow.outputs.event_name }}
27 changes: 23 additions & 4 deletions .github/workflows/validation-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,28 @@ jobs:
set -euo pipefail
echo "Validating commit messages..."
REGEX="^(feat|fix|hotfix|chore|test|refactor|release)(\([a-z0-9_-]+\))?: .{1,72}$"
INVALID_COMMITS=$(git log -1 --format=%s | grep -vE "$REGEX" || true)
# Define the regex for conventional commit format
REGEX="^(feat|fix|hotfix|chore|test|refactor|release|ci)(\([a-z0-9_-]+\))?: .{1,72}$"
# Fetch the base branch dynamically (fallback to 'main' if not in a pull request)
BASE_BRANCH=${{ github.event.pull_request.base.ref || 'main' }}
echo "Base branch: $BASE_BRANCH"
# Fetch all commits between the base branch and the current branch
git fetch origin $BASE_BRANCH
# Extract all commit messages excluding auto-generated ones
INVALID_COMMITS=$(git log origin/$BASE_BRANCH..HEAD --pretty=format:"%s" \
| grep -vE "^(Merge pull request|Initial commit)" \
| grep -vE "^(Merge remote-tracking branch|Merge pull request)" \
| grep -vE "^(Merge branch|DCO Remediation|Signed-off-by)" \
| grep -vE "$REGEX" || true)
# Check for overly long summaries
LONG_SUMMARIES=$(git log origin/$BASE_BRANCH..HEAD --pretty=format:"%s" \
| awk 'length($0) > 72')
# Check if there are invalid commit messages
if [[ -n "$INVALID_COMMITS" ]]; then
echo "❌ The following commit messages do not follow the convention:"
echo "$INVALID_COMMITS"
Expand All @@ -62,5 +81,5 @@ jobs:
echo " fix(payment): resolve rounding error in total calculation"
exit 1
else
echo "✅ All commit messages follow the convention."
fi
echo "✅ All developer-made commit messages follow the convention."
fi
103 changes: 103 additions & 0 deletions local_dev_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
### **README for Local Git Hooks**

#### **Introduction**
This repository provides optional local Git hooks to help developers maintain code quality and adhere to commit conventions before pushing changes to the repository. These hooks automate checks during various stages of the Git workflow, ensuring that issues are caught early in the development process.

---

### **What Are Git Hooks?**
Git hooks are scripts that Git runs automatically at specific points in your workflow. Local Git hooks can be set up in your development environment to run checks before commits, pushes, or other Git actions. These hooks are not automatically shared across the team, so developers must configure them manually.

This repository includes three hooks for development:
1. **Pre-Commit Hook (`pre-commit`)**: Validates code before committing.
2. **Commit Message Hook (`commit-msg`)**: Ensures commit messages adhere to conventions.
3. **Pre-Push Hook (`pre-push`)**: Validates the branch name before allowing a push.

---

### **Included Hooks**
#### **1. Pre-Commit Hook**
- **Location**: `./local_dev_tools/validate_commit.dart`
- **Purpose**: Validates the code (e.g., linting or formatting) before allowing the commit.
- **When It Runs**: Automatically triggered before `git commit`.
- **Usage**:
- Ensures all code complies with the repository's coding standards.
- Prevents committing code with syntax errors or formatting issues.

#### **2. Commit Message Hook**
- **Location**: `./local_dev_tools/validate_commit_msg.dart`
- **Purpose**: Ensures commit messages follow the repository's commit message conventions (e.g., Conventional Commits).
- **When It Runs**: Automatically triggered after you enter a commit message.
- **Usage**:
- Validates the format of commit messages, ensuring clear and consistent commit history.
- Prevents commits with messages that fail validation.

#### **3. Pre-Push Hook**
- **Location**: `./local_dev_tools/validate_branch.dart`
- **Purpose**: Checks branch names or other repository-specific rules before pushing changes.
- **When It Runs**: Automatically triggered before `git push`.
- **Usage**:
- Ensures that the branch name follows naming conventions.
- Can block pushes from unintended branches (e.g., `main` or `master`).

---

### **Setup Instructions**
To enable these hooks in your local development environment:

#### **1. Install Hooks**
Run the following command to configure the hooks:
```bash
git config core.hooksPath ./local_dev_tools/
```

This command tells Git to look for hooks in the `./local_dev_tools` directory instead of the default `.git/hooks` directory.

---

### **How Developers Can Use These Hooks**
1. **Pre-Commit Checks**:
- When you run `git commit`, the `pre-commit` hook will validate your code.
- If any issues are detected (e.g., linting errors), the commit will be blocked, and you’ll be prompted to fix them.

2. **Commit Message Validation**:
- After you write a commit message, the `commit-msg` hook will check the message format.
- If the message doesn’t adhere to the required format, the commit will be rejected with instructions for fixing it.

3. **Pre-Push Validation**:
- When you run `git push`, the `pre-push` hook will check the branch name or other repository-specific rules.
- If the branch name is invalid or rules are violated, the push will be blocked.

---

### **FAQs**

#### **Q: Are these hooks mandatory?**
No, these hooks are optional. However, they are recommended to maintain consistency and quality.

#### **Q: How do I disable the hooks temporarily?**
To bypass hooks during a specific operation, use the `--no-verify` flag:
```bash
git commit --no-verify
git push --no-verify
```

#### **Q: Can I customize the hooks?**
Yes, you can modify the hook scripts (`validate_commit.dart`, `validate_commit_msg.dart`, and `validate_branch.dart`) to suit your project’s needs.

---

# Automatically add Signed-off-by to commit message
#!/bin/bash

if ! grep -q "Signed-off-by:" "$1"; then
echo "Signed-off-by: $(git config user.name) <$(git config user.email)>" >> "$1"
fi

chmod +x .git/hooks/prepare-commit-msg

### **Additional Notes**
- These hooks run locally on your machine and do not affect other developers.
- Hooks ensure that most issues are caught during development, saving time and effort during code reviews and CI/CD processes.

For further assistance, feel free to contact the repository maintainers. Happy coding! 🎉
31 changes: 31 additions & 0 deletions local_dev_tools/validate_branch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:io';

void main(List<String> args) {
print('Validating branch name...');

// Retrieve the branch name
final result = Process.runSync('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
final branchName = result.stdout.toString().trim();

if (branchName.isEmpty) {
print('❌ Could not determine branch name.');
exit(1);
}

print('Branch name: $branchName');

final validBranches = RegExp(r'^(qa|beta|main)$');
final validFeatureBranch =
RegExp(r'^(feat|fix|hotfix|chore|test|refactor|release)/[a-z0-9_-]+$');

if (validBranches.hasMatch(branchName) ||
validFeatureBranch.hasMatch(branchName)) {
print('✅ Branch name is valid.');
} else {
print(
'❌ Branch name does not follow the required convention: <type>/<branch-name>');
print(
'Valid types: feat, fix, hotfix, chore, test, refactor, release, qa, beta, main');
exit(1);
}
}
23 changes: 23 additions & 0 deletions local_dev_tools/validate_commit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:io';

void main(List<String> args) {
print('Validating commit...');

// Run dart analyze
final analyzeResult = Process.runSync('dart', ['analyze']);
if (analyzeResult.exitCode != 0) {
print('❌ Dart analyze failed. Please fix the issues.');
print(analyzeResult.stdout);
exit(1);
}

// Run dart format
final formatResult =
Process.runSync('dart', ['format', '--set-exit-if-changed', '.']);
if (formatResult.exitCode != 0) {
print('❌ Dart format failed. Please format your code.');
exit(1);
}

print('✅ Commit passed all validations.');
}
25 changes: 25 additions & 0 deletions local_dev_tools/validate_commit_msg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'dart:io';

void main(List<String> args) {
print('Validating commit message...');

if (args.isEmpty) {
print('❌ No commit message file provided.');
exit(1);
}

final commitMessage = File(args[0]).readAsStringSync();
final regex = RegExp(
r'^(feat|fix|hotfix|chore|test|refactor|release)(\([a-z0-9_-]+\))?: .{1,72}$');

if (!regex.hasMatch(commitMessage)) {
print('❌ Commit message does not follow the required format.');
print('Format: <type>(<scope>): <short summary>');
print('Examples:');
print(' feat(auth): add OAuth 2.0 support');
print(' fix(payment): resolve rounding error');
exit(1);
}

print('✅ Commit message is valid.');
}
Binary file not shown.
Loading

0 comments on commit 0713a39

Please sign in to comment.