-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
84 lines (78 loc) · 3.14 KB
/
action.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
name: Update Files
description: |
Updates all common project files by pulling them from a central repository
and creating a pull request in the target repository if there are changes.
inputs:
source-repo:
description: The URL of the repository containing the common files.
default: https://github.com/BetonQuest/CommonProjectFiles
branch-name:
description: The branch name to use for syncing changes.
default: CommonProjectFiles-Sync
ignored-files:
description: |
A comma-separated list of additional files or directories to ignore during the sync process.
Example: .github,custom-config.json
default: ''
include-default-ignored-files:
description: |
A comma-separated list of entries from the default ignore list to re-add (i.e., include back during the sync).
Example: LICENSE,README.md
default: ''
token:
description: The GitHub token to use for cloning the target repository.
default: ${{ github.token }}
runs:
using: composite
steps:
- name: Checkout Target Repository
uses: actions/checkout@v4
- name: Clone Source Repository
shell: bash --noprofile --norc -euo pipefail {0}
run: |
git clone --depth 1 ${{ inputs.source-repo }} CommonProjectFiles
- name: Prepare Ignored Files
shell: bash --noprofile --norc -euo pipefail {0}
run: |
DEFAULT_IGNORED_FILES=".git,README.md,LICENSE,action.yml,.github/dependabot.yml,.github/workflows/editorconfig.yml"
IGNORE_FILES="${DEFAULT_IGNORED_FILES}"
if [[ -n "${{ inputs.ignored-files }}" ]]; then
IGNORE_FILES+=",${{ inputs.ignored-files }}"
fi
if [[ -n "${{ inputs.include-default-ignored-files }}" ]]; then
IFS=',' read -ra READD_ENTRIES <<< "${{ inputs.include-default-ignored-files }}"
for ENTRY in "${READD_ENTRIES[@]}"; do
IGNORE_FILES=$(echo "$IGNORE_FILES" | sed "s~,$ENTRY~~g")
IGNORE_FILES=$(echo "$IGNORE_FILES" | sed "s~^$ENTRY,~~g")
IGNORE_FILES=$(echo "$IGNORE_FILES" | sed "s~,$ENTRY\$~~g")
done
fi
echo "ignore_files=${IGNORE_FILES}" >> $GITHUB_ENV
- name: Sync Files
shell: bash --noprofile --norc -euo pipefail {0}
run: |
IFS=',' read -ra IGNORE_FILES <<< ${{ env.ignore_files }}
cd CommonProjectFiles
find . -mindepth 1 | while read -r FILE; do
RELATIVE_PATH="${FILE#./}"
for IGNORE in "${IGNORE_FILES[@]}"; do
if [[ "$RELATIVE_PATH" == "$IGNORE" || "$RELATIVE_PATH" == "$IGNORE/"* ]]; then
rm -rf "$FILE"
break
fi
done
done
cd ..
sync
rsync -av CommonProjectFiles/ ./
rm -rf CommonProjectFiles
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
branch: ${{ inputs.branch-name }}
title: "Sync common files"
body: |
This pull request updates the repository with the latest common files from the source repository.
commit-message: "Sync common files from central repository"
delete-branch: true
token: '${{ inputs.token }}'