Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] fix Substrate rustdoc link checker #2308

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-substrate-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Check latest substrate links
run: yarn; node --experimental-json-modules scripts/update-substrate.mjs; node scripts/check-substrate-release.mjs
run: yarn; node --experimental-json-modules scripts/update-substrate-links.mjs
54 changes: 0 additions & 54 deletions scripts/check-substrate-release.mjs

This file was deleted.

43 changes: 23 additions & 20 deletions scripts/update-substrate.mjs → scripts/update-substrate-links.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* This script should replace substrate rustdoc links in the md files for the latest version of substrate.
*/


import { Octokit } from "@octokit/rest";
import axios from "axios";
import fs from "fs";
Expand All @@ -10,30 +15,28 @@ import fs from "fs";
});
let latestTag = releases.data[0].tag_name;
let pastTag = releases.data[1].tag_name;
let pass = false;
while (!pass) {
let testUrl = `http://substrate.dev/rustdocs/${latestTag}/sc_service/index.html`;
try {
const res = await axios.get(testUrl);
if (res.status === 200) pass = true;
} catch (err) {
latestTag = latestTag.slice(0, -1);
}
}

let passTwo = false;
while (!passTwo) {
let testUrl = `http://substrate.dev/rustdocs/${pastTag}/sc_service/index.html`;
try {
const res = await axios.get(testUrl);
if (res.status === 200) passTwo = true;
} catch (err) {
pastTag = pastTag.slice(0, -1);
const testSubstrateDocsVersion = async (tag) => {
let tagTemp = tag;
let pass = false;

while (!pass) {
let testUrl = `http://substrate.dev/rustdocs/${tagTemp}/sc_service/index.html`;
try {
const res = await axios.get(testUrl);
if (res.status === 200) pass = true;
} catch (err) {
tagTemp = tagTemp.slice(0, -1);
if (tagTemp.length === 0) {
console.log(`NOTE: '${tag}' and variants of its prefixes are not valid Substrate rustdoc version numbers. No links to update!`);
jakehemmerle marked this conversation as resolved.
Show resolved Hide resolved
process.exit(0);
}
}
}
}

console.log("Latest tag:", latestTag);
console.log("Previous tag:", pastTag);
await testSubstrateDocsVersion(latestTag);
await testSubstrateDocsVersion(pastTag);

// Now read through all files.
const dir = fs.readdirSync("docs");
Expand Down