Skip to content

Commit 9fff272

Browse files
authored
Merge branch 'main-enterprise' into docs-github-action
2 parents 8928d69 + 467f68b commit 9fff272

File tree

12 files changed

+609
-392
lines changed

12 files changed

+609
-392
lines changed

.github/workflows/create-pre-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ jobs:
5050
cache: 'npm'
5151
- run: npm install
5252
- name: Set up Docker Buildx
53-
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
53+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
5454
- name: Log in to the Container registry
55-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
55+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
5656
with:
5757
registry: ${{ env.REGISTRY }}
5858
username: ${{ github.actor }}
5959
password: ${{ secrets.GITHUB_TOKEN }}
6060
- name: Build Docker Image Locally
61-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0
61+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
6262
with:
6363
context: .
6464
file: ./Dockerfile
@@ -85,7 +85,7 @@ jobs:
8585
commitish: ${{ github.ref }}
8686
- name: Push Docker Image
8787
if: ${{ success() }}
88-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0
88+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
8989
with:
9090
context: .
9191
file: ./Dockerfile

.github/workflows/create-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
cache: "npm"
2929
- run: npm install
3030
- name: Set up Docker Buildx
31-
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
31+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
3232
- name: Log in to the Container registry
33-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
33+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
3434
with:
3535
registry: ${{ env.REGISTRY }}
3636
username: ${{ github.actor }}
3737
password: ${{ secrets.GITHUB_TOKEN }}
3838
- name: Build Docker Image Locally
39-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0
39+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
4040
with:
4141
context: .
4242
file: ./Dockerfile
@@ -59,7 +59,7 @@ jobs:
5959
bump: final
6060
- name: Push Docker Image
6161
if: ${{ success() }}
62-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0
62+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
6363
with:
6464
context: .
6565
file: ./Dockerfile

.github/workflows/rc-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ jobs:
6060
- run: echo ${{ github.actor }}
6161

6262
- name: Log in to the Container registry
63-
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
63+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
6464
with:
6565
registry: ${{ env.REGISTRY }}
6666
username: ${{ github.actor }}
6767
password: ${{ secrets.GITHUB_TOKEN }}
6868

6969
- name: Extract metadata
7070
id: meta
71-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
71+
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f
7272
with:
7373
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
7474
- name: Set up QEMU
7575
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392
7676
- name: Set up Docker Buildx
77-
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
77+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
7878
- name: Build and push Docker image
79-
uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0
79+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
8080
with:
8181
context: .
8282
push: true

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# GitHub Safe-Settings
1+
# 🛡️ GitHub Safe-Settings
22

