-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ai-cfia/24-change-github-teams-management…
…-strategy Adding codeowners file creation script
- Loading branch information
Showing
13 changed files
with
283 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: Devops repository workflow | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- closed | ||
- synchronize | ||
|
||
jobs: | ||
markdown-check: | ||
uses: | ||
ai-cfia/github-workflows/.github/workflows/workflow-markdown-check.yml@main | ||
|
||
yaml-check: | ||
uses: | ||
ai-cfia/github-workflows/.github/workflows/workflow-yaml-check.yml@main | ||
|
||
sh-check: | ||
uses: | ||
ai-cfia/github-workflows/.github/workflows/workflow-sh-check.yml@main | ||
|
||
repo-standard: | ||
uses: | ||
ai-cfia/github-workflows/.github/workflows/workflow-repo-standards-validation.yml@main | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
# GitHub Branch Protection Automation Script | ||
This script adds a branch protection requiring lint-test to pass in order to be able to merge the changes to the main branch. | ||
|
||
This script adds a branch protection requiring lint-test to pass in order to be | ||
able to merge the changes to the main branch. | ||
|
||
## Description | ||
This script is designed to automate the process of setting up branch protection rules on the main branch of each public repository within a specified GitHub organization. It specifically adds a branch protection rule that requires the lint-test / build status check to pass before changes can be merged into the main branch. | ||
|
||
This script is designed to automate the process of setting up branch protection | ||
rules on the main branch of each public repository within a specified GitHub | ||
organization. It specifically adds a branch protection rule that requires the | ||
lint-test / build status check to pass before changes can be merged into the | ||
main branch. | ||
|
||
## Permission required | ||
|
||
Administration - Access: Read and write | ||
|
||
## Usage | ||
Run the script in a Bash-compatible shell. Ensure you have the necessary permissions on the GitHub token for the organization. | ||
|
||
Run the script in a Bash-compatible shell. Ensure you have the necessary | ||
permissions on the GitHub token for the organization. | ||
|
||
## Breakdown | ||
|
||
The script performs three actions : | ||
|
||
- Prompt user for token. | ||
- Get all public repositories from the organisation. | ||
- Apply the branch protection rule to the repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# CODEOWNERS Automation Script | ||
|
||
This script automates the creation of CODEOWNERS files within repositories of | ||
the CFIA organization and applies tag rules based on repository names. | ||
|
||
## Functionality | ||
|
||
* **Creates CODEOWNERS Files:** The script generates CODEOWNERS files in target | ||
repositories, defining code ownership rules to streamline the review process. | ||
* **Customizable Team Tagging:** It tags relevant teams (`backend`, `frontend`, | ||
`data`, `devops`) based on the repository name. | ||
* **DevOps Ownership:** The script assigns specific ownership to the DevOps team | ||
for files within the `.github` directory, Dockerfile, and docker-compose | ||
configurations. | ||
|
||
## Requirements | ||
|
||
* **GitHub Personal Access Token (PAT):** A PAT with the `repo` scope. | ||
|
||
## Usage | ||
|
||
1. **Set Environment Variables:** | ||
1. `GITHUB_TOKEN`: Store your GitHub PAT in this environment variable. | ||
2. `ORG_NAME`: Set this to the name of your target GitHub organization. | ||
2. **Execute the Script:** Run the script. It will: | ||
1. Prompt for your GitHub token (if not set). | ||
2. Retrieve a list of repositories within the organization. | ||
3. Process each repository, generating and adding the CODEOWNERS file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
generate_codeowners() { | ||
repo_name=$1 | ||
|
||
echo "# This CODEOWNERS file is auto-generated. See the script for modification details." > .github/CODEOWNERS | ||
|
||
# Default rules for AI-CFIA ownership for repositories which name ends with "backend", "frontend" or "db" | ||
if [[ ${repo_name} == *"backend" ]]; then | ||
echo "* @ai-cfia/backend" >> .github/CODEOWNERS | ||
elif [[ ${repo_name} == *"frontend" ]]; then | ||
echo "* @ai-cfia/frontend" >> .github/CODEOWNERS | ||
elif [[ ${repo_name} == *"db" ]]; then | ||
echo "* @ai-cfia/data" >> .github/CODEOWNERS | ||
fi | ||
|
||
{ | ||
echo "/.github/ @ai-cfia/devops" | ||
echo "Dockerfile @ai-cfia/devops" | ||
echo "docker-compose.yml @ai-cfia/devops" | ||
echo "docker-compose.*.yml @ai-cfia/devops" | ||
} >> .github/CODEOWNERS | ||
} | ||
|
||
create_codeowners() { | ||
org_name=$1 | ||
repo_name=$2 | ||
codeowners_content=$(generate_codeowners "${repo_name}") | ||
|
||
encoded_content=$(echo "${codeowners_content}" | base64 -w 0) | ||
|
||
API_URL="https://api.github.com/repos/${org_name}/${repo_name}/contents/.github/CODEOWNERS" | ||
|
||
curl -s -X PUT \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
-d "{\"message\": \"Add CODEOWNERS file\", \"content\": \"${encoded_content}\"}" \ | ||
"${API_URL}" | ||
} | ||
|
||
echo "Please enter your GitHub token:" | ||
read -r GITHUB_TOKEN | ||
|
||
ORG_NAME="ai-cfia" | ||
API_URL="https://api.github.com/orgs/${ORG_NAME}/repos?type=public" | ||
RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${API_URL}") | ||
REPOS=$(echo "${RESPONSE}" | jq -r '.[].full_name') | ||
|
||
for REPO in ${REPOS}; do | ||
echo "Processing repository: ${REPO}" | ||
|
||
create_codeowners "$(dirname "${REPO}") $(basename "${REPO}")" | ||
|
||
done |
Oops, something went wrong.