Skip to content

Commit 050a552

Browse files
Merge branch 'main-enterprise' into fix-nop-envs
2 parents 57b9777 + 1fff61c commit 050a552

35 files changed

+9852
-6554
lines changed

.eslintrc.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
"standard"
99
],
1010
"parserOptions": {
11-
"ecmaVersion": 12
11+
"ecmaVersion": 13
1212
},
1313
"rules": {
1414
},
15-
"ignorePatterns": ["test/**/*.js"]
15+
"overrides": [
16+
{
17+
"files": ["test/**/*.js"],
18+
"env": {
19+
"jest": true
20+
}
21+
}
22+
]
1623
}

.github/actions/codeql-analysis/action.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ env:
3131
REGISTRY: ghcr.io
3232
IMAGE_NAME: ${{ github.repository }}
3333

34+
permissions:
35+
contents: write
36+
packages: write
37+
3438
jobs:
3539
build:
3640
if: ${{ github.actor != 'dependabot'}}
@@ -46,15 +50,15 @@ jobs:
4650
cache: 'npm'
4751
- run: npm install
4852
- name: Set up Docker Buildx
49-
uses: docker/setup-buildx-action@v3
53+
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5
5054
- name: Log in to the Container registry
51-
uses: docker/login-action@v3
55+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
5256
with:
5357
registry: ${{ env.REGISTRY }}
5458
username: ${{ github.actor }}
5559
password: ${{ secrets.GITHUB_TOKEN }}
5660
- name: Build Docker Image Locally
57-
uses: docker/build-push-action@master
61+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
5862
with:
5963
context: .
6064
file: ./Dockerfile
@@ -73,15 +77,15 @@ jobs:
7377
- run: echo "${{ github.ref }}"
7478
- name: Tag a final release
7579
id: prerelease
76-
uses: actionsdesk/semver@0.6.0-rc.10
80+
uses: actionsdesk/semver@82aa4310e4e21c59cd0020007a4278e733e81dcb
7781
with:
7882
bump: ${{ inputs.bump }}
7983
prerelease: ${{ inputs.prerelease }}
8084
prelabel: ${{ inputs.prelabel }}
8185
commitish: ${{ github.ref }}
8286
- name: Push Docker Image
8387
if: ${{ success() }}
84-
uses: docker/build-push-action@master
88+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
8589
with:
8690
context: .
8791
file: ./Dockerfile

.github/workflows/create-release.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ env:
99
REGISTRY: ghcr.io
1010
IMAGE_NAME: ${{ github.repository }}
1111

12+
permissions:
13+
contents: write
14+
packages: write
15+
1216
jobs:
1317
build:
1418
if: ${{ github.actor != 'dependabot'}}
@@ -24,15 +28,15 @@ jobs:
2428
cache: "npm"
2529
- run: npm install
2630
- name: Set up Docker Buildx
27-
uses: docker/setup-buildx-action@v3
31+
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5
2832
- name: Log in to the Container registry
29-
uses: docker/login-action@v3
33+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
3034
with:
3135
registry: ${{ env.REGISTRY }}
3236
username: ${{ github.actor }}
3337
password: ${{ secrets.GITHUB_TOKEN }}
3438
- name: Build Docker Image Locally
35-
uses: docker/build-push-action@master
39+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
3640
with:
3741
context: .
3842
file: ./Dockerfile
@@ -50,12 +54,12 @@ jobs:
5054
curl http://localhost:3000
5155
- name: Tag a final release
5256
id: finalrelease
53-
uses: actionsdesk/semver@0.6.0-rc.10
57+
uses: actionsdesk/semver@82aa4310e4e21c59cd0020007a4278e733e81dcb
5458
with:
5559
bump: final
5660
- name: Push Docker Image
5761
if: ${{ success() }}
58-
uses: docker/build-push-action@master
62+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
5963
with:
6064
context: .
6165
file: ./Dockerfile

