-
Notifications
You must be signed in to change notification settings - Fork 2
165 lines (134 loc) · 5.07 KB
/
reusable-autolog.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: reusable-autolog
on:
workflow_call:
secrets:
WORKFLOW_TOKEN:
required: true
EPICGAMES:
required: false
MEGA:
required: false
ONEDRIVE:
required: false
USR_YAHOO_1:
required: false
PWD_YAHOO_1:
required: false
SMU:
required: false
# inputs in this case are arguments passed from caller workflow
inputs:
# name of folder to commit csv logfile to
folder:
required: true
type: string
# how the caller workflow was triggered (auto or manual)
mode:
required: true
type: string
# account platform name to be reflected in commit message, e.g. OneDrive
platform-name:
default: ${{ inputs.folder }}
type: string
# Workflow level env variables:
# Declare GitHub Personal Access Token
# and login credentials of each account here
env:
WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
EPICGAMES: ${{ secrets.EPICGAMES }}
MEGA: ${{ secrets.MEGA }}
ONEDRIVE: ${{ secrets.ONEDRIVE }}
USR_YAHOO_1: ${{ secrets.USR_YAHOO_1 }}
PWD_YAHOO_1: ${{ secrets.PWD_YAHOO_1 }}
SMU: ${{ secrets.SMU }}
jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v3 # checkout repo content of caller workflow to github runner.
- name: Setup Python
uses: actions/setup-python@v4
# with:
# python-version: 3.9.6
- name: Setup dependencies
run: |
pip install python-dotenv
pip install playwright
playwright install firefox
pip install pandas
pip install rapidfuzz
pip install requests
# pip install rapidfuzz==2.0.11
- name: Clone private repo folder
run: |
git clone \
--depth 1 \
--filter=blob:none \
--sparse \
https://${GITHUB_ACTOR}:${{ env.WORKFLOW_TOKEN }}@github.com/${GITHUB_REPOSITORY_OWNER}/login-log \
;
cd login-log
git sparse-checkout init --cone
git sparse-checkout set ${{ inputs.folder }}
cd ..
- name: Run Python script
run: python keep-${{ inputs.folder }}-active.py
- name: Commit and push folder to private repo if updated
run: |
cd login-log
datestamp=$(date -u +%F)
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add ./${{ inputs.folder }}
if ! git diff-index --quiet HEAD; then
git commit -m "updated ${{ inputs.platform-name }} logs for ${datestamp} (${{ inputs.mode }})" -- ./${{ inputs.folder }}
git push "https://${GITHUB_ACTOR}:${{ env.WORKFLOW_TOKEN }}@github.com/${GITHUB_REPOSITORY_OWNER}/login-log.git" \
HEAD:main || exit 0
fi
schedule-maintenance:
needs: login
# if: (needs.login.result == 'success' || needs.login.result == 'failure') && (inputs.folder != 'smu')
# always runs after login job regardless of whether login job succeeded.
# Does not run for SMU script
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v3
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v4
# with:
# python-version: 3.8.2
- name: Setup dependencies
run: pip install ruamel.yaml
- name: Run reset schedule script
id: reset
if: needs.login.result == 'success' && inputs.folder != 'smu'
run: |
export folder=${{ inputs.folder }}
python reset-schedule.py
- name: Run reschedule script
id: reschedule
if: needs.login.result == 'failure' && inputs.folder != 'smu'
run: |
export folder=${{ inputs.folder }}
python reschedule-next-run.py
- name: Commit and push modified YAML file
env:
WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git pull
git add -A
if ! git diff-index --quiet HEAD; then
if [[ ${{ steps.reset.outcome }} == 'success' ]]; then
git commit -m "login-${{ inputs.folder }}-auto back to normal schedule"
elif [[ ${{ steps.reschedule.outcome }} == 'success' ]]; then
git commit -m "rescheduled login-${{ inputs.folder }}-auto"
fi
git push "https://${GITHUB_ACTOR}:${WORKFLOW_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:main || exit 0
fi
# EOF