Skip to content

Commit 30364f3

Browse files
authored
Merge pull request #118 from sommersoft/action-ify
Migrate Scheduled Adabot Activities From TravisCI to GitHub Actions
2 parents f7bbfc2 + 155122b commit 30364f3

File tree

7 files changed

+153
-59
lines changed

7 files changed

+153
-59
lines changed

.github/workflows/bundle_cron.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Update Bundles
2+
3+
on:
4+
schedule:
5+
- cron: 0 5 * * *
6+
7+
jobs:
8+
check-repo-owner:
9+
# This job is so the entire workflow will end successfully and give some
10+
# output to explain why it hasn't run on a non-Adafruit fork.
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: repository
14+
env:
15+
OWNER_IS_ADAFRUIT: ${{ startswith(github.repository, 'adafruit/') }}
16+
run: |
17+
echo "This workflow will only run if Adafruit is the repository owner."
18+
echo "Repository owner is Adafruit: $OWNER_IS_ADAFRUIT"
19+
update-bundles:
20+
runs-on: ubuntu-latest
21+
# Only run the build on Adafruit's repository. Forks won't have the secrets.
22+
# Its necessary to do this here, since 'schedule' events cannot (currently)
23+
# be limited (they run on all forks' default branches).
24+
if: startswith(github.repository, 'adafruit/')
25+
services:
26+
redis:
27+
image: redis
28+
ports:
29+
- 6379/tcp
30+
options: --entrypoint redis-server
31+
steps:
32+
- name: Dump GitHub context
33+
env:
34+
GITHUB_CONTEXT: ${{ toJson(github) }}
35+
run: echo "$GITHUB_CONTEXT"
36+
- name: Set up Python 3.6
37+
uses: actions/setup-python@v1
38+
with:
39+
python-version: 3.6
40+
- name: Versions
41+
run: |
42+
python3 --version
43+
- uses: actions/checkout@v1
44+
with:
45+
submodules: true
46+
- name: Install deps
47+
run: |
48+
pip install -r requirements.txt
49+
- name: Run adabot.circuitpython_bundle
50+
env:
51+
ADABOT_EMAIL: ${{ secrets.ADABOT_EMAIL }}
52+
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.ADABOT_GITHUB_ACCESS_TOKEN }}
53+
run: |
54+
python3 -u -m adabot.circuitpython_bundle

.github/workflows/reports_cron.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Run Daily Reports
2+
3+
on:
4+
schedule:
5+
- cron: 15 5 * * *
6+
7+
jobs:
8+
check-repo-owner:
9+
# This job is so the entire workflow will end successfully and give some
10+
# output to explain why it hasn't run on a non-Adafruit fork.
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: repository
14+
env:
15+
OWNER_IS_ADAFRUIT: ${{ startswith(github.repository, 'adafruit/') }}
16+
run: |
17+
echo "This workflow will only run if Adafruit is the repository owner."
18+
echo "Repository owner is Adafruit: $OWNER_IS_ADAFRUIT"
19+
run-reports:
20+
runs-on: ubuntu-latest
21+
# Only run the build on Adafruit's repository. Forks won't have the secrets.
22+
# Its necessary to do this here, since 'schedule' events cannot (currently)
23+
# be limited (they run on all forks' default branches).
24+
if: startswith(github.repository, 'adafruit/')
25+
env:
26+
ADABOT_GITHUB_ACCESS_TOKEN: ${{ secrets.ADABOT_GITHUB_ACCESS_TOKEN }}
27+
steps:
28+
- name: Dump GitHub context
29+
env:
30+
GITHUB_CONTEXT: ${{ toJson(github) }}
31+
run: echo "$GITHUB_CONTEXT"
32+
- name: Set up Python 3.6
33+
uses: actions/setup-python@v1
34+
with:
35+
python-version: 3.6
36+
- name: Versions
37+
run: |
38+
python3 --version
39+
- uses: actions/checkout@v1
40+
with:
41+
submodules: true
42+
- name: Install deps
43+
run: |
44+
pip install -r requirements.txt
45+
- name: Make Directory For Report Files
46+
run: mkdir -p bin/adabot
47+
- name: Set Date Variable
48+
id: today
49+
run: |
50+
echo ::set-output name=date::$(
51+
date +%Y%m%d
52+
)
53+
- name: Run adabot.circuitpython_libraries
54+
env:
55+
# LIB_CHECK_CP_FILE is for circuitpython_libraries.py output
56+
LIB_CHECK_CP_FILE: bin/adabot/circuitpython_library_report_${{ steps.today.outputs.date }}.txt
57+
run: |
58+
python3 -u -m adabot.circuitpython_libraries -o $LIB_CHECK_CP_FILE
59+
continue-on-error: true
60+
- name: Run adabot.circuitpython_library_download_stats
61+
env:
62+
# LIB_DL_STATS_FILE is for future Bundle and PyPi download stats script
63+
LIB_DL_STATS_FILE: bin/adabot/library_download_stats_${{ steps.today.outputs.date }}.txt
64+
run: |
65+
python3 -u -m adabot.circuitpython_library_download_stats -o $LIB_DL_STATS_FILE
66+
continue-on-error: true
67+
- name: Run adabot.arduino_libraries
68+
env:
69+
# LIB_CHECK_ARD_FILE is for arduino_libraries.py output
70+
LIB_CHECK_ARD_FILE: bin/adabot/arduino_library_report_${{ steps.today.outputs.date }}.txt
71+
run: |
72+
python3 -u -m adabot.arduino_libraries -o $LIB_CHECK_ARD_FILE
73+
continue-on-error: true
74+
- name: Check For Files
75+
run: |
76+
ls bin/adabot
77+
- name: Upload Reports To AWS S3
78+
env:
79+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
80+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
81+
run: "[ -z \"$AWS_ACCESS_KEY_ID\" ] || aws s3 cp bin/adabot/ s3://adafruit-circuit-python/adabot/bin/reports/ --recursive --no-progress --region us-east-1"

