-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (107 loc) · 3.72 KB
/
copy-content.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
117
118
119
120
121
name: Copy content to other repository
on:
workflow_call:
inputs:
repo:
required: true
type: string
branch:
required: true
type: string
source_dir:
required: true
type: string
destination_dir:
required: true
type: string
commit_msg:
required: true
type: string
prerun:
required: false
type: string
secrets:
PAT:
required: true
jobs:
copy_content:
runs-on: ubuntu-latest
steps:
- name: Check if existing tokens branch exists
id: check_branch
env:
GH_TOKEN: ${{ secrets.PAT }}
run: echo "branch_exists=$(gh api repos/${{ inputs.repo }}/branches/${{ inputs.branch }} --jq '.name' | wc -l | xargs)" >> $GITHUB_OUTPUT
- name: Check if open PR exists
id: check_pr
env:
GH_TOKEN: ${{ secrets.PAT }}
run: echo "pr_exists=$(gh pr list -R ${{ inputs.repo }} -H ${{ inputs.branch }} --json number -q length)" >> $GITHUB_OUTPUT
- name: Checkout source repo
uses: actions/checkout@v4
with:
path: "source"
- name: Checkout destination repo (Branch exists)
uses: actions/checkout@v4
if: ${{ steps.check_branch.outputs.branch_exists != 0 }}
with:
path: "destination"
repository: ${{ inputs.repo }}
token: ${{ secrets.PAT }}
ref: ${{ inputs.branch }}
- name: Checkout destination repo (Branch doesn't exist)
uses: actions/checkout@v4
if: ${{ steps.check_branch.outputs.branch_exists == 0 }}
with:
path: "destination"
repository: ${{ inputs.repo }}
token: ${{ secrets.PAT }}
- name: Create branch in destination repo
if: ${{ steps.check_branch.outputs.branch_exists == 0 }}
run: |
cd destination
git checkout -b ${{ inputs.branch }}
- name: Run pre-run command
if: inputs.prerun != ''
run: |
cd destination
eval ${{ inputs.prerun }}
- name: Get current date
id: date
run: echo "date=$(date +'%d %b %Y, %H:%M:%S')" >> $GITHUB_OUTPUT
- name: Copy files
# run: cp -r source/${{ inputs.source_dir }}/* destination/${{ inputs.destination_dir }}
- name: Stage destination changes
run: |
cd destination
git config --global user.name "zeta-icons-bot"
git config --global user.email "[email protected]"
git add -A
- run: cd destination; git diff
- name: Check if there are changes
id: changed
run: |
cd destination
git diff
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: steps.changed.outputs.changed == 'true'
run: |
git commit -m "deps(automated): ${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
git push --set-upstream origin ${{inputs.branch}} -f
- name: Open PR
uses: thecanadianroot/[email protected]
if: ${{ steps.check_pr.outputs.pr_exists == 0 }}
with:
token: ${{ secrets.PAT }}
base: main
head: ${{ inputs.branch }}
title: "deps(automated): ${{inputs.commit_msg}}"
labels: tokens
body: "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"
repository: ${{ inputs.repo }}
- name: Add comment to existing PR
env:
GH_TOKEN: ${{ secrets.PAT }}
if: ${{ steps.check_pr.outputs.pr_exists != 0 }}
run: gh pr comment -R ${{ inputs.repo }} ${{ inputs.branch }} --body "${{inputs.commit_msg}} ${{ steps.date.outputs.date }}"