Add tablegen workflow

Fix workflow


Fix workflow


Fix workflow


Update table
This commit is contained in:
akp 2020-12-06 11:45:04 +00:00
parent b81f7c7235
commit b03983913d
No known key found for this signature in database
GPG key ID: D3E7EAA31B39637E
4 changed files with 105 additions and 16 deletions

48
.github/README.md vendored
View file

@ -4,23 +4,39 @@ Solutions to the [2020 Advent of Code](https://adventofcode.com/2020), in both P
Go solutions are near direct copies of the Python solutions and may be added a few days afterwards. Go solutions are near direct copies of the Python solutions and may be added a few days afterwards.
**Key:** ![Completed][check] is completed, ![Incomplete][cross] is incomplete. **Key:** ![Completed][check] is completed, ![Incomplete][cross] is incomplete, ![Partially complete][partial] is partially complete and ![Not yet attempted][pending] is released but not yet attempted.
| | Part 1 | Part 2 | | Part 1 | Part 2 | <!-- PARSE START -->
|----|-------------------------|-------------------------|----|-------------------------|-------------------------| | Day | | Python | Go |
| 1 | ![Completed][check] | ![Completed][check] | 2 | ![Completed][check] | ![Completed][check] | |-----|---------------------|--------|----|
| 3 | ![Completed][check] | ![Completed][check] | 4 | ![Completed][check] | ![Completed][check] | | 1 | ![Completed][check] | | |
| 5 | ![Completed][check] | ![Completed][check] | 6 | ![Completed][check] | ![Completed][check] | | 2 | ![Completed][check] | | |
| 7 | | | 8 | | | | 3 | ![Completed][check] | | |
| 9 | | | 10 | | | | 4 | ![Completed][check] | | |
| 11 | | | 12 | | | | 5 | ![Completed][check] | | |
| 13 | | | 14 | | | | 6 | ![Not yet attempted][pending] | | |
| 15 | | | 16 | | | | 7 | | | |
| 17 | | | 18 | | | | 8 | | | |
| 19 | | | 20 | | | | 9 | | | |
| 21 | | | 22 | | | | 10 | | | |
| 23 | | | 24 | | | | 11 | | | |
| 25 | | | | | | | 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
<!-- PARSE END -->
[check]: https://github.com/codemicro/adventOfCode/blob/master/.github/check.jpg?raw=true [check]: https://github.com/codemicro/adventOfCode/blob/master/.github/check.jpg?raw=true
[cross]: https://github.com/codemicro/adventOfCode/blob/master/.github/cross.jpg?raw=true [cross]: https://github.com/codemicro/adventOfCode/blob/master/.github/cross.jpg?raw=true
[partial]: https://github.com/codemicro/adventOfCode/blob/master/.github/partial.jpg?raw=true
[pending]: https://github.com/codemicro/adventOfCode/blob/master/.github/asterisk.jpg?raw=true

BIN
.github/partial.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

41
.github/tablegen.py vendored Normal file
View file

@ -0,0 +1,41 @@
from datetime import datetime
import re
today_day = datetime.now().day
readme_text = open(".github/README.md").read().strip().split("\n")
start_flag = "<!-- PARSE START -->"
end_flag = "<!-- PARSE END -->"
table_lines = []
in_table = False
for line in readme_text:
line = line.strip()
if line == end_flag:
in_table = False
if in_table:
table_lines.append(line)
elif line == start_flag:
in_table = True
for i, l in enumerate(table_lines):
rs = re.match(r"\|\s*(\d{1,})\s*\|\s*\|.+\|.+\|", l)
if rs is not None and int(rs.group(1)) == today_day:
table_lines[i] = f"| {today_day} | ![Not yet attempted][pending] | | |"
counter = 0
for i, line in enumerate(readme_text):
line = line.strip()
if line == end_flag:
in_table = False
if in_table:
readme_text[i] = table_lines[counter]
counter += 1
elif line == start_flag:
in_table = True
open(".github/README.md", "w").write("\n".join(readme_text))

32
.github/workflows/updatetable.yml vendored Normal file
View file

@ -0,0 +1,32 @@
name: Update table
on:
workflow_dispatch:
schedule:
- cron: "1 5 * 12 *"
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Run script
run: python .github/tablegen.py
- name: Git commit and push
run: |
git config user.email 'actions@github.com'
git config user.name 'github-actions'
git add .github/README.md
git commit -m 'Update table'
git push origin HEAD:${{ github.ref }}