-
-
Notifications
You must be signed in to change notification settings - Fork 274
168 lines (133 loc) · 6.65 KB
/
new-spec-release.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Push new spec to the website because of new spec release
on:
release:
types:
- published
jobs:
Make-PR:
name: Make PR on website repository with latest spec release
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout Current repository
uses: actions/checkout@v3
with:
path: spec
ref: ${{ github.event.release.target_commitish }}
- name: Checkout Another repository
uses: actions/checkout@v3
with:
repository: asyncapi/website
path: website
token: ${{ env.GITHUB_TOKEN }}
- name: Config git
run: |
git config --global user.name asyncapi-bot
git config --global user.email [email protected]
- name: Create branch
working-directory: ./website
run: |
git checkout -b spec-release-${{github.event.release.tag_name}}
- name: Check for previous spec file and remove it
uses: actions/github-script@v6
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const specFiles = fs.readdirSync("./website/pages/docs/reference/specification");
const nextRelease = `${{github.event.release.tag_name}}`;
const prefixRelease = nextRelease.split("-")[0];
for (const filename of specFiles) {
if (filename.startsWith(prefixRelease)) {
fs.unlinkSync(`./website/pages/docs/reference/specification/${filename}`);
}
}
- name: Copy Spec file from Current Repo to Another
working-directory: ./website
run: |
cp ../spec/spec/asyncapi.md ./pages/docs/reference/specification/${{github.event.release.tag_name}}.md
- name: Remove Table of Contents from Spec
uses: actions/github-script@v6
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const script = require('./spec/.github/scripts/remove-toc');
script(`${{github.event.release.tag_name}}`);
- name: Change the redirect file to point to latest spec
uses: actions/github-script@v6
if: ${{github.event.release.prerelease == false}}
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const startingLine = "# LATEST-SPEC-REDIRECTION:START\n";
const endingLine = "# LATEST-SPEC-REDIRECTION:END";
const releaseVersion = `${{github.event.release.tag_name}}`;
const redirectLine = `/docs/reference/specification/latest /docs/reference/specification/${releaseVersion} 302!\n`;
const redirectFile = fs.readFileSync("./website/public/_redirects", "utf-8");
const startingIndex = redirectFile.indexOf(startingLine);
const endingIndex = redirectFile.indexOf(endingLine);
if (startingIndex === -1 || endingIndex === -1) {
console.log("NOT FOUND");
return;
}
const firstHalf = redirectFile.slice(0, startingIndex + startingLine.length);
const secondHalf = redirectFile.slice(endingIndex);
const newRedirect = `${firstHalf}${redirectLine}${secondHalf}`;
fs.writeFileSync("./website/public/_redirects", newRedirect);
- name: Remove previous pre-release redirects in case of a new release
uses: actions/github-script@v6
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const startingLine = "# SPEC-REDIRECTION:START\n";
const endingLine = "# SPEC-REDIRECTION:END\n";
const releaseVersion = `${{github.event.release.tag_name}}`;
if(!releaseVersion.startsWith('v')) return;
const releaseVersionWithoutV = releaseVersion.slice(1).split("-")[0];
const redirectFile = fs.readFileSync("./website/public/_redirects", "utf-8");
const startingIndex = redirectFile.indexOf(startingLine);
const endingIndex = redirectFile.indexOf(endingLine);
if (startingIndex === -1 || endingIndex === -1) {
console.log("NOT FOUND");
return;
}
const firstHalf = redirectFile.slice(0, startingIndex + startingLine.length);
const middle = redirectFile.slice(startingIndex + startingLine.length, endingIndex);
const secondHalf = redirectFile.slice(endingIndex);
const middleWithoutPreviousPreReleaseRedirects = middle.split("\n").filter(value => !value.includes(releaseVersionWithoutV)).join("\n");
const newRedirect = `${firstHalf}${middleWithoutPreviousPreReleaseRedirects}${secondHalf}`;
fs.writeFileSync("./website/public/_redirects", newRedirect);
- name: Change the redirect file to point to specs
uses: actions/github-script@v6
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const startingLine = "# SPEC-REDIRECTION:START\n";
const releaseVersion = `${{github.event.release.tag_name}}`;
if(!releaseVersion.startsWith('v')) return;
const releaseVersionWithoutV = releaseVersion.slice(1);
const redirectLine = `/docs/reference/specification/${releaseVersionWithoutV} /docs/reference/specification/${releaseVersion} 302!\n`;
const redirectFile = fs.readFileSync("./website/public/_redirects", "utf-8");
const startingIndex = redirectFile.indexOf(startingLine);
if (startingIndex === -1) {
console.log("NOT FOUND");
return;
}
const firstHalf = redirectFile.slice(0, startingIndex + startingLine.length);
const secondHalf = redirectFile.slice(startingIndex + startingLine.length);
const newRedirect = `${firstHalf}${redirectLine}${secondHalf}`;
fs.writeFileSync("./website/public/_redirects", newRedirect);
- name: Commit and push
working-directory: ./website
run: |
git add .
git commit -m "docs(spec): ${{github.event.release.tag_name}} release"
git push https://${{ env.GITHUB_TOKEN }}@github.com/asyncapi/website
- name: Create PR
working-directory: ./website
run: |
gh pr create --title "docs(spec): ${{github.event.release.tag_name}} release" --body "New version of the specification is available and this PR introduces update to specification document on the website" --head "spec-release-${{github.event.release.tag_name}}"