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: auto bump versions in our windows/nix install scripts #332

Merged
merged 5 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ members = [".", "crates/*", "installers/binstall"]
[build-dependencies]
anyhow = "1"
camino = "1.0"
regex = "1"
which = "4.0.2"
75 changes: 71 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use anyhow::{anyhow, Context, Error, Result};
use camino::{Utf8Path, Utf8PathBuf};
use regex::bytes::Regex;

use std::{
env, fs,
path::PathBuf,
process::{Command, Output},
str,
};

use camino::{Utf8Path, Utf8PathBuf};

/// files to copy from the repo's root directory into the npm tarball
const FILES_TO_COPY: &[&str; 2] = &["LICENSE", "README.md"];

Expand All @@ -24,6 +25,7 @@ fn main() -> Result<()> {
}
}

prep_installer_versions()?;
prep_npm(is_release_build)
}

Expand All @@ -35,6 +37,71 @@ fn cargo_warn(message: &str) {
println!("cargo:warn=/!\\ {}", message);
}

/// prep_installer_versions prepares our curl/iwr installers
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
/// with the Cargo.toml version
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
fn prep_installer_versions() -> Result<()> {
let scripts_dir = get_binstall_scripts_root();
prep_nix_installer(&scripts_dir)?;
prep_windows_installer(&scripts_dir)
}

/// prep_nix_installer updates our curl installer with the Cargo.toml version
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
fn prep_nix_installer(parent: &Utf8Path) -> Result<()> {
let installer = Utf8PathBuf::from(parent).join("nix").join("install.sh");
let old_installer_contents = fs::read_to_string(installer.as_path())
.context("Could not read contents of nix installer to a String")?;
let version_regex = Regex::new(r#"(?:PACKAGE_VERSION="v){1}(.*)"{1}"#)
.context("Could not create regular expression for nix installer version replacer")?;
let old_version = str::from_utf8(
version_regex
.captures(old_installer_contents.as_bytes())
.expect("Could not find PACKAGE_VERSION in nix/install.sh")
.get(1)
.expect("Could not find the version capture group in nix/install.sh")
.as_bytes(),
)
.context("Capture group is not valid UTF-8")?;
let new_installer_contents = old_installer_contents.replace(old_version, PKG_VERSION);
fs::write(installer.as_path(), &new_installer_contents)
.context("Could not write updated PACKAGE_VERSION to nix/install.sh")?;
Ok(())
}

/// prep_windows_installer updates our windows installer with the Cargo.toml version
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
fn prep_windows_installer(parent: &Utf8Path) -> Result<()> {
let installer = Utf8PathBuf::from(parent)
.join("windows")
.join("install.ps1");
let old_installer_contents = fs::read_to_string(installer.as_path())
.context("Could not read contents of windows installer to a String")?;
let version_regex = Regex::new(r#"(?:\$package_version = 'v){1}(.*)'{1}"#)
.context("Could not create regular expression for windows installer version replacer")?;
let old_version = str::from_utf8(
version_regex
.captures(old_installer_contents.as_bytes())
.expect("Could not find $package_version in windows/install.ps1")
.get(1)
.expect("Could not find the version capture group in windows/install.ps1")
.as_bytes(),
)
.context("Capture group is not valid UTF-8")?;
let new_installer_contents = old_installer_contents.replace(old_version, PKG_VERSION);
fs::write(installer.as_path(), &new_installer_contents)
.context("Could not write updated $package_version to windows/install.ps1")?;
Ok(())
}

/// get_binstall_scripts_root gets the parent directory
/// of our nix/windows install scripts
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
fn get_binstall_scripts_root() -> Utf8PathBuf {
let root_directory = Utf8PathBuf::new();

root_directory
.join("installers")
.join("binstall")
.join("scripts")
}

/// prep_npm prepares our npm installer package for release
/// by default this runs on every build and does all the steps
/// if the machine has npm installed.
Expand Down Expand Up @@ -82,7 +149,7 @@ fn prep_npm(is_release_build: bool) -> Result<()> {
install_dependencies(&npm_install_path, &npm_dir)
.context("Could not install dependencies.")?;

update_version(&npm_install_path, &npm_dir)
update_npm_version(&npm_install_path, &npm_dir)
.context("Could not update version in package.json.")?;

if is_release_build {
Expand Down Expand Up @@ -132,7 +199,7 @@ fn install_dependencies(npm_install_path: &Utf8Path, npm_dir: &Utf8Path) -> Resu
process_command_output(&command_output).context("Could not print output of 'npm install'.")
}

fn update_version(npm_install_path: &Utf8Path, npm_dir: &Utf8Path) -> Result<()> {
fn update_npm_version(npm_install_path: &Utf8Path, npm_dir: &Utf8Path) -> Result<()> {
let command_output = Command::new(npm_install_path)
.current_dir(npm_dir)
.arg("version")
Expand Down
2 changes: 2 additions & 0 deletions installers/binstall/scripts/nix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set -u
BINARY_DOWNLOAD_PREFIX="https://github.com/apollographql/rover/releases/download"

# Rover version defined in root cargo.toml
# Note: this line is built automatically
# in build.rs. Don't touch it!
PACKAGE_VERSION="v0.0.3"

download_binary_and_run_installer() {
Expand Down
2 changes: 2 additions & 0 deletions installers/binstall/scripts/windows/install.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# version found in Rover's Cargo.toml
# Note: this line is built automatically
# in build.rs. Don't touch it!
$package_version = 'v0.0.3'

function Install-Binary() {
Expand Down