Skip to content
Merged
26 changes: 26 additions & 0 deletions .github/environments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Develop": {
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
},
"reviewers": [],
"wait_timer": 0
},
"Production": {
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
},
"reviewers": [],
"wait_timer": 0
},
"GitHub Pages": {
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
},
"reviewers": [],
"wait_timer": 0
}
}
15 changes: 15 additions & 0 deletions .github/protection.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{
"develop": {
"allow_deletions": false,
"allow_force_pushes": false,
"enforce_admins": false,
Comment thread
a5chin marked this conversation as resolved.
Resolved
"required_pull_request_reviews": {
"dismiss_stale_reviews": false,
"require_code_owner_reviews": false,
"required_approving_review_count": 1
},
"required_status_checks": {
"contexts": [],
"strict": true
},
"restrictions": null
},
Comment thread
a5chin marked this conversation as resolved.
Resolved
"main": {
"allow_deletions": false,
"allow_force_pushes": false,
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/draft.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/publish-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish App to GHCR
on:
push:
branches:
- main
- develop
paths:
- ".github/workflows/publish-app.yml"
- ".python-version"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Publish Devcontainer to GHCR
on:
push:
branches:
- main
- develop
paths:
- ".devcontainer/Dockerfile"
- ".github/workflows/publish-devcontainer.yml"
Expand Down
27 changes: 25 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Release
on:
pull_request:
branches:
- develop
- main
types:
- closed
Expand All @@ -12,11 +13,33 @@ permissions:
pull-requests: read

jobs:
publish:
if: github.event.pull_request.merged == true && contains(github.head_ref, 'release/')
develop:
if: github.event.pull_request.merged == true && github.base_ref == 'develop'

runs-on: ubuntu-latest

environment: Develop

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Update Draft Release
uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter.yml
disable-autolabeler: true
publish: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

production:
if: github.event.pull_request.merged == true && github.base_ref == 'main'

runs-on: ubuntu-latest

environment: Production

steps:
- name: Checkout
uses: actions/checkout@v6
Comment thread
a5chin marked this conversation as resolved.
Resolved
Comment thread
a5chin marked this conversation as resolved.
Resolved
Expand Down
53 changes: 49 additions & 4 deletions .github/workflows/setting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- .github/workflows/setting.yml
- .github/environments.json
- .github/protection.json
schedule:
- cron: "0 0 * * *"
Expand All @@ -23,7 +24,9 @@ jobs:

- name: Enable auto-delete head branches
run: |
gh repo edit ${{ github.repository }} --delete-branch-on-merge
gh repo edit ${{ github.repository }} \
--default-branch develop \
--delete-branch-on-merge
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

Expand Down Expand Up @@ -68,12 +71,12 @@ jobs:

- name: Apply Branch Protection Rules
run: |
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: $CONFIG_FILE not found!"
if [ ! -f "${{ env.CONFIG_FILE }}" ]; then
echo "Error: ${{ env.CONFIG_FILE }} not found!"
exit 1
fi

BRANCHES=$(jq -r 'keys[]' "$CONFIG_FILE")
BRANCHES=$(jq -r 'keys[]' "${{ env.CONFIG_FILE }}")

for BRANCH in $BRANCHES; do
if ! gh api "repos/${{ github.repository }}/branches/$BRANCH" --silent >/dev/null 2>&1; then
Expand All @@ -86,3 +89,45 @@ jobs:
env:
CONFIG_FILE: .github/protection.json
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

environments:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- environment: Develop
branch: develop
- environment: Production
branch: main
- environment: GitHub Pages
branch: gh-pages

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_KEY }}

- name: Configure Environment
run: |
if [ ! -f "${{ env.CONFIG_FILE }}" ]; then
echo "Error: ${{ env.CONFIG_FILE }} not found!"
exit 1
fi

jq -c ".\"${{ env.ENVIRONMENT_NAME }}\"" "${{ env.CONFIG_FILE }}" | gh api -X PUT "repos/${{ github.repository }}/environments/${{ env.ENVIRONMENT_NAME }}" --input -

gh api -X POST "repos/${{ github.repository }}/environments/${{ env.ENVIRONMENT_NAME }}/deployment-branch-policies" \
-f "name=${{ env.BRANCH_NAME }}" \
-f "type=branch"
Comment thread
a5chin marked this conversation as resolved.
Resolved
env:
CONFIG_FILE: .github/environments.json
BRANCH_NAME: ${{ matrix.branch }}
ENVIRONMENT_NAME: ${{ matrix.environment }}
GH_TOKEN: ${{ steps.generate-token.outputs.token }}