Repository navigation
132 lines (123 loc) · 5.13 KB
/
Copy pathupdate-pull-request-parent.yml
File metadata and controls
132 lines (123 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Update pull request parent
on:
workflow_call:
inputs:
number:
required: true
type: string
base-ref:
required: true
type: string
base-sha:
required: true
type: string
base-previous-sha:
required: true
type: string
parent-merge-sha:
required: true
type: string
head-ref:
required: true
type: string
head-sha:
required: true
type: string
outputs:
outcome:
description: "Whether the parent update was clean, conflicted, or empty"
value: ${{ jobs.update.outputs.outcome }}
head_sha:
description: "The cleanly rebased candidate head"
value: ${{ jobs.update.outputs.head_sha }}
rejection_reason:
description: "Why a source or parent revision could not be used"
value: ${{ jobs.update.outputs.rejection_reason }}
permissions: {}
env:
UV_LOCKED: 1
jobs:
update:
name: "Update parent of pull request #${{ inputs.number }}"
if: github.repository == 'astral-sh/uv-dev' || github.repository == 'astral-sh/uv-security'
runs-on: ${{ github.repository_owner == 'astral-sh' && 'github-ubuntu-24.04-x86_64-2' || 'ubuntu-slim' }}
timeout-minutes: 10
permissions:
contents: read
outputs:
outcome: ${{ steps.update.outputs.outcome }}
head_sha: ${{ steps.update.outputs.head_sha }}
rejection_reason: ${{ steps.update.outputs.rejection_reason }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Rebase child commits without conflict resolution
id: update
env:
BASE_REF: ${{ inputs.base-ref }}
BASE_SHA: ${{ inputs.base-sha }}
BASE_PREVIOUS_SHA: ${{ inputs.base-previous-sha }}
PARENT_MERGE_SHA: ${{ inputs.parent-merge-sha }}
HEAD_REF: ${{ inputs.head-ref }}
HEAD_SHA: ${{ inputs.head-sha }}
GH_TOKEN: ${{ github.token }}
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_NOSYSTEM: "1"
GIT_EDITOR: "true"
run: |
git check-ref-format "refs/heads/$BASE_REF"
git check-ref-format "refs/heads/$HEAD_REF"
for sha in "$BASE_SHA" "$BASE_PREVIOUS_SHA" "$PARENT_MERGE_SHA" "$HEAD_SHA"; do
if ! [[ "$sha" =~ ^[0-9a-f]{40}$ ]]; then
echo "The parent-update context contains an invalid commit SHA." >&2
exit 1
fi
done
git -c credential.helper= -c 'credential.helper=!gh auth git-credential' fetch \
--no-tags "https://github.com/$GITHUB_REPOSITORY.git" "refs/heads/$HEAD_REF"
if [ "$(git rev-parse 'FETCH_HEAD^{commit}')" != "$HEAD_SHA" ] || [ "$(git rev-parse --verify "refs/remotes/origin/$BASE_REF^{commit}")" != "$BASE_SHA" ]; then
echo "rejection_reason=The source or destination changed before its parent update." >> "$GITHUB_OUTPUT"
exit 0
fi
if ! git merge-base --is-ancestor "$BASE_PREVIOUS_SHA" "$HEAD_SHA" || ! git merge-base --is-ancestor "$PARENT_MERGE_SHA" "$BASE_SHA"; then
echo "rejection_reason=The source or destination does not contain the verified parent revision." >> "$GITHUB_OUTPUT"
exit 0
fi
git checkout --detach "$HEAD_SHA"
git config user.name "astral-automations-bot[bot]"
git config user.email "305554984+astral-automations-bot[bot]@users.noreply.github.com"
if ! git -c core.hooksPath=/dev/null -c commit.gpgsign=false rebase --committer-date-is-author-date --onto "$BASE_SHA" "$BASE_PREVIOUS_SHA"; then
if { [ -d "$(git rev-parse --git-path rebase-merge)" ] || [ -d "$(git rev-parse --git-path rebase-apply)" ]; } && [ -n "$(git ls-files --unmerged)" ]; then
git -c core.hooksPath=/dev/null rebase --abort
echo "outcome=conflicts" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Git failed without leaving merge conflicts." >&2
exit 1
fi
git merge-base --is-ancestor "$BASE_SHA" HEAD
git diff --check "$BASE_SHA...HEAD"
if [ -n "$(git status --porcelain)" ]; then
echo "The parent update left a dirty worktree." >&2
exit 1
fi
if [ "$(git rev-parse HEAD)" = "$BASE_SHA" ]; then
echo "outcome=empty" >> "$GITHUB_OUTPUT"
exit 0
fi
git bundle create "$RUNNER_TEMP/updated-parent.bundle" "$BASE_SHA..HEAD"
{
echo "outcome=clean"
echo "head_sha=$(git rev-parse HEAD)"
} >> "$GITHUB_OUTPUT"
- name: Upload updated parent candidate
if: steps.update.outputs.outcome == 'clean'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: updated-pull-request-parent-${{ inputs.number }}-${{ inputs.head-sha }}
path: ${{ runner.temp }}/updated-parent.bundle
if-no-files-found: error
compression-level: 0
retention-days: 1