-
Notifications
You must be signed in to change notification settings - Fork 15
91 lines (80 loc) · 3.91 KB
/
check_links.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
name: Picture Health
on:
push:
branches: [ master ]
paths:
- '.github/workflows/check_links.yml'
- '**.xml'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/check_links.yml'
- '**.xml'
workflow_dispatch:
schedule:
# Runs at the start of each month (UTC)
- cron: '0 0 1 * *'
jobs:
check_urls:
# Do not run the scheduled workflow on forks
if: ( github.event_name != 'schedule' || github.repository_owner == 'Cockatrice' )
name: Check image links
runs-on: ubuntu-latest
env:
lychee_args: '--no-progress --require-https --cache --max-cache-age 8h --exclude http://www.w3.org'
steps:
- name: Checkout
uses: actions/checkout@v4
# Restore cache
- name: Restore lychee cache
id: restore-cache
uses: actions/cache/restore@v4
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-
# Extract and check URLs directly from token files (checking dumped file did not work)
- name: Check token art URLs
uses: lycheeverse/lychee-action@v2
with:
args: '${{env.lychee_args}} -- tokens.xml'
jobSummary: true
# Extract picture URLs from tokens.xml
- name: Extract URLs
id: tokens_pic_urls
uses: lycheeverse/lychee-action@v2
with:
args: '--dump --exclude www.w3.org -- tokens.xml'
output: lychee/out.md
jobSummary: false
# List some helpful stats on missing pictures
- name: List missing image link counts
shell: bash
run: |
echo "🪞 **Missing Image Links**" >> $GITHUB_STEP_SUMMARY
echo "Token with missing \`set\` element: [![](https://img.shields.io/badge/dynamic/xml?label=&colorB=white&query=count%28%2F%2Fcard%5Bnot%28set%29%5D%29&url=https%3A%2F%2Fraw.githubusercontent.com%2FCockatrice%2FMagic-Token%2Fmaster%2Ftokens.xml)](https://raw.githubusercontent.com/Cockatrice/Magic-Token/master/tokens.xml)" >> $GITHUB_STEP_SUMMARY
echo "Missing picURL attribute ( \`<set>\` ): [![](https://img.shields.io/badge/dynamic/xml?label=&colorB=white&query=count%28%2F%2Fset%29-count%28%2F%2Fset%5B%40picURL%5D%29&url=https%3A%2F%2Fraw.githubusercontent.com%2FCockatrice%2FMagic-Token%2Fmaster%2Ftokens.xml)](https://raw.githubusercontent.com/Cockatrice/Magic-Token/master/tokens.xml)" >> $GITHUB_STEP_SUMMARY
echo "Empty picURL value ( \`<set picURL="">\` ): [![](https://img.shields.io/badge/dynamic/xml?label=&colorB=white&query=count%28%2F%2Fset%5B%40picURL%3D%22%22%5D%29&url=https%3A%2F%2Fraw.githubusercontent.com%2FCockatrice%2FMagic-Token%2Fmaster%2Ftokens.xml)](https://raw.githubusercontent.com/Cockatrice/Magic-Token/master/tokens.xml)" >> $GITHUB_STEP_SUMMARY
# Analyse extracted links (1/2)
- name: List duplicated image links
if: steps.tokens_pic_urls.outcome == 'success'
shell: bash
# Remove empty lines | trim trailing integers (Scryfall) | sort | count and list duplicates
run: |
echo "🪞 **Duplicated Image Links**" >> $GITHUB_STEP_SUMMARY
grep . lychee/out.md | sed 's/\.jpg?.*/.jpg/' | sort | uniq -cd >> $GITHUB_STEP_SUMMARY
# Analyse extracted links (2/2)
- name: List image hosting sources
if: steps.tokens_pic_urls.outcome == 'success'
shell: bash
# Extract 3rd field (domain name) | remove empty lines | sort | count duplicates and list with numbers | sort descending
run: |
echo "📊 **Image Hosting Statistics**" >> $GITHUB_STEP_SUMMARY
awk -F/ '{print $3}' lychee/out.md | grep . | sort | uniq -c | sort -nr >> $GITHUB_STEP_SUMMARY
# Always save cache
- name: Save lychee cache
uses: actions/cache/save@v4
if: always()
with:
path: .lycheecache
key: ${{ steps.restore-cache.outputs.cache-primary-key }}