1+ name : Integrate Develop to Staging
2+
3+ on :
4+ push :
5+ branches :
6+ - develop
7+
8+ concurrency :
9+ group : ${{ github.workflow }}-${{ github.ref }}
10+ cancel-in-progress : true
11+
12+ jobs :
13+ create-or-update-pr :
14+ name : Create or Update PR to Staging
15+ runs-on : ubuntu-latest
16+ permissions :
17+ contents : write
18+ pull-requests : write
19+ steps :
20+ - name : Checkout
21+ uses : actions/checkout@v4
22+ with :
23+ fetch-depth : 0
24+
25+ - name : Setup Node.js
26+ uses : actions/setup-node@v4
27+ with :
28+ node-version : ' 22.10.0'
29+
30+ - name : Check for existing PR
31+ id : check-pr
32+ run : |
33+ EXISTING_PR=$(gh pr list --base staging --head develop --json number --jq '.[0].number' || echo "")
34+
35+ if [ -n "$EXISTING_PR" ]; then
36+ echo "pr_exists=true" >> $GITHUB_OUTPUT
37+ echo "pr_number=$EXISTING_PR" >> $GITHUB_OUTPUT
38+ echo "Found existing PR #$EXISTING_PR"
39+ else
40+ echo "pr_exists=false" >> $GITHUB_OUTPUT
41+ echo "No existing PR found"
42+ fi
43+ env :
44+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
45+
46+ - name : Get commit information
47+ id : commit-info
48+ run : |
49+ # Fetch staging branch
50+ git fetch origin staging:staging || echo "Staging branch not found"
51+
52+ # Get the latest commits from develop that aren't in staging
53+ if git rev-parse --verify origin/staging >/dev/null 2>&1; then
54+ COMMITS=$(git log --pretty=format:"- %s (%h)" origin/staging..HEAD | head -20)
55+ COMMIT_COUNT=$(git rev-list --count origin/staging..HEAD)
56+ else
57+ COMMITS=$(git log --pretty=format:"- %s (%h)" HEAD | head -20)
58+ COMMIT_COUNT=$(git rev-list --count HEAD)
59+ fi
60+
61+ # Escape for GitHub Actions output
62+ COMMITS="${COMMITS//'%'/'%25'}"
63+ COMMITS="${COMMITS//$'\n'/'%0A'}"
64+ COMMITS="${COMMITS//$'\r'/'%0D'}"
65+
66+ echo "commits<<EOF" >> $GITHUB_OUTPUT
67+ echo "$COMMITS" >> $GITHUB_OUTPUT
68+ echo "EOF" >> $GITHUB_OUTPUT
69+ echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
70+
71+ # Get timestamp
72+ TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
73+ echo "timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
74+
75+ - name : Create PR to staging
76+ if : steps.check-pr.outputs.pr_exists == 'false'
77+ run : |
78+ COMMIT_COUNT="${{ steps.commit-info.outputs.commit_count }}"
79+ TIMESTAMP="${{ steps.commit-info.outputs.timestamp }}"
80+
81+ # Create PR body file
82+ {
83+ echo "## π Integration from develop to staging"
84+ echo ""
85+ echo "### π Summary"
86+ echo "- **Commits**: ${COMMIT_COUNT} new commits"
87+ echo "- **Created**: ${TIMESTAMP}"
88+ echo "- **Auto-generated**: This PR was automatically created by the integration workflow"
89+ echo ""
90+ echo "### π Recent Commits"
91+ echo "${{ steps.commit-info.outputs.commits }}"
92+ echo ""
93+ echo "### π What happens next?"
94+ echo "1. Review the changes in this PR"
95+ echo "2. Run any necessary QA tests"
96+ echo "3. When approved and merged, the staging workflow will:"
97+ echo " - Check for changesets"
98+ echo " - If found, create beta releases"
99+ echo " - Automatically create a PR to main"
100+ echo ""
101+ echo "### β‘ Notes"
102+ echo "- This PR will be automatically updated with new commits to develop"
103+ echo "- Multiple features can accumulate in this single PR"
104+ echo "- Approval triggers the beta release process"
105+ } > pr-body.md
106+
107+ gh pr create \
108+ --base staging \
109+ --head develop \
110+ --title "π Integrate develop β staging" \
111+ --body-file pr-body.md \
112+ --label "auto-updated"
113+ env :
114+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
115+
116+ - name : Update existing PR
117+ if : steps.check-pr.outputs.pr_exists == 'true'
118+ run : |
119+ PR_NUMBER="${{ steps.check-pr.outputs.pr_number }}"
120+ COMMIT_COUNT="${{ steps.commit-info.outputs.commit_count }}"
121+ TIMESTAMP="${{ steps.commit-info.outputs.timestamp }}"
122+ COMMITS="${{ steps.commit-info.outputs.commits }}"
123+
124+ # Update PR title with commit count
125+ gh pr edit $PR_NUMBER \
126+ --title "π Integrate develop β staging (${COMMIT_COUNT} commits)"
127+
128+ # Get current PR body
129+ CURRENT_BODY=$(gh pr view $PR_NUMBER --json body --jq '.body')
130+
131+ # Create updated section
132+ UPDATED_SECTION="### π Last Updated: ${TIMESTAMP}\nNew commits: ${COMMIT_COUNT}\n\n### π Recent Commits\n${COMMITS}"
133+
134+ # Update or append the updated section
135+ if echo "$CURRENT_BODY" | grep -q "### π Last Updated:"; then
136+ # Replace existing update section
137+ NEW_BODY=$(echo "$CURRENT_BODY" | sed '/### π Last Updated:/,/### π Recent Commits/d' | sed '/^$/d')
138+ NEW_BODY="$NEW_BODY\n\n$UPDATED_SECTION"
139+ else
140+ # Append update section
141+ NEW_BODY="$CURRENT_BODY\n\n---\n\n$UPDATED_SECTION"
142+ fi
143+
144+ # Update PR body
145+ echo "$NEW_BODY" > pr-body-update.md
146+ gh pr edit $PR_NUMBER --body-file pr-body-update.md
147+
148+ # Add labels
149+ gh pr edit $PR_NUMBER \
150+ --add-label "needs-review"
151+
152+ # Set as ready for review
153+ gh pr ready $PR_NUMBER || true
154+
155+ echo "β
Updated PR #${PR_NUMBER} with ${COMMIT_COUNT} new commits"
156+ env :
157+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments