-
Notifications
You must be signed in to change notification settings - Fork 968
75 lines (67 loc) · 2.35 KB
/
trust-fork-pr.yml
File metadata and controls
75 lines (67 loc) · 2.35 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
name: Trust Fork PR
on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to trust'
required: true
jobs:
trust-fork:
runs-on: ubuntu-latest
steps:
- name: Generate unique identifier
id: gen_uid
run: echo "::set-output name=uid::$(date +%s)-${{ github.run_id }}"
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Fetch PR details
id: pr
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: parseInt(context.payload.inputs.pr_number)
});
core.setOutput('head_repo', pr.data.head.repo.full_name);
core.setOutput('head_branch', pr.data.head.ref);
- name: Fetch and push to trusted branch
env:
FORK_REPO: ${{ steps.pr.outputs.head_repo }}
FORK_BRANCH: ${{ steps.pr.outputs.head_branch }}
UNIQUE_ID: ${{ steps.gen_uid.outputs.uid }}
run: |
git remote add fork https://github.com/${FORK_REPO}.git
git fetch fork ${FORK_BRANCH}
git push origin fork/${FORK_BRANCH}:temp-ci-trusted-fork-${UNIQUE_ID} --force
- name: Cleanup
if: always()
run: |
git remote remove fork
- name: Schedule branch deletion
if: success()
env:
UNIQUE_ID: ${{ steps.gen_uid.outputs.uid }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const deleteDate = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(); // 24 hours from now
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'trust-fork-pr-cleanup.yml',
ref: 'main',
inputs: {
branch_to_delete: `temp-ci-trusted-fork-${process.env.UNIQUE_ID}`,
delete_after: deleteDate
}
});