generated from peter-evans/swagger-github-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (77 loc) · 2.88 KB
/
main.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
name: Create index.html for new swagger.yaml
on:
push:
paths:
- '**/swagger.yaml'
jobs:
create-swagger-version:
if: "contains(github.event.commits[0].message, '[CREATE-SWAGGER]')"
env:
GITHUB_TOKEN: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
GH_TOKEN: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# fetch the last 2 commits to check difference
fetch-depth: 2
- name: Check commit message
id: check-commit
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Commit message: $COMMIT_MESSAGE"
if [[ "$COMMIT_MESSAGE" != *"[BOT]"* || "$COMMIT_MESSAGE" != *"[CREATE-SWAGGER]"* ]]; then
echo "The commit message does not contain [BOT] and [CREATE-SWAGGER]. Exiting."
exit 1
fi
- name: Find new swagger.yaml files
id: find-new-swagger
run: |
git --no-pager log -5 --oneline
git status
# Find new swagger.yaml files in the commit
git diff --name-status master~1 master | grep '^A' | grep 'swagger.yaml' | awk '{print $2}' > new_swagger_files.txt
if [[ ! -s new_swagger_files.txt ]]; then
echo "No new swagger.yaml files found. Exiting."
exit 1
fi
echo "New swagger.yaml files found:"
cat new_swagger_files.txt
- name: Handle new swagger file
run: |
# Create index.html for each new swagger.yaml found
while IFS= read -r file; do
dir=$(dirname "$file")
cp utils/default_swagger_index_page.html "$dir/index.html"
version=$(basename "$dir")
parent_dir=$(dirname "$dir")
echo "Parent dir: $parent_dir"
echo "$version" >> "$parent_dir/hosted_versions.txt"
done < new_swagger_files.txt
rm new_swagger_files.txt
- name: Commit and push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "blockscout-bot"
git add .
git commit -m "[BOT] [SKIP-GH-PAGES] Add index.html for new swagger.yaml files"
git fetch origin master
if git rebase origin/master; then
git push origin master
else
git rebase --abort
echo "Rebase failed due to conflicts, exiting."
exit 1
fi
- name: Trigger github-pages workflow
uses: actions/github-script@v4
with:
github-token: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
script: |
await github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'jekyll-gh-pages.yml',
ref: 'master'
});