116 lines (101 loc) · 3.01 KB
/
reuseable-pr-from-artifact.yml
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
name: R - Create PR from Artifact
on:
workflow_call:
inputs:
patch_artifact:
description: Name of the Artifact
required: true
type: string
patch_path:
description: Patch diff files
required: false
type: string
default: "*.diff"
base:
description: The Base Ref to apply the diff
required: true
type: string
body:
description: Optional body of the PR
required: false
type: string
commit-message:
description: Commit Message for the PR
required: true
type: string
branch:
description: The Branch to create for the PR
required: true
type: string
title:
description: PR title - defaults to commit-message
required: false
type: string
secrets:
app_id:
required: true
private_key:
required: true
permissions:
contents: read
jobs:
pr:
runs-on: ubuntu-latest
env:
REF_BRANCH: ${{ inputs.base }}
steps:
- name: Input
env:
INPUT: ${{ toJSON(inputs) }}
run: |
echo "$INPUT"
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ env.REF_BRANCH }}
- name: Restore Artifact
uses: actions/download-artifact@v3
with:
name: ${{ inputs.patch_artifact }}
path: temp
- name: show downloaded
run: ls -alFR temp
# - name: show diff
# run: cat temp/*.diff
- name: apply diff
run: |
git apply --allow-empty temp/${{ inputs.patch_path }}
- name: Has changes
run: |
git --no-pager diff --compact-summary --exit-code && echo "git_status=clean" >> $GITHUB_ENV || echo "git_status=dirty" >> $GITHUB_ENV
git --no-pager diff --compact-summary
- name: Gen Body
env:
BODY: ${{ inputs.body }}
run: |
echo 'git_body<<DIFF' >> $GITHUB_ENV
echo "$BODY" >> $GITHUB_ENV
git --no-pager diff --compact-summary >> $GITHUB_ENV
echo 'DIFF' >> $GITHUB_ENV
- name: Echo git_status
run: echo "${{ env.git_status }}"
- name: Body
run: |
echo "$git_body"
- uses: tibdex/github-app-token@f717b5ecd4534d3c4df4ce9b5c1c2214f0f7cd06 # v1.5 # cspell:ignore tibdex
if: env.git_status == 'dirty'
id: generate-token
with:
app_id: ${{ secrets.app_id }}
private_key: ${{ secrets.private_key }}
- name: Create Pull Request
if: env.git_status == 'dirty'
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 # v4
with:
commit-message: ${{ inputs.commit-message }}
branch: ${{ inputs.branch }}
base: ${{ inputs.base }}
title: ${{ inputs.title || inputs.commit-message }}
token: ${{ steps.generate-token.outputs.token }}
body: ${{ env.git_body }}
delete-branch: true