-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (120 loc) · 4.16 KB
/
routine.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
name: Invoke API
on:
schedule:
- cron: '7 1,5,10,14,17,22 * * *'
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#providing-inputs
workflow_dispatch:
inputs:
unconditional-invoking:
description: 'Invoke API unconditionally'
type: boolean
required: true
default: true
# https://github.com/actions/checkout/issues/19
jobs:
# Random:
# runs-on: ubuntu-latest
# outputs:
# runnable: ${{ steps.decision.outputs.runnable }}
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# with:
# ref: master
# token: ${{ secrets.PAT }}
# - name: Pull upstream
# run: bash wrapper.sh pull sync
# - name: Commit and push
# run: bash wrapper.sh push "sync with upstream"
# - name: Make a decision
# id: decision
# env:
# PASSWD: ${{ secrets.PASSWD }}
# run: |
# sum=$(cksum <<< "$PASSWD" | cut -f1 -d' ')
# m=$(date "+%-m")
# d=$(date "+%-d")
# h=$(date "+%-H")
# [ $(((d + m + sum) % 6)) = 1 ] && exit 0
# [ $(((h + d + sum) & 1)) = 1 ] && exit 0
# echo "::set-output name=runnable::true"
Invoke:
runs-on: ubuntu-latest
if: ${{ github.event.repository.private }}
# needs: Random
# if: needs.Random.outputs.runnable == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: master
token: ${{ secrets.PAT }}
- name: Sync with upstream
run: bash wrapper.sh pull
- name: Check config files
env:
USER: ${{ secrets.USER }}
run: |
bash wrapper.sh has_valid_cfg || {
echo "Config files are not valid, please run Register App action."
exit 1
}
- name: Make a decision
id: decision
env:
PASSWD: ${{ secrets.PASSWD }}
run: |
[ "${{ inputs.unconditional-invoking }}" = "true" ] && {
echo "runnable=true" >> $GITHUB_OUTPUT
exit 0
}
sum=$(cksum <<< "$PASSWD" | cut -f1 -d' ')
m=$(date "+%-m")
d=$(date "+%-d")
h=$(date "+%-H")
[ $(((d + m + sum) % 6)) = 1 ] && exit 0
[ $(((h + d + sum) & 1)) = 1 ] && exit 0
# echo "::set-output name=runnable::true"
echo "runnable=true" >> $GITHUB_OUTPUT
- name: Set up python
if: steps.decision.outputs.runnable == 'true'
id: setup-python
uses: actions/setup-python@v4
with:
python-version: '3.10.10'
- name: Load cached utils
if: steps.decision.outputs.runnable == 'true'
id: cached-utils
uses: actions/cache@v3
with:
path: ~/.local
key: ${{ runner.os }}-utils-az-poetry-20230204
restore-keys: |
${{ runner.os }}-utils-
- name: Install poetry
if: steps.decision.outputs.runnable == 'true' && steps.cached-utils.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: 1.3.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
if: steps.decision.outputs.runnable == 'true'
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-venv-${{ hashFiles('**/poetry.lock') }}
- name: Install python dependencies
if: steps.decision.outputs.runnable == 'true' && steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --only main
- name: Test API
if: steps.decision.outputs.runnable == 'true'
env:
USER: ${{ secrets.USER }}
PASSWD: ${{ secrets.PASSWD }}
run: bash wrapper.sh invoke
- name: Commit and push
if: steps.decision.outputs.runnable == 'true'
run: bash wrapper.sh push "update app config"