Skip to content

Commit 56a2b75

Browse files
authored
Merge pull request #171 from a5chin/fix/deploy
Fix deploy workflow
2 parents c9217c3 + d764505 commit 56a2b75

8 files changed

Lines changed: 134 additions & 40 deletions

File tree

‎.github/environments.json‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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-pages": {
19+
"deployment_branch_policy": null,
20+
"reviewers": [],
21+
"wait_timer": 0
22+
}
23+
}

‎.github/protection.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
{
2+
"develop": {
3+
"allow_deletions": false,
4+
"allow_force_pushes": false,
5+
"enforce_admins": false,
6+
"required_pull_request_reviews": {
7+
"dismiss_stale_reviews": false,
8+
"require_code_owner_reviews": false,
9+
"required_approving_review_count": 1
10+
},
11+
"required_status_checks": {
12+
"contexts": [],
13+
"strict": true
14+
},
15+
"restrictions": null
16+
},
217
"main": {
318
"allow_deletions": false,
419
"allow_force_pushes": false,

‎.github/workflows/draft.yml‎

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

‎.github/workflows/gh-deploy.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
deploy:
2121
runs-on: ubuntu-latest
2222

23+
environment: github-pages
24+
2325
steps:
2426
- name: Checkout
2527
uses: actions/checkout@v6

‎.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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Release
33
on:
44
pull_request:
55
branches:
6+
- develop
67
- main
78
types:
89
- closed
@@ -12,11 +13,33 @@ permissions:
1213
pull-requests: read
1314

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

1819
runs-on: ubuntu-latest
1920

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

‎.github/workflows/setting.yml‎

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
paths:
66
- .github/workflows/setting.yml
7+
- .github/environments.json
78
- .github/protection.json
89
schedule:
910
- cron: "0 0 * * *"
@@ -23,7 +24,9 @@ jobs:
2324

2425
- name: Enable auto-delete head branches
2526
run: |
26-
gh repo edit ${{ github.repository }} --delete-branch-on-merge
27+
gh repo edit ${{ github.repository }} \
28+
--default-branch develop \
29+
--delete-branch-on-merge
2730
env:
2831
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
2932

@@ -40,14 +43,15 @@ jobs:
4043

4144
- name: Set GitHub Pages Source
4245
run: |
43-
gh api -X POST "repos/${{ github.repository }}/pages" \
46+
gh api -X POST ${{ env.ENDPOINT }} \
4447
-f "source[branch]=${{ env.BRANCH }}" \
4548
-f "source[path]=${{ env.TARGET_PATH }}" --silent \
4649
|| \
47-
gh api -X PUT "repos/${{ github.repository }}/pages" \
50+
gh api -X PUT ${{ env.ENDPOINT }} \
4851
-f "source[branch]=${{ env.BRANCH }}" \
4952
-f "source[path]=${{ env.TARGET_PATH }}"
5053
env:
54+
ENDPOINT: repos/${{ github.repository }}/pages
5155
BRANCH: gh-pages
5256
TARGET_PATH: /
5357
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
@@ -68,21 +72,75 @@ jobs:
6872

6973
- name: Apply Branch Protection Rules
7074
run: |
71-
if [ ! -f "$CONFIG_FILE" ]; then
72-
echo "Error: $CONFIG_FILE not found!"
75+
if [ ! -f ${{ env.CONFIG_FILE }} ]; then
76+
echo "Error: ${{ env.CONFIG_FILE }} not found!"
7377
exit 1
7478
fi
7579
76-
BRANCHES=$(jq -r 'keys[]' "$CONFIG_FILE")
80+
BRANCHES=$(jq -r 'keys[]' ${{ env.CONFIG_FILE }})
7781
7882
for BRANCH in $BRANCHES; do
79-
if ! gh api "repos/${{ github.repository }}/branches/$BRANCH" --silent >/dev/null 2>&1; then
80-
echo "Warning: Branch '$BRANCH' does not exist in this repository. Skipping..."
83+
if ! gh api "${{ env.ENDPOINT }}/$BRANCH" --silent >/dev/null 2>&1; then
84+
echo "Warning: Branch $BRANCH does not exist in this repository. Skipping..."
8185
continue
8286
fi
8387
84-
jq -c ".\"$BRANCH\"" "$CONFIG_FILE" | gh api -X PUT "repos/${{ github.repository }}/branches/$BRANCH/protection" --input -
88+
jq -c ".\"$BRANCH\"" ${{ env.CONFIG_FILE }} | gh api -X PUT "${{ env.ENDPOINT }}/$BRANCH/protection" --input -
8589
done
8690
env:
8791
CONFIG_FILE: .github/protection.json
92+
ENDPOINT: repos/${{ github.repository }}/branches
93+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
94+
95+
environments:
96+
runs-on: ubuntu-latest
97+
98+
strategy:
99+
matrix:
100+
include:
101+
- environment: Develop
102+
branch: develop
103+
- environment: Production
104+
branch: main
105+
- environment: github-pages
106+
branch: gh-pages
107+
108+
steps:
109+
- name: Checkout
110+
uses: actions/checkout@v6
111+
112+
- name: Generate a token
113+
id: generate-token
114+
uses: actions/create-github-app-token@v2
115+
with:
116+
app-id: ${{ vars.APP_ID }}
117+
private-key: ${{ secrets.APP_KEY }}
118+
119+
- name: Configure Environment
120+
run: |
121+
if [ ! -f ${{ env.CONFIG_FILE }} ]; then
122+
echo "Error: ${{ env.CONFIG_FILE }} not found!"
123+
exit 1
124+
fi
125+
126+
jq -c ".\"${{ env.ENVIRONMENT_NAME }}\"" ${{ env.CONFIG_FILE }} | gh api -X PUT "${{ env.ENDPOINT }}/${{ env.ENVIRONMENT_NAME }}" --input -
127+
128+
CUSTOM_BRANCH_POLICIES=$(jq -r ".\"${{ env.ENVIRONMENT_NAME }}\".deployment_branch_policy.custom_branch_policies" ${{ env.CONFIG_FILE }})
129+
130+
if [ "$CUSTOM_BRANCH_POLICIES" != true ]; then
131+
IDS=$(gh api "${{ env.ENDPOINT }}/${{ env.ENVIRONMENT_NAME }}/deployment-branch-policies" --jq '.branch_policies[].id' || true)
132+
for ID in $IDS; do
133+
gh api -X DELETE "${{ env.ENDPOINT }}/${{ env.ENVIRONMENT_NAME }}/deployment-branch-policies/$ID" --silent || true
134+
done
135+
exit 0
136+
fi
137+
138+
gh api -X POST "${{ env.ENDPOINT }}/${{ env.ENVIRONMENT_NAME }}/deployment-branch-policies" \
139+
-f "name=${{ env.BRANCH_NAME }}" \
140+
-f "type=branch"
141+
env:
142+
CONFIG_FILE: .github/environments.json
143+
BRANCH_NAME: ${{ matrix.branch }}
144+
ENDPOINT: repos/${{ github.repository }}/environments
145+
ENVIRONMENT_NAME: ${{ matrix.environment }}
88146
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

0 commit comments

Comments
 (0)