-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (92 loc) · 3.7 KB
/
main.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
name: Pull Files from Another Repository on Push
env:
SOURCE_REPO: lwcorp/lwserver
AUTOMATIC_MONITOR: true
FILES: "*.au3 LICENSE" # separate multiple entries with ,
FILES_NEW: "*.au3 LICENSE*" # separate multiple entries with ,
EXTRA: mv LICENSE LICENSE_LWServer # do an extra command like renaming
USERNAME: ${{ github.actor }}
ADDRESS_SUFFIX: users.noreply.github.com
TOKEN_NAME: ACCESS_TOKEN # name of token defined in the target repo's settings, needed for private repos
# SOURCE_BRANCH: source_alternate_branch # uncomment to takes files from a non default source branch
# TARGET_BRANCH: target_alternate_branch # uncomment to monitor a non default target branch
# TARGET_PATH: target_alternate_path # uncomment to monitor a non default target branch
THE_SERVER: ${{ github.server_url }}
PATH_SOURCE_CHECKOUT: temp_folder
THE_SECRET: ${{ secrets.TOKEN_NAME || 'default_value' }}
on: # Remove # below for non default branches
workflow_dispatch:
push:
# branches:
# - ${{ env.TARGET_BRANCH }}
# paths:
# - ${{ env.TARGET_PATH }}
jobs:
pull-file:
runs-on: ubuntu-latest
steps:
- name: Check whether to automatically monitor
if: ${{ github.event_name != 'workflow_dispatch' && env.AUTOMATIC_MONITOR == false }}
run: |
echo "Set not to run automatically. Exiting."
echo "exiting1=true" >> $GITHUB_ENV
- name: Checkout
if: env.exiting1 != 'true'
uses: actions/checkout@v3
- name: Checkout source with token and branch
if: env.exiting1 != 'true' && env.THE_SECRET != 'default_value' && env.SOURCE_BRANCH
uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_REPO }}
ref: ${{ env.SOURCE_BRANCH }}
token: ${{ secrets[env.TOKEN_NAME] }}
path: ${{ env.PATH_SOURCE_CHECKOUT }}
- name: Checkout source with token but without branch
if: env.exiting1 != 'true' && env.THE_SECRET != 'default_value' && !env.SOURCE_BRANCH
uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_REPO }}
token: ${{ secrets[env.TOKEN_NAME] }}
path: ${{ env.PATH_SOURCE_CHECKOUT }}
- name: Checkout source without token but with branch
if: env.exiting1 != 'true' && env.THE_SECRET == 'default_value' && env.SOURCE_BRANCH
uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_REPO }}
ref: ${{ env.SOURCE_BRANCH }}
path: ${{ env.PATH_SOURCE_CHECKOUT }}
- name: Checkout source without token and without branch
if: env.exiting1 != 'true' && env.THE_SECRET == 'default_value' && !env.SOURCE_BRANCH
uses: actions/checkout@v3
with:
repository: ${{ env.SOURCE_REPO }}
path: ${{ env.PATH_SOURCE_CHECKOUT }}
- name: Update
if: env.exiting1 != 'true'
run: |
cd $PATH_SOURCE_CHECKOUT
$EXTRA
cp -u $FILES_NEW ../
cd ..
- name: Check for changes
if: env.exiting1 != 'true'
run: |
if git diff --quiet; then
echo "No changes detected. Exiting."
echo "exiting2=true" >> $GITHUB_ENV
fi
- name: Commit
if: env.exiting1 != 'true' && env.exiting2 != 'true'
run: |
git config user.name "$USERNAME"
git config user.email "$USERNAME@$ADDRESS_SUFFIX"
git add $FILES_NEW
git commit -m "Pulled files from $THE_SERVER/$SOURCE_REPO."
- name: Push
if: env.exiting1 != 'true' && env.exiting2 != 'true'
run: |
if [ -n "$TARGET_BRANCH" ]; then
git push origin $TARGET_BRANCH
else
git push
fi