Skip to content

Commit 6f02bdb

Browse files
committed
Add auto-deploy support
1 parent e601a3a commit 6f02bdb

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "Deploy to S3"
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
pull_request:
7+
branches: [ "**" ]
8+
schedule:
9+
- cron: '17 14 * * 3'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
# Run in all these versions of Python
18+
python-version: ["3.10"]
19+
20+
steps:
21+
# Checkout the latest code from the repo
22+
- name: Checkout repo
23+
uses: actions/checkout@v2
24+
25+
# Setup which version of Python to use
26+
- name: Set Up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
# Display the Python version being used
32+
- name: Display Python version
33+
run: python -c "import sys; print(sys.version)"
34+
35+
# Update pip
36+
- name: Update pip
37+
run: python -m pip install --upgrade pip
38+
39+
# Install requirements.
40+
- name: Install requirements
41+
run: python -m pip install --upgrade -r requirements.txt
42+
43+
# Create environment variables.
44+
- name: Create environment variables
45+
run: python write_config.py --github_access_token ${{ secrets.ACCESS_TOKEN_GITHUB }} --aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --bucket ${{ secrets.AWS_BUCKET }}
46+
47+
# Deploy to S3 Bucket
48+
- name: Deploy to S3
49+
run: python update_voters.py --no_print yes

update_voters.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import requests
22
import json
33
import boto3
4+
import argparse
5+
import sys, os
46
from configparser import ConfigParser
57

8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("--no_print", help="Disable printing")
10+
args = parser.parse_args()
11+
12+
if args.no_print:
13+
sys.stdout = open(os.devnull, "w")
14+
615
config = ConfigParser()
716
config.read(".env")
817
FILE = config.get("default", "file")

write_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from configparser import ConfigParser
2+
import argparse
3+
import sys, os
4+
5+
sys.stdout = open(os.devnull, "w")
6+
7+
parser = argparse.ArgumentParser()
8+
config = ConfigParser()
9+
10+
parser.add_argument("--github_access_token", help="Github access token")
11+
parser.add_argument("--aws_access_key_id", help="AWS access key id")
12+
parser.add_argument("--aws_secret_access_key", help="AWS secret access key")
13+
parser.add_argument("-b", "--bucket", help="S3 bucket name")
14+
15+
args = parser.parse_args()
16+
17+
config.add_section("github")
18+
config.add_section("aws")
19+
config.add_section("default")
20+
21+
22+
config.set("github", "access_token", args.github_access_token)
23+
config.set("aws", "aws_access_key_id", args.aws_access_key_id)
24+
config.set("aws", "aws_secret_access_key", args.aws_secret_access_key)
25+
config.set("aws", "bucket", args.bucket)
26+
config.set("default", "file", "voters.csv")
27+
28+
29+
with open(file="test.ini", mode="w+", encoding="utf-8") as f:
30+
config.write(f)

0 commit comments

Comments
 (0)