.github/workflows/deploy-k8s.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ jobs:
2929
steps:
3030
- name: Checkout repository
3131
uses: actions/checkout@v4
32-
- uses: azure/login@v1
32+
- uses: azure/login@a65d910e8af852a8061c627c456678983e180302
3333
with:
3434
client-id: ${{ secrets.AZURE_CLIENT_ID }}
3535
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
3636
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
37-
- uses: azure/aks-set-context@v3
37+
- uses: azure/aks-set-context@feeca6405be94202afcb1c395616ff29b1811b9f
3838
with:
3939
resource-group: ${{env.AZURE_RESOURCE_GROUP}}
4040
cluster-name: ${{env.AZURE_AKS_CLUSTER}}
4141
id: login
4242
- run: |
4343
kubectl get deployment
4444
- name: app-env
45-
uses: azure/k8s-create-secret@v4
45+
uses: azure/k8s-create-secret@6e0ba8047235646753f2a3a3b359b4d0006ff218
4646
with:
4747
namespace: 'default'
4848
secret-type: 'generic'
4949
arguments: --from-literal=APP_ID=${{ secrets.APP_ID }} --from-literal=PRIVATE_KEY=${{ secrets.PRIVATE_KEY }} --from-literal=WEBHOOK_SECRET=${{ secrets.WEBHOOK_SECRET }}
5050
secret-name: app-env
5151
- name: Set imagePullSecret
52-
uses: azure/k8s-create-secret@v4
52+
uses: azure/k8s-create-secret@6e0ba8047235646753f2a3a3b359b4d0006ff218
5353
with:
5454
namespace: ${{env.AZURE_AKS_NAMESPACE}}
5555
container-registry-url: ${{env.IMAGE_REGISTRY_URL}}
5656
container-registry-username: ${{ secrets.DOCKER_USERNAME }}
5757
container-registry-password: ${{ secrets.DOCKER_PASSWORD }}
5858
secret-name: 'image-pull-secret'
5959
id: create-secret
60-
- uses: Azure/k8s-deploy@v4.10
60+
- uses: Azure/k8s-deploy@v5
6161
with:
6262
namespace: ${{env.AZURE_AKS_NAMESPACE}}
6363
manifests: |

.github/workflows/node-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Node.js CI
22
on:
33
pull_request:
44

5+
permissions:
6+
contents: read
7+
58
concurrency:
69
group: ${{ github.workflow }}-${{ github.ref }}
710
cancel-in-progress: true

.github/workflows/rc-release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Tag a rc release
3636
if: ${{ !github.event.pull_request.head.repo.fork }}
3737
id: rcrelease
38-
uses: actionsdesk/semver@0.6.0-rc.10
38+
uses: actionsdesk/semver@82aa4310e4e21c59cd0020007a4278e733e81dcb
3939
with:
4040
prerelease: withBuildNumber
4141
prelabel: rc
@@ -60,23 +60,23 @@ jobs:
6060
- run: echo ${{ github.actor }}
6161

6262
- name: Log in to the Container registry
63-
uses: docker/login-action@v3
63+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
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@v5
71+
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
7272
with:
7373
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
7474
- name: Set up QEMU
75-
uses: docker/setup-qemu-action@v3
75+
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf
7676
- name: Set up Docker Buildx
77-
uses: docker/setup-buildx-action@v3
77+
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5
7878
- name: Build and push Docker image
79-
uses: docker/build-push-action@master
79+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
8080
with:
8181
context: .
8282
push: true

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232
>
3333
> Settings files must have a `.yml` extension only. For now, the `.yaml` extension is ignored.
3434
35+
3536
## How it works
3637

