Skip to content

Commit 17dd339

Browse files
Update merge-upstream workflow to open a PR for upstream sync (#190)
* Update merge-upstream workflow to open a PR for upstream sync This update opens a PR to merge upstream changes into the elastic otel demo repo. If there are no conflicts, the PR is auto-merged. Otherwise it will need manual resolution. * Set git git config with github details
1 parent a623856 commit 17dd339

File tree

1 file changed

+81
-32
lines changed

1 file changed

+81
-32
lines changed
Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,104 @@
1-
name: Scheduled Merge Upstream
1+
name: Merge Upstream PR
22
on:
33
workflow_dispatch:
44
schedule:
5-
- cron: '23 0/3 * * *'
5+
- cron: '0 9 * * 1,4'
66

77
jobs:
8-
merge_upstream:
8+
create_upstream_pr:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313
with:
1414
ref: main
1515
fetch-depth: 0
1616
token: ${{ secrets.OTEL_DEMO_MERGE_SECRET }}
17-
- name: fetch and push
18-
env:
19-
GITHUB_TOKEN: ${{ github.token }}
20-
UPSTREAM: https://github.com/open-telemetry/opentelemetry-demo
17+
18+
- name: Fetch upstream
2119
run: |
2220
git config --global user.name "github-actions"
2321
git config --global user.email "github-actions@users.noreply.github.com"
22+
git remote add upstream https://github.com/open-telemetry/opentelemetry-demo.git
23+
git fetch upstream main
2424
25-
git remote add upstream "${UPSTREAM}"
25+
- name: Check for upstream changes
26+
id: check
27+
run: |
28+
COMMITS_BEHIND=$(git rev-list --count HEAD..upstream/main)
29+
echo "commits_behind=${COMMITS_BEHIND}" >> $GITHUB_OUTPUT
2630
27-
# Get all recent branches and commits from the upstream
28-
git fetch upstream main
31+
- name: Create branch from upstream
32+
if: steps.check.outputs.commits_behind != '0'
33+
id: branch
34+
run: |
35+
BRANCH_NAME="auto-merge/upstream-$(date +%Y%m%d-%H%M%S)"
36+
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
37+
38+
git checkout -b "${BRANCH_NAME}" upstream/main
39+
git push origin "${BRANCH_NAME}"
2940
30-
git merge upstream/main --no-edit || { echo "Merge conflicts detected. Please resolve them manually."; exit 1; }
41+
- name: Create Pull Request
42+
if: steps.check.outputs.commits_behind != '0'
43+
id: create_pr
44+
env:
45+
GH_TOKEN: ${{ secrets.OTEL_DEMO_MERGE_SECRET }}
46+
run: |
47+
PR_URL=$(gh pr create \
48+
--title "chore: merge with upstream opentelemetry-demo" \
49+
--body "## Automated upstream merge
50+
51+
This PR merges with the upstream opentelemetry-demo repository.
52+
53+
### Changes from upstream
54+
- ${{ steps.check.outputs.commits_behind }} new commits
55+
56+
### If there are conflicts
57+
Check out this branch and resolve them:
58+
\`\`\`bash
59+
git fetch origin ${{ steps.branch.outputs.branch_name }}
60+
git checkout ${{ steps.branch.outputs.branch_name }}
61+
git merge main
62+
# resolve conflicts
63+
git push
64+
\`\`\`
65+
66+
**Note:** If \`src/payment/package.json\` conflicts, take upstream version and add:
67+
\`\`\`json
68+
\"@elastic/opentelemetry-node\": \"1.5.0\"
69+
\`\`\`
70+
And update the start script to:
71+
\`\`\`json
72+
\"start\": \"OTEL_EXPORTER_OTLP_PROTOCOL=grpc node --require @elastic/opentelemetry-node index.js\"
73+
\`\`\`
74+
75+
---
76+
*This PR was automatically created.*" \
77+
--base main \
78+
--head ${{ steps.branch.outputs.branch_name }})
79+
80+
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
81+
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
82+
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
3183
32-
git push origin $(git branch --show-current)
84+
- name: Enable auto-merge
85+
if: steps.create_pr.outputs.pr_number != ''
86+
env:
87+
GH_TOKEN: ${{ secrets.OTEL_DEMO_MERGE_SECRET }}
88+
run: |
89+
gh pr merge ${{ steps.create_pr.outputs.pr_number }} --auto --merge
3390
3491
notify-failure:
35-
needs: [merge_upstream]
36-
if: always() && needs.merge_upstream.result != 'success'
92+
needs: [create_upstream_pr]
93+
if: failure()
3794
runs-on: ubuntu-latest
3895
steps:
39-
- name: Get previous workflow status
40-
uses: Mercymeilya/last-workflow-status@v0.3.3
41-
id: last_status
42-
with:
43-
github_token: ${{ secrets.GITHUB_TOKEN }}
44-
- name: Slack notification
45-
if: success() && steps.last_status.outputs.last_status == 'success'
46-
env:
47-
SLACK_WEBHOOK: ${{ secrets.OTELSLACKCHANNELWEBHOOK }}
48-
SLACK_UNFURL_LINKS: "true"
49-
uses: AlexanderWert/action-slack@2.3.0
50-
with:
51-
args: |
52-
:wave:
53-
Auto-merge of the <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|elastic/opentelemetry-demo> repository with the upstream failed!
54-
Manual resolution of the merge conflicts is required!
55-
96+
- name: Slack notification if any error
97+
uses: elastic/oblt-actions/slack/send@v1
98+
with:
99+
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
100+
channel-id: "C02LJMUSXLH" #otel-data-team
101+
message: |
102+
:warning: Upstream merge workflow failed for `${{ github.repository }}@${{ github.ref_name }}`.
103+
104+
Please check <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|the workflow run>.

0 commit comments

Comments
 (0)