33
[![Create a release](https://github.com/github/safe-settings/actions/workflows/create-release.yml/badge.svg)](https://github.com/github/safe-settings/actions/workflows/create-release.yml)
4+
[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5+
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
6+
7+
> **Policy-as-Code for GitHub Organizations**
8+
> Centrally manage and enforce repository settings, branch protections, teams, and more across your entire GitHub organization.
49
510
`Safe-settings` – an app to manage policy-as-code and apply repository settings across an organization.
611

@@ -29,8 +34,121 @@
2934

3035
> [!NOTE]
3136
> The `suborg` and `repo` level settings directory structure cannot be customized.
32-
>
3337
38+
## 🚀 Quick Start
39+
40+
### 1. **Deploy Safe-Settings**
41+
42+
Choose your preferred deployment method:
43+
44+
- **🌟 AWS Lambda (**: Use the [SafeSettings-Template](https://github.com/bheemreddy181/SafeSettings-Template) for production-ready deployment with Docker containers, GitHub Actions CI/CD, and comprehensive testing
45+
- **🐳 Docker**: Deploy using Docker containers locally or in your infrastructure
46+
- **☁️ Cloud Platforms**: Deploy to Heroku, Glitch, or Kubernetes
47+
48+
👉 **[View all deployment options →](docs/deploy.md)**
49+
50+
### 2. **Create Admin Repository**
51+
52+
Create an `admin` repository in your organization to store all configuration files:
53+
54+
```bash
55+
# Create admin repo in your organization
56+
gh repo create your-org/admin --private
57+
```
58+
59+
### 3. **Configure Settings Structure**
60+
61+
Set up your configuration files in the admin repository:
62+
63+
```
64+
admin/
65+
├── .github/
66+
│ ├── settings.yml # Organization-wide settings
67+
│ ├── suborgs/ # Sub-organization settings
68+
│ │ ├── frontend-team.yml
69+
│ │ └── backend-team.yml
70+
│ └── repos/ # Repository-specific settings
71+
│ ├── api-service.yml
72+
│ └── web-app.yml
73+
```
74+
75+
### 4. **Install GitHub App**
76+
77+
Install the Safe-Settings GitHub App in your organization with the required permissions.
78+
79+
👉 **[Complete setup guide →](#how-to-use)**
80+
81+
## 📊 Visual Architecture
82+
83+
### Configuration Hierarchy
84+
85+
```mermaid
86+
graph TD
87+
A[Organization Settings<br/>.github/settings.yml] --> B[Sub-Organization Settings<br/>.github/suborgs/*.yml]
88+
B --> C[Repository Settings<br/>.github/repos/*.yml]
89+
90+
style A fill:#e1f5fe,stroke:#01579b,stroke-width:2px,color:#000
91+
style B fill:#f3e5f5,stroke:#4a148c,stroke-width:2px,color:#000
92+
style C fill:#e8f5e8,stroke:#1b5e20,stroke-width:2px,color:#000
93+
```
94+
95+
**Precedence Order**: Repository > Sub-Organization > Organization
96+
97+
### Request Flow
98+
99+
```mermaid
100+
sequenceDiagram
101+
participant GH as GitHub
102+
participant SS as Safe-Settings
103+
participant AR as Admin Repo
104+
participant TR as Target Repos
105+
106+
Note over GH,TR: Webhook Event Processing
107+
108+
GH->>+SS: Webhook Event<br/>(push, repo created, etc.)
109+
SS->>SS: Validate Event Source
110+
SS->>+AR: Fetch Configuration Files<br/>(.github/settings.yml, suborgs/, repos/)
111+
AR-->>-SS: Return Config Files
112+
113+
SS->>SS: Merge Configurations<br/>(Org → Suborg → Repo)
114+
SS->>SS: Compare with Current<br/>GitHub Settings
115+
116+
alt Configuration Changes Detected
117+
SS->>+TR: Apply Settings<br/>(Branch Protection, Teams, etc.)
118+
TR-->>-SS: Confirm Changes
119+
SS->>GH: Create Check Run<br/>(Success/Failure)
120+
else No Changes Needed
121+
SS->>GH: Create Check Run<br/>(No Changes)
122+
end
123+
124+
SS-->>-GH: HTTP 200 Response
125+
126+
Note over GH,TR: Pull Request Validation (Dry-Run Mode)
127+
128+
GH->>+SS: PR Event<br/>(opened, synchronize)
129+
SS->>+AR: Fetch PR Changes<br/>(Modified Config Files)
130+
AR-->>-SS: Return Changed Configs
131+
132+
SS->>SS: Validate Changes<br/>(Dry-Run Mode)
133+
SS->>SS: Run Custom Validators<br/>(if configured)
134+
135+
alt Validation Passes
136+
SS->>GH: ✅ Check Success<br/>+ PR Comment (optional)
137+
else Validation Fails
138+
SS->>GH: ❌ Check Failure<br/>+ Error Details
139+
end
140+
141+
SS-->>-GH: HTTP 200 Response
142+
143+
Note over GH,TR: Scheduled Sync (Drift Prevention)
144+
145+
SS->>SS: Cron Trigger<br/>(if configured)
146+
SS->>+AR: Fetch All Configurations
147+
AR-->>-SS: Return All Configs
148+
SS->>+TR: Sync All Repositories<br/>(Prevent Drift)
149+
TR-->>-SS: Confirm Sync
150+
SS->>GH: Create Check Run<br/>(Sync Results)
151+
```
34152

35153
## How it works
36154

index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,32 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
624624
return syncSettings(false, context)
625625
})
626626

627+
robot.on('repository.archived', async context => {
628+
const { payload } = context
629+
const { sender } = payload
630+
631+
if (sender.type === 'Bot') {
632+
robot.log.debug('Repository Archived by a Bot')
633+
return
634+
}
635+
robot.log.debug('Repository Archived by a Human')
636+
637+
return syncSettings(false, context)
638+
})
639+
640+
robot.on('repository.unarchived', async context => {
641+
const { payload } = context
642+
const { sender } = payload
643+
644+
if (sender.type === 'Bot') {
645+
robot.log.debug('Repository Unarchived by a Bot')
646+
return
647+
}
648+
robot.log.debug('Repository Unarchived by a Human')
649+
650+
return syncSettings(false, context)
651+
})
652+
627653
if (process.env.CRON) {
628654
/*
629655
# ┌────────────── second (optional)

0 commit comments

Comments
 (0)