-
Notifications
You must be signed in to change notification settings - Fork 2
ci: open dev-to-main PR instead of pushing protected main #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ on: | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: write | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull-requests: write | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| release: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,15 +57,42 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GITHUB_TOKEN: ${{ github.token }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Merge dev -> main | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git status | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git pull | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git fetch | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git checkout main | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git rebase dev | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git push origin main | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| git status | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Create or reuse PR from dev to main | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| github-token: ${{ github.token }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const owner = context.repo.owner | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const repo = context.repo.repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const head = 'dev' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const base = 'main' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const title = 'chore: merge dev into main after earn release' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = 'Automated PR opened by release-earn-apps workflow.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: prs } = await github.rest.pulls.list({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: 'open', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| head: `${owner}:${head}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| base, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| per_page: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (prs.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| core.info(`PR already open: #${prs[0].number} ${prs[0].html_url}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: pr } = await github.rest.pulls.create({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| head, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| base, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| title, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "release-earn-apps.yaml" -type fRepository: OasisDEX/summerfi-monorepo Length of output: 112 🏁 Script executed: cat -n .github/workflows/release-earn-apps.yaml | sed -n '70,110p'Repository: OasisDEX/summerfi-monorepo Length of output: 1610 🏁 Script executed: cat -n .github/workflows/release-earn-apps.yamlRepository: OasisDEX/summerfi-monorepo Length of output: 4721 🌐 Web query:
💡 Result: When you call GitHub’s REST API does not provide an “idempotent create PR” option (i.e., you can’t ask it to return 201/OK if the PR already exists); you need to handle it in your client by detecting the existing PR and treating that case as success [2]. Practical fix (recommended pattern)
This avoids relying on parsing the 422 message, and prevents repeated create attempts that will always fail once a PR exists. [1] 🌐 Web query:
💡 Result: For Common 422 causes for creating a pull request:
How to quickly pinpoint which one you hit:
Citations:
Handle concurrent PR creation to prevent 422 errors. The list check at lines 72-84 doesn't prevent the race condition when two workflow runs execute concurrently and both pass the check before either creates the PR. Add try-catch on 422 to handle idempotently. Suggested fix- const { data: pr } = await github.rest.pulls.create({
- owner,
- repo,
- head,
- base,
- title,
- body,
- })
-
- core.info(`Created PR: #${pr.number} ${pr.html_url}`)
+ try {
+ const { data: pr } = await github.rest.pulls.create({
+ owner,
+ repo,
+ head,
+ base,
+ title,
+ body,
+ })
+ core.info(`Created PR: #${pr.number} ${pr.html_url}`)
+ } catch (error) {
+ if (error.status === 422) {
+ core.info('PR already exists; skipping.')
+ return
+ }
+ throw error
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| core.info(`Created PR: #${pr.number} ${pr.html_url}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Generate GitHub App token for e2e-tests | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: e2e_tests_app_token | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OasisDEX/summerfi-monorepo
Length of output: 4721
Checkout must pin to dev or workflow dispatch branch mismatch can cause wrong release.
Workflow can be dispatched from any branch but checkout is not pinned. Line 67 hardcodes
head = 'dev'for PR creation, so releasing frommainchecks outmain, tagsmain, but tries to open PR fromdev → main.Add
ref: devto checkout step.🤖 Prompt for AI Agents