|
1 | | -name: Scheduled Merge Upstream |
| 1 | +name: Merge Upstream PR |
2 | 2 | on: |
3 | 3 | workflow_dispatch: |
4 | 4 | schedule: |
5 | | - - cron: '23 0/3 * * *' |
| 5 | + - cron: '0 9 * * 1,4' |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - merge_upstream: |
| 8 | + create_upstream_pr: |
9 | 9 | runs-on: ubuntu-latest |
10 | 10 | steps: |
11 | 11 | - name: Checkout |
12 | | - uses: actions/checkout@v2 |
| 12 | + uses: actions/checkout@v4 |
13 | 13 | with: |
14 | 14 | ref: main |
15 | 15 | fetch-depth: 0 |
16 | 16 | 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 |
21 | 19 | run: | |
22 | 20 | git config --global user.name "github-actions" |
23 | 21 | 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 |
24 | 24 |
|
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 |
26 | 30 |
|
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}" |
29 | 40 |
|
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 |
31 | 83 |
|
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 |
33 | 90 |
|
34 | 91 | notify-failure: |
35 | | - needs: [merge_upstream] |
36 | | - if: always() && needs.merge_upstream.result != 'success' |
| 92 | + needs: [create_upstream_pr] |
| 93 | + if: failure() |
37 | 94 | runs-on: ubuntu-latest |
38 | 95 | 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