Skip to content

Commit e68077b

Browse files
committed
fix: deploy flow
1 parent e7192de commit e68077b

File tree

6 files changed

+108
-10
lines changed

6 files changed

+108
-10
lines changed

.github/environments.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"Develop": {
3+
"deployment_branch_policy": {
4+
"protected_branches": false,
5+
"custom_branch_policies": true
6+
},
7+
"reviewers": [],
8+
"wait_timer": 0
9+
},
10+
"Production": {
11+
"deployment_branch_policy": {
12+
"protected_branches": false,
13+
"custom_branch_policies": true
14+
},
15+
"reviewers": [],
16+
"wait_timer": 0
17+
}
18+
}

.github/protection.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
},
1515
"restrictions": null
1616
},
17+
"develop": {
18+
"allow_deletions": false,
19+
"allow_force_pushes": false,
20+
"enforce_admins": false,
21+
"required_pull_request_reviews": {
22+
"dismiss_stale_reviews": false,
23+
"require_code_owner_reviews": false,
24+
"required_approving_review_count": 1
25+
},
26+
"required_status_checks": {
27+
"contexts": [],
28+
"strict": true
29+
},
30+
"restrictions": null
31+
},
1732
"gh-pages": {
1833
"allow_deletions": false,
1934
"allow_force_pushes": true,

.github/workflows/publish-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publish App to GHCR
33
on:
44
push:
55
branches:
6-
- main
6+
- develop
77
paths:
88
- ".github/workflows/publish-app.yml"
99
- ".python-version"

.github/workflows/publish-devcontainer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publish Devcontainer to GHCR
33
on:
44
push:
55
branches:
6-
- main
6+
- develop
77
paths:
88
- ".devcontainer/Dockerfile"
99
- ".github/workflows/publish-devcontainer.yml"

.github/workflows/release.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,41 @@ name: Release
33
on:
44
pull_request:
55
branches:
6+
- develop
67
- main
7-
types:
8-
- closed
98

109
permissions:
1110
contents: write
1211
pull-requests: read
1312

1413
jobs:
15-
publish:
16-
if: github.event.pull_request.merged == true && contains(github.head_ref, 'release/')
14+
develop:
15+
if: github.event.pull_request.merged == true && github.base_ref == 'develop'
1716

1817
runs-on: ubuntu-latest
1918

19+
environment: Develop
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v6
24+
25+
- name: Update Draft Release
26+
uses: release-drafter/release-drafter@v6
27+
with:
28+
config-name: release-drafter.yml
29+
disable-autolabeler: true
30+
publish: false
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
34+
production:
35+
if: github.event.pull_request.merged == true && github.base_ref == 'main'
36+
37+
runs-on: ubuntu-latest
38+
39+
environment: Production
40+
2041
steps:
2142
- name: Checkout
2243
uses: actions/checkout@v6

.github/workflows/setting.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ jobs:
2323

2424
- name: Enable auto-delete head branches
2525
run: |
26-
gh repo edit ${{ github.repository }} --delete-branch-on-merge
26+
gh repo edit ${{ github.repository }} \
27+
--delete-branch-on-merge \
28+
--default-branch develop
2729
env:
2830
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
2931

@@ -68,12 +70,12 @@ jobs:
6870

6971
- name: Apply Branch Protection Rules
7072
run: |
71-
if [ ! -f "$CONFIG_FILE" ]; then
72-
echo "Error: $CONFIG_FILE not found!"
73+
if [ ! -f "${{ env.CONFIG_FILE }}" ]; then
74+
echo "Error: ${{ env.CONFIG_FILE }} not found!"
7375
exit 1
7476
fi
7577
76-
BRANCHES=$(jq -r 'keys[]' "$CONFIG_FILE")
78+
BRANCHES=$(jq -r 'keys[]' "${{ env.CONFIG_FILE }}")
7779
7880
for BRANCH in $BRANCHES; do
7981
if ! gh api "repos/${{ github.repository }}/branches/$BRANCH" --silent >/dev/null 2>&1; then
@@ -86,3 +88,45 @@ jobs:
8688
env:
8789
CONFIG_FILE: .github/protection.json
8890
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
91+
92+
environments:
93+
runs-on: ubuntu-latest
94+
95+
strategy:
96+
matrix:
97+
include:
98+
- environment: Develop
99+
branch: develop
100+
- environment: Production
101+
branch: main
102+
103+
environment: ${{ matrix.environment }}
104+
105+
steps:
106+
- name: Checkout
107+
uses: actions/checkout@v6
108+
109+
- name: Generate a token
110+
id: generate-token
111+
uses: actions/create-github-app-token@v2
112+
with:
113+
app-id: ${{ vars.APP_ID }}
114+
private-key: ${{ secrets.APP_KEY }}
115+
116+
- name: Configure Environment
117+
run: |
118+
if [ ! -f "${{ env.CONFIG_FILE }}" ]; then
119+
echo "Error: ${{ env.CONFIG_FILE }} not found!"
120+
exit 1
121+
fi
122+
123+
jq -c ".\"${{ env.ENVIRONMENT_NAME }}\"" "${{ env.CONFIG_FILE }}" | gh api -X PUT "repos/${{ github.repository }}/environments/${{ env.ENVIRONMENT_NAME }}" --input -
124+
125+
gh api -X PUT "repos/${{ github.repository }}/environments/${{ env.ENVIRONMENT_NAME }}/deployment-branch-policies" \
126+
-f "name=${{ env.ENVIRONMENT_NAME }}" \
127+
-f "type=branch"
128+
env:
129+
CONFIG_FILE: .github/environments.json
130+
BRANCH_NAME: ${{ matrix.branch }}
131+
ENVIRONMENT_NAME: ${{ matrix.environment }}
132+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

0 commit comments

Comments
 (0)