-
-
Notifications
You must be signed in to change notification settings - Fork 157
70 lines (52 loc) · 2.89 KB
/
update-acknowledgements.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
# Update the Acknowledgements.md file by periodically running a python script. !@#$!@$%!#$%
name: Update Acknowledgements
# Controls when the action will run
on:
# Action is triggered manually
workflow_dispatch:
# Action runs periodically
schedule:
- cron: "*/5 * * * *" # Every 5 minutes. See crontab.guru/
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "regenerate-acknowledgements"
regenerate-acknowledgements:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: master # Checkout the branch with this name
- name: Use cache
uses: actions/cache@v4
with: # Note: Setting `enableCrossOsArchive: true` would kinda make sense because the cached data is not OS specific. But we only run on Ubuntu at the moment, so it's whatever.
path: Markdown/gumroad_sales_cache.json
key: gumroad_sales_cache-${{ github.run_id }}-${{ github.run_attempt }} # A cache is immutable. To get the cache to behave as if it's updatable, the key needs to change on every run, so that there's a new cache every run. Then `restore-keys` can be used to restore the latest cache. Source: https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache)
restore-keys: |
gumroad_sales_cache-
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip' # caching pip dependencies. This is from the official example. Not totally sure what we're doing here.
cache-dependency-path: './Markdown/Code/python_requirements.txt'
- name: Install python dependencies
run: |
python -m pip install -r ./Markdown/Code/python_requirements.txt
- name: Run script
run: |
python ./Markdown/Code/markdown_generator.py --document acknowledgements --api_key ${{ secrets.GUMROAD_API_KEY }}
- name: Commit and push changes
run: |
if [[ -n $(git status --short) ]]; then
# We do if statement here, otherwise the GitHub Actions exits with an error if there are no changes which we don't want since it's normal to have no changes. Src for the if condition: https://remarkablemark.org/blog/2017/10/12/check-git-dirty/
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "GitHub Actions Workflow automatically regenerated Acknowledgements.md"
git push
else
echo 'No changes. Not commiting and pushing'
fi