Skip to content

Commit 8ad9144

Browse files
committed
Add github action to rebase datadog branch on upstream (#18)
1 parent e350531 commit 8ad9144

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Prepare rebase on upstream
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
prepare:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
pull-requests: write
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
ssh-key: ${{ secrets.DEPLOY_KEY }}
16+
17+
- name: Set up Git
18+
run: |
19+
git config user.name "github-actions[bot]"
20+
git config user.email "github-actions[bot]@users.noreply.github.com"
21+
22+
# Do not use `gh repo sync` with GITHUB_TOKEN, it will fail with 422:
23+
# {"message":"Repository rule violations found","documentation_url":"https://docs.github.com/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository","status":"422"}
24+
- name: Sync main with upstream
25+
run: |
26+
git switch main
27+
git remote add upstream [email protected]:open-telemetry/opentelemetry-ebpf-profiler.git
28+
git fetch upstream
29+
git merge --ff upstream/main
30+
git push origin
31+
32+
- name: Checkout datadog branch
33+
run: |
34+
git switch datadog
35+
git pull
36+
37+
- name: Rebase datadog on main
38+
run: |
39+
git switch -c rebase-on-upstream
40+
git rebase origin/main
41+
git push origin rebase-on-upstream
42+
43+
- name: Create PR
44+
run: |
45+
gh pr create -R ${{ github.repository }} --base main --head rebase-on-upstream --title "Rebase datadog on upstream/main" --body "This PR is to rebase datadog branch on main branch"
46+
env:
47+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Add comment
50+
run: |
51+
gh pr comment rebase-on-upstream -R ${{ github.repository }} --body "Please close and re-open this PR to trigger the tests."
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Rebase on upstream
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
check:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
pull-requests: write
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
ssh-key: ${{ secrets.DEPLOY_KEY }}
17+
18+
- name: Set up Git
19+
run: |
20+
git config user.name "github-actions[bot]"
21+
git config user.email "github-actions[bot]@users.noreply.github.com"
22+
23+
- name: Check PR
24+
id: check_pr
25+
run: |
26+
# Check that ${{ github.ref_name }} has main as ancestor (ie. fast forward merge is possible)
27+
if ! git merge-base --is-ancestor origin/main ${{ github.ref_name }}; then
28+
echo "${{ github.ref_name }} does not have main as ancestor"
29+
exit 1
30+
fi
31+
32+
gh pr list --state open --head ${{ github.ref_name }} --base main --json number,reviewDecision,state,isDraft,mergeable,statusCheckRollup > pr.json
33+
# Check that there is a single PR with main as base branch and ${{ github.ref_name }} as head branch
34+
if [[ "$(jq length pr.json)" -eq 0 ]]; then
35+
echo "No PR with main as base branch and ${{ github.ref_name }} as head branch"
36+
exit 1
37+
fi
38+
# No need to check that PR count is greater than 1, because github prevents creating multiple PRs with the same head and base branches
39+
40+
# Check that PR is not draft
41+
if [[ "$(jq '.[0] | .isDraft' pr.json)" == "true" ]]; then
42+
echo "PR is a draft"
43+
exit 1
44+
fi
45+
46+
# Check that PR is mergeable
47+
if [[ "$(jq '.[0] | .mergeable' pr.json)" == "false" ]]; then
48+
echo "PR is not mergeable"
49+
exit 1
50+
fi
51+
52+
# Check that PR is approved
53+
if [[ "$(jq -r '.[0] | .reviewDecision' pr.json)" != "APPROVED" ]]; then
54+
echo "PR is not approved"
55+
exit 1
56+
fi
57+
58+
# Check that PR build is successful, sdm policy check is a bit different from the others
59+
unsuccessful_check_count=$(jq '[.[0] | .statusCheckRollup | .[] | select(.workflowName != null and (.status != "COMPLETED" or .conclusion != "SUCCESS") or (.context != null and .state != "SUCCESS"))] | length' pr.json)
60+
if [[ "$unsuccessful_check_count" -gt 0 ]]; then
61+
echo "PR build is not successful"
62+
exit 1
63+
fi
64+
65+
echo "pr_number=$(jq '.[0] | .number' pr.json)" >> "$GITHUB_OUTPUT"
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Rewrite datadog branch
70+
run: |
71+
git checkout datadog
72+
git reset --hard ${{ github.ref_name }}
73+
git push -f
74+
75+
- name: Close PR and delete update branch
76+
run: |
77+
gh pr close -d ${{ steps.check_pr.outputs.pr_number }}
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)