-
Notifications
You must be signed in to change notification settings - Fork 723
149 lines (132 loc) · 5.53 KB
/
full-ci-promote.yml
File metadata and controls
149 lines (132 loc) · 5.53 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Full CI Promote
on:
pull_request_target:
types:
- labeled
concurrency:
group: full-ci-promote-${{ github.event.pull_request.number }}
cancel-in-progress: false
permissions:
actions: write
contents: write
pull-requests: write
issues: write
jobs:
promote:
if: |
github.event.label.name == 'run-with-secrets' &&
github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
ref: main
- name: Fetch contributor branch
env:
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
TARGET_BRANCH: ci/pr-${{ github.event.pull_request.number }}
run: |
git config user.name "opendal-bot"
git config user.email "opendal-bot@apache.org"
git fetch https://github.com/${PR_HEAD_REPO} ${PR_HEAD_REF}:refs/remotes/contrib/head
git checkout -B "${TARGET_BRANCH}" remotes/contrib/head
git push --force origin "${TARGET_BRANCH}"
- name: Create or update mirror PR
id: create_internal_pr
uses: actions/github-script@v8
env:
TARGET_BRANCH: ci/pr-${{ github.event.pull_request.number }}
with:
script: |
const targetBranch = process.env.TARGET_BRANCH;
const base = 'main';
const owner = context.repo.owner;
const repo = context.repo.repo;
const headParam = `${owner}:${targetBranch}`;
const { data: existing } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: headParam,
base,
per_page: 1,
});
let mirrorPr = existing[0];
if (!mirrorPr) {
const title = `[CI] Full run for #${context.payload.pull_request.number}`;
const body = [
`Mirrored branch for PR #${context.payload.pull_request.number}.`,
'This PR is created automatically to run full CI with repository secrets after maintainer approval.',
'Do not edit manually.',
].join('\n');
const createResp = await github.rest.pulls.create({ owner, repo, head: headParam, base, title, body });
mirrorPr = createResp.data;
}
core.setOutput('mirror_pr_number', mirrorPr.number);
core.setOutput('mirror_pr_html_url', mirrorPr.html_url);
- name: Trigger Behavior Test
uses: actions/github-script@v8
env:
TARGET_BRANCH: ci/pr-${{ github.event.pull_request.number }}
with:
script: |
const workflows = [
{ id: 'test_behavior.yml', inputs: { pr_number: `${context.payload.pull_request.number}` } },
];
const owner = context.repo.owner;
const repo = context.repo.repo;
const ref = process.env.TARGET_BRANCH;
for (const workflow of workflows) {
await github.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id: workflow.id,
ref,
inputs: workflow.inputs,
});
core.info(`Dispatched ${workflow.id} on ref ${ref}`);
}
- name: Comment on PR
uses: actions/github-script@v8
env:
MIRROR_PR: ${{ steps.create_internal_pr.outputs.mirror_pr_number || '' }}
MIRROR_PR_URL: ${{ steps.create_internal_pr.outputs.mirror_pr_html_url || '' }}
with:
script: |
const marker = '<!-- ci-bot:full-ci -->';
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const mirrorUrl = process.env.MIRROR_PR_URL;
const body = [
marker,
'Maintainer triggered full CI with repository secrets.',
`Please monitor the mirrored CI PR for results: ${mirrorUrl}`,
'Workflows dispatched: test_behavior.yml.',
'Re-applying the label will refresh this mirror.',
].join('\n');
const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number: prNumber, per_page: 100 });
const existing = comments.find((c) => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body });
}