38+
`Safe-settings` is designed to run as a service listening for webhook events or as a scheduled job running on some regular cadence. It can also be triggered through GitHub Actions. (See the [How to use](#how-to-use) section for details on deploying and configuring.)
39+
40+
3741
### Events
3842
The App listens to the following webhook events:
3943

@@ -286,7 +290,21 @@ The following can be configured:
286290
- `Rulesets`
287291
- `Environments` - wait timer, required reviewers, prevent self review, protected branches deployment branch policy, custom deployment branch policy, variables, deployment protection rules
288292

289-
It is possible to provide an `include` or `exclude` settings to restrict the `collaborators`, `teams`, `labels` to a list of repos or exclude a set of repos for a collaborator.
293+
> [!important]
294+
> It is possible to provide an `include` or `exclude` settings to restrict the `collaborators`, `teams`, `labels` to a list of repos or exclude a set of repos for a collaborator.
295+
> The include/exclude pattern can also be for glob. For e.g.:
296+
```
297+
teams:
298+
- name: Myteam-admins
299+
permission: admin
300+
- name: Myteam-developers
301+
permission: push
302+
- name: Other-team
303+
permission: push
304+
include:
305+
- '*-config'
306+
```
307+
> Will only add `Other-team` to only `*-config` repos
290308
291309
See [`docs/sample-settings/settings.yml`](docs/sample-settings/settings.yml) for a sample settings file.
292310
@@ -364,11 +382,13 @@ You can pass environment variables; the easiest way to do it is via a `.env` fil
364382
365383
## How to use
366384
367-
1. __[Deploy and install the app](docs/deploy.md)__.
385+
1. Create an `admin` repo (or an alternative of your choosing) within your organization. Remember to set `ADMIN_REPO` if you choose something other than `admin`. See [Environment variables](#environment-variables) for more details.
386+
387+
2. Add the settings for the `org`, `suborgs`, and `repos`. Sample files can be found [here](docs/sample-settings).
388+
389+
3. __[Deploy and install the app](docs/deploy.md)__. Alternatively, the __[GitHub Actions Guide](docs/github-action.md)__ describes how to run `safe-settings` with GitHub Actions.
368390
369-
2. Create an `admin` repo (or an alternative of your choosing) within your organization. Remember to set `CONFIG_REPO` if you choose something other than `admin`. See [Environment variables](#environment-variables) for more details.
370391
371-
3. Add the settings for the `org`, `suborgs`, and `repos`. Sample files can be found [here](docs/sample-settings).
372392
373393
374394
## License

docs/github-action.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Running Safe-settings with GitHub Actions (GHA)
2+
3+
This guide describes how to schedule a full safe-settings sync using GitHub Actions. This assumes that an `admin` repository has been configured with your `safe-settings` configuration. Refer to the [How to Use](../README.md#how-to-use) docs for more details on that process.
4+
5+
6+
## GitHub App Creation
7+
Follow the [Create the GitHub App](deploy.md#create-the-github-app) guide to create an App in your GitHub account. This will allow `safe-settings` to access and modify your repos.
8+
9+
10+
## Defining the GitHub Action Workflow
11+
Running a full-sync with `safe-settings` can be done via `npm run full-sync`. This requires installing Node, such as with [actions/setup-node](https://github.com/actions/setup-node) (see example below). When doing so, the appropriate environment variables must be set (see the [Environment variables](#environment-variables) document for more details).
12+
13+
14+
### Example GHA Workflow
15+
The below example uses the GHA "cron" feature to run a full-sync every 4 hours. While not required, this example uses the `.github` repo as the `admin` repo (set via `ADMIN_REPO` env var) and the safe-settings configurations are stored in the `safe-settings/` directory (set via `CONFIG_PATH` and `DEPLOYMENT_CONFIG_FILE`).
16+
17+
```yaml
18+
name: Safe Settings Sync
19+
on:
20+
schedule:
21+
- cron: "0 */4 * * *"
22+
workflow_dispatch: {}
23+
24+
jobs:
25+
safeSettingsSync:
26+
runs-on: ubuntu-latest
27+
env:
28+
# Version/tag of github/safe-settings repo to use:
29+
SAFE_SETTINGS_VERSION: 2.1.13
30+
31+
# Path on GHA runner box where safe-settings code downloaded to:
32+
SAFE_SETTINGS_CODE_DIR: ${{ github.workspace }}/.safe-settings-code
33+
steps:
34+
# Self-checkout of 'admin' repo for access to safe-settings config:
35+
- uses: actions/checkout@v4
36+
37+
# Checkout of safe-settings repo for running full sync:
38+
- uses: actions/checkout@v4
39+
with:
40+
repository: github/safe-settings
41+
ref: $SAFE_SETTINGS_VERSION
42+
path: $SAFE_SETTINGS_CODE_DIR
43+
- uses: actions/setup-node@v4
44+
- run: npm install
45+
working-directory: $SAFE_SETTINGS_CODE_DIR
46+
- run: npm run full-sync
47+
working-directory: $SAFE_SETTINGS_CODE_DIR
48+
env:
49+
GH_ORG: ${{ vars.SAFE_SETTINGS_GH_ORG }}
50+
APP_ID: ${{ vars.SAFE_SETTINGS_APP_ID }}
51+
PRIVATE_KEY: ${{ secrets.SAFE_SETTINGS_PRIVATE_KEY }}
52+
GITHUB_CLIENT_ID: ${{ vars.SAFE_SETTINGS_GITHUB_CLIENT_ID }}
53+
GITHUB_CLIENT_SECRET: ${{ secrets.SAFE_SETTINGS_GITHUB_CLIENT_SECRET }}
54+
ADMIN_REPO: .github
55+
CONFIG_PATH: safe-settings
56+
DEPLOYMENT_CONFIG_FILE: ${{ github.workspace }}/safe-settings/deployment-settings.yml
57+
```

full-sync.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { createProbot } = require('probot')
2+
const appFn = require('./')
3+
4+
const probot = createProbot()
5+
probot.log.info('Starting full sync.')
6+
const app = appFn(probot, {})
7+
app.syncInstallation()
8+
.then(settings => {
9+
if (settings.errors.length > 0) {
10+
probot.log.error('Errors occurred during full sync.')
11+
process.exit(1)
12+
} else {
13+
probot.log.info('Done with full sync.')
14+
}
15+
})
16+
.catch(error => {
17+
process.stdout.write(`Unexpected error during full sync: ${error}\n`)
18+
process.exit(1)
19+
})

0 commit comments

Comments
 (0)