Skip to content

Commit 0f748bf

Browse files
committed
♻️ Extract the entire complete workflow about run staging release processes as a single reusable workflow to centralized manage.
1 parent 1fe1f9d commit 0f748bf

File tree

2 files changed

+228
-135
lines changed

2 files changed

+228
-135
lines changed
Lines changed: 28 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Staging Release
2+
# This workflow calls the centralized staging release process from the template project
23

34
on:
45
workflow_dispatch:
@@ -23,162 +24,54 @@ concurrency:
2324
cancel-in-progress: false
2425

2526
jobs:
26-
# Parse project configuration from intent.yaml
27-
config:
28-
name: Parse Configuration
29-
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_parse_project_config.yaml@master
30-
31-
compute-version:
32-
name: Compute Staging Version
33-
runs-on: ubuntu-latest
34-
needs: config
35-
outputs:
36-
version: ${{ steps.version.outputs.version }}
37-
rc_version: ${{ steps.version.outputs.rc_version }}
38-
steps:
39-
- name: Checkout repository
40-
uses: actions/checkout@v5
41-
with:
42-
fetch-depth: 0
43-
# Only use ref for push events to master to get latest commit after version bump
44-
# In PR events, github.ref_name gives merge refs like "109/merge" which breaks checkout
45-
ref: ${{ github.event_name == 'push' && github.ref_name == 'master' && github.ref_name || '' }}
46-
47-
- name: Setup Python with UV
48-
uses: Chisanan232/Template-Python-UV-Project/.github/actions/setup-python-uv@master
49-
with:
50-
install-dependencies: 'true'
51-
dependency-groups: 'release-ci'
52-
53-
- name: Compute staging version
54-
id: version
55-
run: |
56-
case "${{ inputs.level }}" in
57-
"patch")
58-
BUMP_FLAG="--bump patch"
59-
;;
60-
"minor")
61-
BUMP_FLAG="--bump minor"
62-
;;
63-
"major")
64-
BUMP_FLAG="--bump major"
65-
;;
66-
*)
67-
BUMP_FLAG="--bump patch"
68-
;;
69-
esac
70-
71-
echo "Computing staging version with: uv version --dry-run $BUMP_FLAG"
72-
BASE_VERSION=$(uv version --short --dry-run $BUMP_FLAG)
73-
RC_VERSION="${BASE_VERSION}-rc.0"
74-
75-
echo "version=$BASE_VERSION" >> $GITHUB_OUTPUT
76-
echo "rc_version=$RC_VERSION" >> $GITHUB_OUTPUT
77-
78-
echo "Base version: $BASE_VERSION"
79-
echo "RC version: $RC_VERSION"
80-
81-
build_git-tag_and_create_github-release:
82-
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_build_git-tag_and_create_github-release_v2.yaml@master
83-
needs: [config, compute-version]
27+
# Call the centralized complete staging release workflow
28+
staging:
29+
name: Complete Staging Release Process
30+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_release_staging_complete.yaml@master
8431
with:
85-
version: ${{ needs.compute-version.outputs.rc_version }}
86-
checkout-sha: ${{ github.sha }}
87-
debug_mode: true
32+
level: ${{ inputs.level }}
8833
secrets:
89-
github_auth_token: ${{ secrets.GITHUB_TOKEN }}
90-
91-
pypi-test:
92-
uses: ./.github/workflows/rw_python_package.yaml
93-
needs: [config, compute-version, build_git-tag_and_create_github-release]
94-
with:
95-
operation: 'publish-testpypi'
96-
version: ${{ needs.compute-version.outputs.version }}
97-
checkout-sha: ${{ github.sha }}
98-
artifact-name: 'staging-python-package'
99-
100-
dockerhub-rc:
101-
name: Staging Release to DockerHub
102-
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docker_operations.yaml@master
103-
needs: [config, compute-version, build_git-tag_and_create_github-release]
104-
secrets:
105-
dockerhub-user: ${{ secrets.DOCKERHUB_USERNAME }}
106-
registry-token: ${{ secrets.DOCKERHUB_TOKEN }}
107-
with:
108-
operation: 'push'
109-
registry: ${{ needs.config.outputs.docker_registry_dockerhub }}
110-
version: ${{ needs.compute-version.outputs.rc_version }}
111-
checkout-sha: ${{ github.sha }}
112-
enable-sbom: true
113-
enable-signing: true
114-
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
115-
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
116-
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
117-
118-
ghcr-rc:
119-
name: Staging Release to GHCR
120-
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docker_operations.yaml@master
121-
needs: [config, compute-version, build_git-tag_and_create_github-release]
122-
with:
123-
operation: 'push'
124-
registry: ${{ needs.config.outputs.docker_registry_ghcr }}
125-
version: ${{ needs.compute-version.outputs.rc_version }}
126-
checkout-sha: ${{ github.sha }}
127-
enable-sbom: true
128-
enable-signing: true
129-
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
130-
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
131-
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
132-
133-
docs-preview:
134-
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docs_operations.yaml@master
135-
needs: [config, compute-version]
136-
with:
137-
operation: 'deploy-preview'
138-
version: ${{ needs.compute-version.outputs.rc_version }}
139-
checkout-sha: ${{ github.sha }}
140-
preview-branch: ${{ needs.config.outputs.docs_preview_branch }}
141-
upload-artifacts: true
34+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
35+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
14236

