-
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (61 loc) · 2.87 KB
/
main.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
name: GitBook PR and Push Check
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
gitbook_check:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v2
# Step 2: Check for GitBook PR or push
- name: Check for GitBook PR or push
id: gitbook-pr-push-check
uses: actions/github-script@v4
with:
script: |
const { data: pullRequests } = await github.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
});
const { data: pushes } = await github.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
});
// Check if there's a pull request with a head repository that matches the GitBook repository name
const hasPR = pullRequests.some(pull => pull.head.repo.full_name === 'GITBOOK_REPO_NAME');
// Check if there's a commit with a message that includes the GitBook commit keyword
const hasPush = pushes.some(push => push.commit.message.includes('GitBook: commit'));
return { pr: hasPR, push: hasPush }
# Step 3: Save last 100 trigger times
- name: Save last 100 trigger times
# Only run this step if either a pull request or push has been made to the GitBook repository
if: steps.gitbook-pr-push-check.outputs.pr == true || steps.gitbook-pr-push-check.outputs.push == true
# Save the current date and time to a temporary file in the same directory as last-trigger-times.txt
run: |
touch last-trigger-times.tmp
echo "GitHub $(date)" >> {{ github.workspace }}/last-trigger-times.tmp
git log -1 --format="%H - %an - %s" >> {{ github.workspace }}/last-trigger-times.tmp
echo "GitBook $(date)" >> {{ github.workspace }}/last-trigger-times.tmp
echo "$(date)" >> {{ github.workspace }}/last-trigger-times.tmp
git log -1 --format="%H - %an - %s" --grep="GitBook: commit" >> {{ github.workspace }}/last-trigger-times.tmp
shell: bash
# Step 4: Merge temporary file to the main file
- name: Merge temporary file to the main file
# Merge the temporary file with the main file, keeping only the last 100 lines
run: |
if [ -f {{ github.workspace }}/last-trigger-times.tmp ]; then
if [ -f {{ github.workspace }}/last-trigger-times.txt ]; then
tail -n 99 {{ github.workspace }}/last-trigger-times.txt > {{ github.workspace }}/last-trigger-times.tmp
cat {{ github.workspace }}/last-trigger-times.tmp >> {{ github.workspace }}/last-trigger-times.txt
rm {{ github.workspace }}/last-trigger-times.tmp
else
mv {{ github.workspace }}/last-trigger-times.tmp {{ github.workspace }}/last-trigger-times.txt
fi
fi