.travis.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

adabot/circuitpython_bundle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
def fetch_bundle(bundle, bundle_path):
4040
if not os.path.isdir(bundle_path):
4141
os.makedirs(bundle_path, exist_ok=True)
42-
if "TRAVIS" in os.environ:
42+
if "GITHUB_WORKSPACE" in os.environ:
4343
git_url = "https://" + os.environ["ADABOT_GITHUB_ACCESS_TOKEN"] + "@github.com/adafruit/"
4444
git.clone("-o", "adafruit", git_url + bundle + ".git", bundle_path)
4545
else:
@@ -360,7 +360,7 @@ def new_release(bundle, bundle_path):
360360

361361
if __name__ == "__main__":
362362
directory = os.path.abspath(".bundles")
363-
if "TRAVIS" in os.environ:
363+
if "GITHUB_WORKSPACE" in os.environ:
364364
git.config("--global", "user.name", "adabot")
365365
git.config("--global", "user.email", os.environ["ADABOT_EMAIL"])
366366
for bundle in bundles:

adabot/circuitpython_libraries.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ def run_library_checks(validators, bundle_submodules, latest_pylint, kw_args):
113113
output_handler("Found {} repos to check.".format(len(repos)))
114114
bundle_submodules = common_funcs.get_bundle_submodules()
115115
output_handler("Found {} submodules in the bundle.".format(len(bundle_submodules)))
116-
github_user = github.get("/user").json()
117-
output_handler("Running GitHub checks as " + github_user["login"])
118-
travis_user = travis.get("/user").json()
119-
output_handler("Running Travis checks as " + travis_user["login"])
116+
github_user = common_funcs.whois_github_user()
117+
output_handler("Running GitHub checks as " + github_user)
120118
need_work = 0
121119
lib_insights = {
122120
"merged_prs": 0,

adabot/github_requests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def _fix_kwargs(kwargs):
5757
kwargs["params"]["access_token"] = access_token
5858
else:
5959
kwargs["params"] = {"access_token": access_token}
60+
6061
return kwargs
6162

6263
def get(url, **kwargs):

adabot/lib/common_funcs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# different search params, and came up emtpy. Hardcoding it as a failsafe.
2525

2626
import datetime
27+
import os
2728
import re
2829
import requests
2930
from adabot import github_requests as github
@@ -249,3 +250,15 @@ def is_new_or_updated(repo):
249250
return "new"
250251
else:
251252
return "updated"
253+
254+
def whois_github_user():
255+
""" Find who the user is that is running the current instance of adabot.
256+
'GITHUB_ACTOR' is an environment variable available on GitHub Actions.
257+
"""
258+
user = None
259+
if "GITHUB_ACTOR" in os.environ:
260+
user = os.environ["GITHUB_ACTOR"]
261+
else:
262+
user = github.get("/user").json()["login"]
263+
264+
return user

0 commit comments

Comments
 (0)