37+
# Summary job to report results
14338
staging-summary:
14439
name: Staging Release Summary
14540
runs-on: ubuntu-latest
146-
needs: [config, compute-version, pypi-test, ghcr-rc, docs-preview]
41+
needs: staging
14742
if: always()
14843
steps:
149-
- name: Generate staging release summary
44+
- name: Report staging results
15045
run: |
15146
echo "=== Staging Release Summary ==="
15247
echo ""
153-
echo "Version Computation: ${{ needs.compute-version.result }}"
154-
echo "TestPyPI Upload: ${{ needs.pypi-test.result }}"
155-
echo "GHCR RC Image: ${{ needs.ghcr-rc.result }}"
156-
echo "Docs Preview: ${{ needs.docs-preview.result }}"
157-
echo ""
158-
echo "📦 Staging Artifacts:"
159-
echo "- Base Version: ${{ needs.compute-version.outputs.version }}"
160-
echo "- RC Version: ${{ needs.compute-version.outputs.rc_version }}"
161-
echo "- TestPyPI: https://test.pypi.org/project/${{ needs.config.outputs.project_name }}/${{ needs.compute-version.outputs.version }}/"
162-
echo "- GHCR RC Image: ghcr.io/${{ github.repository }}:${{ needs.compute-version.outputs.rc_version }}"
163-
echo "- Docs Preview: docs-preview branch"
48+
echo "Staging Status: ${{ needs.staging.result }}"
49+
echo "Base Version: ${{ needs.staging.outputs.version }}"
50+
echo "RC Version: ${{ needs.staging.outputs.rc_version }}"
51+
echo "Staging Completed: ${{ needs.staging.outputs.staging_completed }}"
16452
echo ""
16553
166-
if [[ "${{ needs.compute-version.result }}" == "success" && \
167-
"${{ needs.pypi-test.result }}" == "success" && \
168-
"${{ needs.ghcr-rc.result }}" == "success" && \
169-
"${{ needs.docs-preview.result }}" == "success" ]]; then
170-
echo "✅ Staging release completed successfully!"
54+
if [[ "${{ needs.staging.result }}" == "success" && "${{ needs.staging.outputs.staging_completed }}" == "true" ]]; then
55+
echo "🎉 Staging release completed successfully!"
56+
echo ""
57+
echo "📦 Staging Artifacts:"
58+
echo "- Base Version: ${{ needs.staging.outputs.version }}"
59+
echo "- RC Version: ${{ needs.staging.outputs.rc_version }}"
60+
echo "- TestPyPI: https://test.pypi.org/project/${{ github.repository_owner }}/${{ needs.staging.outputs.version }}/"
61+
echo "- GHCR RC Image: ghcr.io/${{ github.repository }}:${{ needs.staging.outputs.rc_version }}"
62+
echo "- DockerHub RC Image: docker.io/${{ github.repository }}:${{ needs.staging.outputs.rc_version }}"
63+
echo "- Docs Preview: docs-preview branch"
17164
echo ""
17265
echo "🧪 Testing Instructions:"
17366
echo "1. Install from TestPyPI:"
174-
echo " pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ${{ needs.config.outputs.project_name }}==${{ needs.compute-version.outputs.version }}"
67+
echo " pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ${{ github.repository_owner }}==${{ needs.staging.outputs.version }}"
17568
echo ""
17669
echo "2. Test RC Docker image:"
177-
echo " docker run -p ${{ needs.config.outputs.docker_health_check_port }}:${{ needs.config.outputs.docker_health_check_port }} -e ${{ needs.config.outputs.docker_app_env_var_name }}=${{ needs.config.outputs.docker_app_env_var_value }} ghcr.io/${{ github.repository }}:${{ needs.compute-version.outputs.rc_version }}"
70+
echo " docker run -p 8000:8000 ghcr.io/${{ github.repository }}:${{ needs.staging.outputs.rc_version }}"
17871
echo ""
17972
echo "3. Review documentation preview in docs-preview branch"
18073
echo ""
18174
else
182-
echo "❌ Some staging deployment steps failed. Check the logs above."
75+
echo "❌ Staging process failed. Check the workflow logs above."
18376
exit 1
18477
fi
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Centralized Complete Staging Release Workflow
2+
# This reusable workflow contains all the logic for the staging release process
3+
name: Complete Staging Release Process
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
level:
9+
description: 'Release level for staging (patch, minor, major)'
10+
required: false
11+
default: 'patch'
12+
type: string
13+
secrets:
14+
DOCKERHUB_USERNAME:
15+
description: 'Docker Hub username'
16+
required: false
17+
DOCKERHUB_TOKEN:
18+
description: 'Docker Hub token'
19+
required: false
20+
outputs:
21+
version:
22+
description: 'Base version for staging'
23+
value: ${{ jobs.compute-version.outputs.version }}
24+
rc_version:
25+
description: 'RC version for staging'
26+
value: ${{ jobs.compute-version.outputs.rc_version }}
27+
staging_completed:
28+
description: 'Whether staging was completed successfully'
29+
value: ${{ jobs.staging-summary.outputs.success }}
30+
31+
permissions:
32+
contents: write
33+
packages: write
34+
id-token: write
35+
36+
jobs:
37+
# Parse project configuration from intent.yaml
38+
config:
39+
name: Parse Configuration
40+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_parse_project_config.yaml@master
41+
42+
compute-version:
43+
name: Compute Staging Version
44+
runs-on: ubuntu-latest
45+
needs: config
46+
outputs:
47+
version: ${{ steps.version.outputs.version }}
48+
rc_version: ${{ steps.version.outputs.rc_version }}
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v5
52+
with:
53+
fetch-depth: 0
54+
# Only use ref for push events to master to get latest commit after version bump
55+
# In PR events, github.ref_name gives merge refs like "109/merge" which breaks checkout
56+
ref: ${{ github.event_name == 'push' && github.ref_name == 'master' && github.ref_name || '' }}
57+
58+
- name: Setup Python with UV
59+
uses: Chisanan232/Template-Python-UV-Project/.github/actions/setup-python-uv@master
60+
with:
61+
install-dependencies: 'true'
62+
dependency-groups: 'release-ci'
63+
64+
- name: Compute staging version
65+
id: version
66+
run: |
67+
case "${{ inputs.level }}" in
68+
"patch")
69+
BUMP_FLAG="--bump patch"
70+
;;
71+
"minor")
72+
BUMP_FLAG="--bump minor"
73+
;;
74+
"major")
75+
BUMP_FLAG="--bump major"
76+
;;
77+
*)
78+
BUMP_FLAG="--bump patch"
79+
;;
80+
esac
81+
82+
echo "Computing staging version with: uv version --dry-run $BUMP_FLAG"
83+
BASE_VERSION=$(uv version --short --dry-run $BUMP_FLAG)
84+
RC_VERSION="${BASE_VERSION}-rc.0"
85+
86+
echo "version=$BASE_VERSION" >> $GITHUB_OUTPUT
87+
echo "rc_version=$RC_VERSION" >> $GITHUB_OUTPUT
88+
89+
echo "Base version: $BASE_VERSION"
90+
echo "RC version: $RC_VERSION"
91+
92+
build_git-tag_and_create_github-release:
93+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_build_git-tag_and_create_github-release_v2.yaml@master
94+
needs: [config, compute-version]
95+
with:
96+
version: ${{ needs.compute-version.outputs.rc_version }}
97+
checkout-sha: ${{ github.sha }}
98+
debug_mode: true
99+
secrets:
100+
github_auth_token: ${{ secrets.GITHUB_TOKEN }}
101+
102+
pypi-test:
103+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_python_package.yaml@master
104+
needs: [config, compute-version, build_git-tag_and_create_github-release]
105+
with:
106+
operation: 'publish-testpypi'
107+
version: ${{ needs.compute-version.outputs.version }}
108+
checkout-sha: ${{ github.sha }}
109+
artifact-name: 'staging-python-package'
110+
111+
dockerhub-rc:
112+
name: Staging Release to DockerHub
113+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docker_operations.yaml@master
114+
needs: [config, compute-version, build_git-tag_and_create_github-release]
115+
secrets:
116+
dockerhub-user: ${{ secrets.DOCKERHUB_USERNAME }}
117+
registry-token: ${{ secrets.DOCKERHUB_TOKEN }}
118+
with:
119+
operation: 'push'
120+
registry: ${{ needs.config.outputs.docker_registry_dockerhub }}
121+
version: ${{ needs.compute-version.outputs.rc_version }}
122+
checkout-sha: ${{ github.sha }}
123+
enable-sbom: true
124+
enable-signing: true
125+
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
126+
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
127+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
128+
129+
ghcr-rc:
130+
name: Staging Release to GHCR
131+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docker_operations.yaml@master
132+
needs: [config, compute-version, build_git-tag_and_create_github-release]
133+
with:
134+
operation: 'push'
135+
registry: ${{ needs.config.outputs.docker_registry_ghcr }}
136+
version: ${{ needs.compute-version.outputs.rc_version }}
137+
checkout-sha: ${{ github.sha }}
138+
enable-sbom: true
139+
enable-signing: true
140+
health-check-port: ${{ needs.config.outputs.docker_health_check_port }}
141+
health-check-path: ${{ needs.config.outputs.docker_health_check_path }}
142+
docker-run-options: ${{ needs.config.outputs.docker_run_options }}
143+
144+
docs-preview:
145+
uses: Chisanan232/Template-Python-UV-Project/.github/workflows/rw_docs_operations.yaml@master
146+
needs: [config, compute-version]
147+
with:
148+
operation: 'deploy-preview'
149+
version: ${{ needs.compute-version.outputs.rc_version }}
150+
checkout-sha: ${{ github.sha }}
151+
preview-branch: ${{ needs.config.outputs.docs_preview_branch }}
152+
upload-artifacts: true
153+
154+
staging-summary:
155+
name: Staging Release Summary
156+
runs-on: ubuntu-latest
157+
needs: [config, compute-version, pypi-test, ghcr-rc, docs-preview]
158+
if: always()
159+
outputs:
160+
success: ${{ steps.summary.outputs.success }}
161+
steps:
162+
- name: Generate staging release summary
163+
id: summary
164+
run: |
165+
echo "=== Staging Release Summary ==="
166+
echo ""
167+
echo "Version Computation: ${{ needs.compute-version.result }}"
168+
echo "TestPyPI Upload: ${{ needs.pypi-test.result }}"
169+
echo "GHCR RC Image: ${{ needs.ghcr-rc.result }}"
170+
echo "Docs Preview: ${{ needs.docs-preview.result }}"
171+
echo ""
172+
echo "📦 Staging Artifacts:"
173+
echo "- Base Version: ${{ needs.compute-version.outputs.version }}"
174+
echo "- RC Version: ${{ needs.compute-version.outputs.rc_version }}"
175+
echo "- TestPyPI: https://test.pypi.org/project/${{ needs.config.outputs.project_name }}/${{ needs.compute-version.outputs.version }}/"
176+
echo "- GHCR RC Image: ghcr.io/${{ github.repository }}:${{ needs.compute-version.outputs.rc_version }}"
177+
echo "- Docs Preview: docs-preview branch"
178+
echo ""
179+
180+
if [[ "${{ needs.compute-version.result }}" == "success" && \
181+
"${{ needs.pypi-test.result }}" == "success" && \
182+
"${{ needs.ghcr-rc.result }}" == "success" && \
183+
"${{ needs.docs-preview.result }}" == "success" ]]; then
184+
echo "✅ Staging release completed successfully!"
185+
echo "success=true" >> $GITHUB_OUTPUT
186+
echo ""
187+
echo "🧪 Testing Instructions:"
188+
echo "1. Install from TestPyPI:"
189+
echo " pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ${{ needs.config.outputs.project_name }}==${{ needs.compute-version.outputs.version }}"
190+
echo ""
191+
echo "2. Test RC Docker image:"
192+
echo " docker run -p ${{ needs.config.outputs.docker_health_check_port }}:${{ needs.config.outputs.docker_health_check_port }} ${{ needs.config.outputs.docker_run_options }} ghcr.io/${{ github.repository }}:${{ needs.compute-version.outputs.rc_version }}"
193+
echo ""
194+
echo "3. Review documentation preview in docs-preview branch"
195+
echo ""
196+
else
197+
echo "❌ Some staging deployment steps failed. Check the logs above."
198+
echo "success=false" >> $GITHUB_OUTPUT
199+
exit 1
200+
fi

0 commit comments

Comments
 (0)