3030 markdown-link-check "$file"
3131 done
3232
33+ - name : Create wiki branch if not exists
34+ uses : actions/github-script@v6
35+ with :
36+ script : |
37+ try {
38+ await github.rest.repos.getBranch({
39+ owner: context.repo.owner,
40+ repo: context.repo.repo,
41+ branch: 'wiki'
42+ });
43+ } catch (error) {
44+ if (error.status === 404) {
45+ // Create wiki branch from main
46+ const mainBranch = await github.rest.repos.getBranch({
47+ owner: context.repo.owner,
48+ repo: context.repo.repo,
49+ branch: 'main'
50+ });
51+
52+ await github.rest.git.createRef({
53+ owner: context.repo.owner,
54+ repo: context.repo.repo,
55+ ref: 'refs/heads/wiki',
56+ sha: mainBranch.data.commit.sha
57+ });
58+ } else {
59+ throw error;
60+ }
61+ }
62+
3363 - name : Update wiki
3464 uses : actions/github-script@v6
3565 with :
@@ -48,14 +78,40 @@ jobs:
4878
4979 // Update each file in the wiki
5080 for (const file of files) {
51- await github.rest.repos.createOrUpdateFileContents({
52- owner: context.repo.owner,
53- repo: context.repo.repo,
54- path: `wiki/${file.name}`,
55- message: `Update wiki: ${file.name}`,
56- content: Buffer.from(file.content).toString('base64'),
57- branch: 'wiki'
58- });
81+ try {
82+ // Try to get existing file
83+ const existingFile = await github.rest.repos.getContent({
84+ owner: context.repo.owner,
85+ repo: context.repo.repo,
86+ path: `wiki/${file.name}`,
87+ ref: 'wiki'
88+ });
89+
90+ // Update existing file
91+ await github.rest.repos.createOrUpdateFileContents({
92+ owner: context.repo.owner,
93+ repo: context.repo.repo,
94+ path: `wiki/${file.name}`,
95+ message: `Update wiki: ${file.name}`,
96+ content: Buffer.from(file.content).toString('base64'),
97+ sha: existingFile.data.sha,
98+ branch: 'wiki'
99+ });
100+ } catch (error) {
101+ if (error.status === 404) {
102+ // Create new file
103+ await github.rest.repos.createOrUpdateFileContents({
104+ owner: context.repo.owner,
105+ repo: context.repo.repo,
106+ path: `wiki/${file.name}`,
107+ message: `Create wiki: ${file.name}`,
108+ content: Buffer.from(file.content).toString('base64'),
109+ branch: 'wiki'
110+ });
111+ } else {
112+ throw error;
113+ }
114+ }
59115 }
60116
61117 - name : Create wiki issue on failure
0 commit comments