Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: settings
"on":
push:
branches:
- main
schedule:
- cron: 42 6 * * *
workflow_dispatch:
Comment thread
sbp-bvanb marked this conversation as resolved.
permissions:
contents: read
jobs:
settings-action:
runs-on: ubuntu-24.04
steps:
# yamllint disable rule:line-length
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./
env:
GH_TOKEN: ${{ secrets.SETTINGS_ACTION }}
with:
description: Settings Action configures the settings of a GitHub repository.
project: ${{ github.repository }}
settings_actions_allowed_actions: selected
settings_actions_github_owned_allowed: true
settings_actions_verified_allowed: false
# mcvs-general-action v0.7.x runs lychee-action and
# markdownlint-cli2-action as nested actions.
settings_actions_patterns_allowed: 030/*,schubergphilis/*,zizmorcore/zizmor-action@*,lycheeverse/lychee-action@*,davidanson/markdownlint-cli2-action@*
settings_actions_require_sha_pinning: true
settings_default_workflow_permissions: read
settings_delete_branch_on_merge: true
settings_discussions: false
settings_github_workflows_can_approve_pull_request_reviews: false
settings_merge_commit: false
settings_merge_rebase: false
settings_merge_squash: true
settings_projects: false
settings_protect_main_branch: false
settings_wiki: false
topics: github-settings,settings-as-code
127 changes: 49 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,52 @@

Settings Action that will configure the settings of a GitHub repository.

## Usage

Create a `~/.github/workflows/settings-guard.yml` file:

```bash
---
name: settings-guard
'on':
schedule:
- cron: '42 6 * * *'
permissions: {}
jobs:
settings-action:
runs-on: ubuntu-22.04
steps:
- uses: 030/settings-action@v0.8.0
env:
GH_TOKEN: ${{ secrets.SETTINGS_GUARD }}
with:
debug: false
description: "Settings Action configures the settings of a GitHub repository."
project: 030/settings-guard
settings_actions_allowed_actions: "selected"
settings_actions_github_owned_allowed: true
settings_actions_verified_allowed: false
settings_actions_patterns_allowed: "030/*"
settings_actions_require_sha_pinning: true
settings_default_workflow_permissions: "read"
settings_delete_branch_on_merge: true
settings_discussions: false
settings_github_workflows_can_approve_pull_request_reviews: true
settings_merge_commit: false
settings_merge_rebase: false
settings_merge_squash: true
settings_protect_main_branch: true
settings_protect_main_branch_enforce_admins: true
settings_protect_main_branch_required_approving_review_count: 1
settings_projects: false
settings_wiki: false
topics: composite-action,github-project-setup,github-settings,settings-as-code
```

use the following variables:

| Option | Description |
| ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| debug | Enable debug logging |
| description | Change the description of a GitHub repository |
| project | The owner/repo |
| settings_actions_allowed_actions | Actions permissions: `all`, `local_only`, or `selected`. Use `selected` to allow OWNER + specific non-OWNER actions/reusable workflows |
| settings_actions_github_owned_allowed | When `settings_actions_allowed_actions` is `selected`, whether GitHub-owned actions (e.g. `actions/checkout`) are allowed |
| settings_actions_verified_allowed | When `settings_actions_allowed_actions` is `selected`, whether actions from verified creators are allowed |
| settings_actions_patterns_allowed | When `settings_actions_allowed_actions` is `selected`, comma-separated list of allowed actions/reusable workflows (e.g. `030/*`) |
| settings_actions_require_sha_pinning | Require actions to be pinned to a full-length commit SHA |
| settings_default_workflow_permissions | Set the default workflow permissions to read or write |
| settings_delete_branch_on_merge | Delete a branch on merge or not |
| settings_discussions | Enable the discussions tab or not |
| settings_github_workflows_can_approve_pull_request_reviews | Whether workflows can approve pull requests |
| settings_merge_commit | Enable merge commit |
| settings_merge_rebase | Enable merge request rebase |
| settings_merge_squash | Enable merge request squash |
| settings_protect_main_branch | Protect the main branch or not |
| settings_protect_main_branch_enforce_admins | Enforce branch protection for admins |
| settings_protect_main_branch_required_approving_review_count | The number of approvals that is required before a PR can be merged |
| settings_projects | Whether the project tab should be enabled |
| settings_wiki | Wiki enabled or not |
| topics | The topic(s) that will appear in the about menu of a project |

and create a token with read and admin permissions and store it as a
`SETTINGS_GUARD` variable in the variables menu.

## Testing

- [Install](https://github.com/cli/cli?tab=readme-ov-file#installation) gh cli.
- Create a read only token.
- Login: `gh auth login` and `choose token` option.
- Check [these graphql samples](https://gist.github.com/duboisf/68fb6e22ac0a2165ca298074f0e3b553)
that can be useful while testing.
## Quickstart

1. Create a `~/.github/workflows/settings-guard.yml` file:

```yaml
---
name: settings-guard
'on':
schedule:
- cron: '42 6 * * *'
permissions: {}
jobs:
settings-action:
runs-on: ubuntu-22.04
steps:
- uses: 030/settings-action@a27696394dd22683f19303883d8ef275b7287e83 # v0.10.1
Comment thread
sbp-bvanb marked this conversation as resolved.
env:
GH_TOKEN: ${{ secrets.SETTINGS_GUARD }}
with:
debug: false
description: "Settings Action configures the settings of a GitHub repository."
project: 030/settings-guard
settings_actions_allowed_actions: "selected"
settings_actions_github_owned_allowed: true
settings_actions_verified_allowed: false
settings_actions_patterns_allowed: "030/*"
settings_actions_require_sha_pinning: true
settings_default_workflow_permissions: "read"
settings_delete_branch_on_merge: true
settings_discussions: false
settings_github_workflows_can_approve_pull_request_reviews: true
settings_merge_commit: false
settings_merge_rebase: false
settings_merge_squash: true
settings_protect_main_branch: true
settings_protect_main_branch_enforce_admins: true
settings_protect_main_branch_required_approving_review_count: 1
settings_projects: false
settings_wiki: false
topics: composite-action,github-project-setup,github-settings,settings-as-code
```

1. Create a token with read and admin permissions on the repository.
1. Store it as a `SETTINGS_GUARD` secret in the repository settings.

## Documentation

- [Inputs](docs/inputs.md): every option the action accepts.
- [Testing](docs/testing.md): testing the action locally.
15 changes: 13 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ runs:
run: gh --version
shell: bash

- name: install the dependencies of main.py
shell: bash
env:
ACTION_PATH: ${{ github.action_path }}
run: |
# A private venv, so the caller does not have to install click and
# the Python on the caller's PATH is left alone.
python3 -m venv "$RUNNER_TEMP/settings-action-venv"
"$RUNNER_TEMP/settings-action-venv/bin/pip" install --disable-pip-version-check \
--require-hashes \
-r "$ACTION_PATH/requirements.txt"
- name: add a description for project ${{ inputs.project }}
shell: bash
env:
Expand Down Expand Up @@ -184,7 +195,7 @@ runs:
debug="--verbose"
fi

python3 "$ACTION_PATH/main.py" actions-permissions \
"$RUNNER_TEMP/settings-action-venv/bin/python" "$ACTION_PATH/main.py" actions-permissions \
--allowed-actions "$ALLOWED_ACTIONS" \
--github-owned-allowed "$GITHUB_OWNED_ALLOWED" \
--verified-allowed "$VERIFIED_ALLOWED" \
Expand Down Expand Up @@ -297,7 +308,7 @@ runs:
fi

update_branch_protection_rule() {
python3 "$ACTION_PATH/main.py" branch-protection-rules \
"$RUNNER_TEMP/settings-action-venv/bin/python" "$ACTION_PATH/main.py" branch-protection-rules \
--enforce-admins "$ENFORCE_ADMINS" \
--required-approving-review-count "$REQUIRED_APPROVING_REVIEW_COUNT"

Expand Down
28 changes: 28 additions & 0 deletions docs/inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Inputs

The inputs of the action, as used in the
[Quickstart](../README.md#quickstart) workflow:

| Option | Description |
| ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| debug | Enable debug logging |
| description | Change the description of a GitHub repository |
| project | The owner/repo |
| settings_actions_allowed_actions | Actions permissions: `all`, `local_only`, or `selected`. Use `selected` to allow OWNER + specific non-OWNER actions/reusable workflows |
| settings_actions_github_owned_allowed | When `settings_actions_allowed_actions` is `selected`, whether GitHub-owned actions (e.g. `actions/checkout`) are allowed |
| settings_actions_verified_allowed | When `settings_actions_allowed_actions` is `selected`, whether actions from verified creators are allowed |
| settings_actions_patterns_allowed | When `settings_actions_allowed_actions` is `selected`, comma-separated list of allowed actions/reusable workflows (e.g. `030/*`) |
| settings_actions_require_sha_pinning | Require actions to be pinned to a full-length commit SHA |
| settings_default_workflow_permissions | Set the default workflow permissions to read or write |
| settings_delete_branch_on_merge | Delete a branch on merge or not |
| settings_discussions | Enable the discussions tab or not |
| settings_github_workflows_can_approve_pull_request_reviews | Whether workflows can approve pull requests |
| settings_merge_commit | Enable merge commit |
| settings_merge_rebase | Enable merge request rebase |
| settings_merge_squash | Enable merge request squash |
| settings_protect_main_branch | Protect the main branch or not |
| settings_protect_main_branch_enforce_admins | Enforce branch protection for admins |
| settings_protect_main_branch_required_approving_review_count | The number of approvals that is required before a PR can be merged |
| settings_projects | Whether the project tab should be enabled |
| settings_wiki | Wiki enabled or not |
| topics | The topic(s) that will appear in the about menu of a project |
7 changes: 7 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Testing

- [Install](https://github.com/cli/cli?tab=readme-ov-file#installation) gh cli.
- Create a read only token.
- Login: `gh auth login` and `choose token` option.
- Check [these graphql samples](https://gist.github.com/duboisf/68fb6e22ac0a2165ca298074f0e3b553)
that can be useful while testing.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requires-python = ">=3.11"
name = "settings-action"
readme = "README.md"
license = { file = "LICENSE" }
dependencies = ["click"]
dependencies = ["click==8.5.0"]
Comment thread
sbp-bvanb marked this conversation as resolved.
dynamic = ["version"]

[project.optional-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --universal --python-version 3.11 --generate-hashes -o requirements.txt
click==8.5.0 \
--hash=sha256:255bc9599cf7748b4b1a446ccc735421bd08a2ae529a8b88597d3de5664ee360 \
--hash=sha256:ba0d2089de75ea0310e2dde03160e6ca10009947fb95a182f9b54021bb272e34
# via settings-action (pyproject.toml)
Loading