44 branches :
55 - dev
66 - master
7+ - rc
78 pull_request :
9+ workflow_dispatch :
810
911jobs :
10- dev-to-master -pr :
11- name : Create or Update PR from Dev to Master
12+ dev-to-rc -pr :
13+ name : Create PR from Dev to RC
1214 if : github.ref == 'refs/heads/dev' && github.repository == 'HyDE-Project/HyDE'
1315 runs-on : ubuntu-latest
16+ steps :
17+ - uses : actions/checkout@v4
18+ with :
19+ fetch-depth : 0
20+
21+ # Generate commit history and calculate suggested merge date
22+ - name : Generate commit history and schedule
23+ id : generate-commits
24+ run : |
25+ chmod +x .github/scripts/promote_to_rc.sh
26+ bash .github/scripts/promote_to_rc.sh
27+
28+ # Check if there are any commits between rc and dev
29+ - name : Check for commits between branches
30+ id : check-commits
31+ run : |
32+ # Fetch rc branch to make sure it exists locally
33+ git fetch origin rc:rc || true
34+
35+ # We're already on dev branch since the job runs when dev is pushed
36+ # Compare dev to rc to see if there are any differences
37+ if git rev-parse --verify rc >/dev/null 2>&1; then
38+ COMMIT_COUNT=$(git rev-list --count rc..dev)
39+ echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
40+ if [ "$COMMIT_COUNT" -gt 0 ]; then
41+ echo "Detected $COMMIT_COUNT commit(s) between rc and dev"
42+ echo "has_commits=true" >> $GITHUB_OUTPUT
43+ else
44+ echo "No commits detected between rc and dev"
45+ echo "has_commits=false" >> $GITHUB_OUTPUT
46+ fi
47+ else
48+ echo "RC branch doesn't exist yet. Assuming changes need to be propagated."
49+ echo "commit_count=999" >> $GITHUB_OUTPUT # Use a high number to indicate there are changes
50+ echo "has_commits=true" >> $GITHUB_OUTPUT
51+ fi
52+
53+ # Set up git for potential operations
54+ - name : Setup git
55+ if : steps.check-commits.outputs.has_commits == 'true'
56+ run : |
57+ git config user.name "GitHub Actions Bot"
58+ git config user.email "[email protected] " 59+
60+ # Create or update PR using GitHub API with retry logic
61+ - name : Create or Update Pull Request
62+ if : steps.check-commits.outputs.has_commits == 'true'
63+ uses : actions/github-script@v6
64+ with :
65+ github-token : ${{ secrets.GITHUB_TOKEN }}
66+ script : |
67+ const { repo, owner } = context.repo;
68+ const prBranch = "dev";
69+ const prTitle = "chore: Release - dev → rc";
70+ const prBody = process.env.PR_BODY;
71+
72+ // Retry helper function
73+ async function retryOperation(operation, maxRetries = 3, delay = 5000) {
74+ let lastError;
75+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
76+ try {
77+ return await operation();
78+ } catch (error) {
79+ lastError = error;
80+ console.log(`Attempt ${attempt}/${maxRetries} failed: ${error.message}`);
81+ if (attempt < maxRetries) {
82+ console.log(`Waiting ${delay/1000} seconds before retry...`);
83+ await new Promise(resolve => setTimeout(resolve, delay));
84+ }
85+ }
86+ }
87+ throw lastError;
88+ }
89+
90+ // Check if PR already exists
91+ const prs = await retryOperation(async () => {
92+ return github.rest.pulls.list({
93+ owner,
94+ repo,
95+ head: `${owner}:${prBranch}`,
96+ base: 'rc',
97+ state: 'open'
98+ });
99+ });
100+
101+ if (prs.data.length > 0) {
102+ // Update existing PR
103+ console.log(`Updating existing PR #${prs.data[0].number}`);
104+ await retryOperation(async () => {
105+ return github.rest.pulls.update({
106+ owner,
107+ repo,
108+ pull_number: prs.data[0].number,
109+ title: prTitle,
110+ body: prBody
111+ });
112+ });
113+ console.log(`PR #${prs.data[0].number} updated successfully.`);
114+ } else {
115+ // Create new PR
116+ try {
117+ const result = await retryOperation(async () => {
118+ return github.rest.pulls.create({
119+ owner,
120+ repo,
121+ title: prTitle,
122+ body: prBody,
123+ head: prBranch,
124+ base: 'rc'
125+ });
126+ });
127+ console.log(`PR created: ${result.data.html_url}`);
128+ } catch (error) {
129+ console.log(`All attempts to create PR failed: ${error.message}`);
130+ // As a fallback, output command for manual PR creation
131+ console.log(`To create the PR manually, visit: https://github.com/${owner}/${repo}/compare/rc...${prBranch}`);
132+ throw error;
133+ }
134+ }
135+
136+ # Output message when no commits are found
137+ - name : No Commits Message
138+ if : steps.check-commits.outputs.has_commits == 'false'
139+ run : |
140+ echo "::notice::No new commits detected between rc and dev branches. Skipping PR creation."
141+ echo "The branches rc and dev are already in sync."
142+
143+ rc-to-master-pr :
144+ name : Create PR from RC to Master
145+ if : github.ref == 'refs/heads/rc' && github.repository == 'HyDE-Project/HyDE'
146+ runs-on : ubuntu-latest
14147 steps :
15148 - uses : actions/checkout@v4
16149 with :
@@ -23,23 +156,23 @@ jobs:
23156 chmod +x .github/scripts/promote_to_master.sh
24157 bash .github/scripts/promote_to_master.sh
25158
26- # Check if there are any commits between master and dev
159+ # Check if there are any commits between master and rc
27160 - name : Check for commits between branches
28161 id : check-commits
29162 run : |
30163 # Fetch master branch to make sure it exists locally
31164 git fetch origin master:master || true
32165
33- # We're already on dev branch since the job runs when dev is pushed
34- # Compare dev to master to see if there are any differences
166+ # We're already on rc branch since the job runs when rc is pushed
167+ # Compare rc to master to see if there are any differences
35168 if git rev-parse --verify master >/dev/null 2>&1; then
36- COMMIT_COUNT=$(git rev-list --count master..dev )
169+ COMMIT_COUNT=$(git rev-list --count master..rc )
37170 echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
38171 if [ "$COMMIT_COUNT" -gt 0 ]; then
39- echo "Detected $COMMIT_COUNT commit(s) between master and dev "
172+ echo "Detected $COMMIT_COUNT commit(s) between master and rc "
40173 echo "has_commits=true" >> $GITHUB_OUTPUT
41174 else
42- echo "No commits detected between master and dev "
175+ echo "No commits detected between master and rc "
43176 echo "has_commits=false" >> $GITHUB_OUTPUT
44177 fi
45178 else
63196 github-token : ${{ secrets.GITHUB_TOKEN }}
64197 script : |
65198 const { repo, owner } = context.repo;
66- const prBranch = "dev ";
67- const prTitle = "chore: release automated changes from dev to master";
199+ const prBranch = "rc ";
200+ const prTitle = "chore: Release - rc → master";
68201 const prBody = process.env.PR_BODY;
69202
70203 // Retry helper function
@@ -125,7 +258,6 @@ jobs:
125258 console.log(`PR created: ${result.data.html_url}`);
126259 } catch (error) {
127260 console.log(`All attempts to create PR failed: ${error.message}`);
128-
129261 // As a fallback, output command for manual PR creation
130262 console.log(`To create the PR manually, visit: https://github.com/${owner}/${repo}/compare/master...${prBranch}`);
131263 throw error;
@@ -136,11 +268,11 @@ jobs:
136268 - name : No Commits Message
137269 if : steps.check-commits.outputs.has_commits == 'false'
138270 run : |
139- echo "::notice::No new commits detected between master and dev branches. Skipping PR creation."
140- echo "The branches master and dev are already in sync."
271+ echo "::notice::No new commits detected between master and rc branches. Skipping PR creation."
272+ echo "The branches master and rc are already in sync."
141273
142274 release :
143- name : release
275+ name : Quarterly Snapshot Release
144276 if : github.ref == 'refs/heads/master' && github.repository == 'HyDE-Project/HyDE'
145277 runs-on : ubuntu-latest
146278 steps :
0 commit comments