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

chore(ci): move markdown link checker to xtask lint #778

Merged
merged 1 commit into from
Aug 31, 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
10 changes: 3 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Check for broken Markdown links
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
folder-path: 'crates, installers'
file-path: './README.md'
- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install Rust
run: |
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
[issue/449]: https://github.com/apollographql/rover/issues/449
[pull/519]: https://github.com/apollographql/rover/pull/519

- **`--routing-url` is now an optional argument to `rover subgraph publish` - [EverlastingBusgtopper], [issue/169] [pull/484]**
- **`--routing-url` is now an optional argument to `rover subgraph publish` - [EverlastingBugstopper], [issue/169] [pull/484]**

When publishing a subgraph, it is important to include a routing URL for that subgraph, so your graph router
knows where to route requests for types in a subgraph. Previously, you had to specify this argument on
every `rover subgraph publish`, but now it acts as an upsert, meaning you must include it on your first
`rover subgraph publish`, but subsequent publishes will retain the existing routing URL for a subgraph
if `--routing-url` is not specified.

[EverlastingBusgtopper]: https://github.com/EverlastingBusgtopper
[EverlastingBugstopper]: https://github.com/EverlastingBugstopper
[pull/484]: https://github.com/apollographql/rover/pull/484
[issue/169]: https://github.com/apollographql/rover/issues/169

Expand Down Expand Up @@ -1369,7 +1369,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- **Document Git Context - [JakeDawkins], [pull/262]**

We added documentation for how Rover provides Git Context to Apollo Studio.
You can read all about it [here](https://apollo-cli-docs.netlify.app/docs/rover/configuring/#git-context).
You can read all about it [here](https://apollographql.com/docs/rover/configuring/#git-context).

[JakeDawkins]: https://github.com/JakeDawkins
[pull/262]: https://github.com/apollographql/rover/pull/262
Expand Down
1 change: 1 addition & 0 deletions crates/rover-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 69 additions & 9 deletions xtask/src/tools/npm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Context, Result};
use camino::Utf8PathBuf;

use std::str;
use std::{convert::TryFrom, fs, str};

use crate::{
tools::Runner,
Expand All @@ -11,15 +11,15 @@ use crate::{
pub(crate) struct NpmRunner {
runner: Runner,
npm_installer_package_directory: Utf8PathBuf,
npm_lint_directory: Utf8PathBuf,
rover_client_lint_directory: Utf8PathBuf,
}

impl NpmRunner {
pub(crate) fn new(verbose: bool) -> Result<Self> {
let runner = Runner::new("npm", verbose)?;
let project_root = PKG_PROJECT_ROOT.clone();

let npm_lint_directory = project_root.join("crates").join("rover-client");
let rover_client_lint_directory = project_root.join("crates").join("rover-client");
let npm_installer_package_directory = project_root.join("installers").join("npm");

if !npm_installer_package_directory.exists() {
Expand All @@ -29,17 +29,17 @@ impl NpmRunner {
));
}

if !npm_lint_directory.exists() {
if !rover_client_lint_directory.exists() {
return Err(anyhow!(
"Rover's GraphQL linter package does not seem to be located here:\n{}",
&npm_lint_directory
&rover_client_lint_directory
));
}

Ok(Self {
runner,
npm_installer_package_directory,
npm_lint_directory,
rover_client_lint_directory,
})
}

Expand All @@ -64,13 +64,32 @@ impl NpmRunner {
}

pub(crate) fn update_linter(&self) -> Result<()> {
self.npm_exec(&["update"], &self.npm_lint_directory)?;
self.npm_exec(&["update"], &self.rover_client_lint_directory)?;
Ok(())
}

pub(crate) fn lint(&self) -> Result<()> {
self.npm_exec(&["install"], &self.npm_lint_directory)?;
self.npm_exec(&["run", "lint"], &self.npm_lint_directory)?;
self.npm_exec(&["install"], &self.rover_client_lint_directory)?;
self.npm_exec(&["run", "lint"], &self.rover_client_lint_directory)?;

let files = get_md_files();

crate::utils::info(&format!("{:?}", files));

for file in files {
self.npm_exec(
&[
"exec",
"--",
"markdown-link-check",
file.as_str(),
"--config=mlc_config.json",
"-v",
],
&PKG_PROJECT_ROOT,
)?;
}

Ok(())
}

Expand Down Expand Up @@ -131,3 +150,44 @@ fn assert_publish_includes(output: &CommandOutput) -> Result<()> {
))
}
}

fn get_md_files() -> Vec<Utf8PathBuf> {
let mut md_files = Vec::new();

walk_dir(PKG_PROJECT_ROOT.as_str(), &mut md_files);

md_files
}

fn walk_dir(base_dir: &str, md_files: &mut Vec<Utf8PathBuf>) {
if let Ok(entries) = fs::read_dir(base_dir) {
for entry in entries.flatten() {
if let Ok(file_type) = entry.file_type() {
if file_type.is_file() {
if let Ok(file_name) = entry.file_name().into_string() {
// the CHANGELOG is simply too large to be running this check on every PR
if file_name.ends_with(".md") && !file_name.contains("CHANGELOG") {
if let Ok(entry_path) = Utf8PathBuf::try_from(entry.path()) {
md_files.push(entry_path)
}
}
}
} else if file_type.is_dir() {
if let Ok(dir_name) = entry.file_name().into_string() {
// we can't do much if a link is broken in node_modules (and it's big!)
if dir_name != "node_modules"
// we don't need to check the Rust compiler's output for broken links
&& dir_name != "target"
// the docs have their own link checker, no need to check twice
&& dir_name != "docs"
// also no need to recurse through hidden directories
&& !dir_name.starts_with('.')
{
walk_dir(&dir_name, md_files);
}
}
}
}
}
}
}