-
Notifications
You must be signed in to change notification settings - Fork 940
95 lines (84 loc) · 2.99 KB
/
schema-markdown-import.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
92
93
94
95
name: Generate user import reference markdown
on:
push:
tags:
- 'backend/*'
workflow_dispatch:
jobs:
import:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
- uses: actions/setup-node@v4
with:
node-version: '20.16.0'
registry-url: https://registry.npmjs.org/
- name: Checkout backend
uses: actions/checkout@v4
with:
path: hanko
- name: Checkout backend wiki
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
path: wiki
- name: Generate import markdown
working-directory: ./hanko/backend
run: |
go generate ./...
go run main.go schema markdown import
- name: Strip links of .md file endings
working-directory: ./hanko/backend
run: |
find ./.generated/docs/import -type f -name "*.md" -exec sed -i "s/\.md//g" "{}" \;
- name: Prepend version information
working-directory: ./hanko/backend
run: |
version=$(echo $GITHUB_REF_NAME | cut -f2 -d'/')
find ./.generated/docs/import -type f -name '*.md' -exec sed -i "1i\\
## Version\\
\\
\`$version\`\\
\\
" {} \;
- name: Copy generated files
working-directory: ./hanko/backend
run: |
mkdir -p $GITHUB_WORKSPACE/wiki/reference/import
rm $GITHUB_WORKSPACE/wiki/reference/import/*.md 2>/dev/null || true
cp .generated/docs/import/*.md $GITHUB_WORKSPACE/wiki/reference/import
- name: Delay check
run: |
OWNER=${{ github.repository_owner }}
NAME="$(cut -f2 -d'/' <<< ${{ github.repository }})"
HEAD_SHA="${{ github.sha }}"
STATUS="in_progress"
BASE="/repos/${OWNER}/${NAME}/actions/workflows/schema-markdown-config.yml/runs"
REQUEST_URL="${BASE}?head_sha=${HEAD_SHA}&status=${STATUS}"
SHOULD_DELAY=$(gh api "$REQUEST_URL" --jq '.total_count > 0')
if [ "$SHOULD_DELAY" = "true" ]; then
echo "Config markdown generation job in progress, delaying to avoid conflicts"
sleep 60s
else
echo "No config markdown generation job in progress, continuing"
fi
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push to wiki
working-directory: ./wiki
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
if ! git diff-index --quiet HEAD; then
version=$(echo $GITHUB_REF_NAME | cut -f2 -d'/')
git commit -m "chore: autogenerate import reference for $version"
git pull origin master --rebase
git push origin HEAD
else
echo "No changes detected, skipping commit and push."
fi