-
Notifications
You must be signed in to change notification settings - Fork 20
98 lines (79 loc) · 3.62 KB
/
cron.yaml
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
92
93
94
95
96
97
98
name: cron
on:
schedule:
- cron: "0 15 * * *" # 00:00 JST
jobs:
# https://zenn.dev/snowcait/articles/903d86d668fcb7
deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
# https://stackoverflow.com/questions/72851548/permission-denied-to-github-actionsbot#answer-76645503
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
contents: write
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: mbstring
- uses: actions/checkout@v4
- name: Get Composer cache directory path
id: composer-cache-dir-path
run: echo "path=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache-dir-path.outputs.path }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev
- name: Build JSON files
run: bin/console build
- name: Check sizes of JSON files
run: |
# The largest file should be smaller thant 30000 bytes
test $(du -ab docs/api/v1 | sort -nr | head -2 | tail -1 | awk '{print $1}') -lt 30000
# The smallest file should be larger than 300 bytes
test $(du -ab docs/api/v1 | sort -n | head -1 | awk '{print $1}') -gt 300
- name: Check diff
id: diff
run: |
git add -N .
git diff --name-only --exit-code
continue-on-error: true
- name: Commit and push to GitHub if needed
if: steps.diff.outcome == 'failure'
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
run: |
set -x
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git add .
git commit --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" -m "Automatically committed"
git push
# prevent scheduled workflows from being disabled automatically
# https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow
ensure_activity:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Get current date
id: now
run: echo "date=$(date +%s)" >> $GITHUB_OUTPUT
- name: Get last commit date
id: last_commit
run: echo "date=$(git log -1 --format=%ct)" >> $GITHUB_OUTPUT
- name: Calculate date difference
id: diff
run: echo "days=$(expr \( ${{ steps.now.outputs.date }} - ${{ steps.last_commit.outputs.date }} \) / 86400)" >> $GITHUB_OUTPUT
- name: Push to GitHub an empty commit if needed
if: ${{ steps.diff.outputs.days >= 59 }}
run: |
set -x
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit --allow-empty --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" -m "Empty commit to ensure activity" -m "" -m "see: https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow#:~:text=In%20a%20public%20repository%2C%20scheduled%20workflows%20are%20automatically%20disabled%20when%20no%20repository%20activity%20has%20occurred%20in%2060%20days."
git push