-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (76 loc) · 2.8 KB
/
run_script.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
name: Run Python Script
on:
schedule:
- cron: '*/20 * * * *' # Every 20 minutes
workflow_dispatch:
jobs:
run-script:
runs-on: ubuntu-22.04
environment: Test
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install cryptography
pip install dnspython
- name: Create Python scripts
run: |
cat > decrypt_file.py << 'EOL'
from cryptography.fernet import Fernet
import os
def decrypt_file():
key = os.environ['ENCRYPTION_KEY'].encode()
f = Fernet(key)
with open('content_file.txt.encrypted', 'rb') as encrypted_file:
encrypted_data = encrypted_file.read()
decrypted_data = f.decrypt(encrypted_data)
with open('content_file.txt', 'wb') as decrypted_file:
decrypted_file.write(decrypted_data)
if __name__ == "__main__":
decrypt_file()
EOL
cat > encrypt_file.py << 'EOL'
from cryptography.fernet import Fernet
import os
def encrypt_file():
key = os.environ['ENCRYPTION_KEY'].encode()
f = Fernet(key)
with open('content_file.txt', 'rb') as file:
data = file.read()
encrypted_data = f.encrypt(data)
with open('content_file.txt.encrypted', 'wb') as encrypted_file:
encrypted_file.write(encrypted_data)
if __name__ == "__main__":
encrypt_file()
EOL
- name: Decrypt file if exists
env:
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
run: |
if [ -f "content_file.txt.encrypted" ]; then
python decrypt_file.py
fi
- name: Run script
env:
EMAIL: ${{ secrets.EMAIL }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
LOGIN_USERNAME: ${{ secrets.LOGIN_USERNAME }}
LOGIN_PASSWORD: ${{ secrets.LOGIN_PASSWORD }}
run: python script.py
- name: Encrypt and save file
env:
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
run: python encrypt_file.py
- name: Commit encrypted file
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git add content_file.txt.encrypted
git diff --quiet && git diff --staged --quiet || (git commit -m "Update encrypted content [skip ci]" && git push)