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

infra: Publish nightly releases of the Router from dev source #2409

Merged
merged 17 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
48 changes: 45 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ parameters:
protoc_version:
type: string
default: "21.8"
nightly:
type: boolean
default: false

# These are common environment variables that we want to set on on all jobs.
# While these could conceivably be set on the CircleCI project settings'
Expand Down Expand Up @@ -415,6 +418,9 @@ jobs:
parameters:
platform:
type: executor
nightly:
type: boolean
default: false
executor: << parameters.platform >>
environment:
<<: *common_job_environment
Expand All @@ -424,15 +430,18 @@ jobs:
MACOS_PRIMARY_BUNDLE_ID: com.apollographql.router
steps:
- checkout
- run:
name: Initialize submodules
command: git submodule update --recursive --init
Comment on lines -427 to -429
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not related to this PR, but should no longer be necessary after #1856

- when:
condition:
equal: [*macos_build_executor, << parameters.platform >>]
steps:
- install_minimal_rust
- macos_install_baseline
# This will set the version to inlude current date and commit hash
- when:
condition:
equal: [true, << parameters.nightly >>]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist
Expand Down Expand Up @@ -461,6 +470,12 @@ jobs:
sudo apt-get update
- install_minimal_rust
- linux_amd_install_baseline
# This will set the version to inlude current date and commit hash
- when:
condition:
equal: [true, << parameters.nightly >>]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist
Expand All @@ -481,6 +496,12 @@ jobs:
sudo apt-get update
- install_minimal_rust
- linux_arm_install_baseline
# This will set the version to inlude current date and commit hash
- when:
condition:
equal: [true, << parameters.nightly >>]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist
Expand Down Expand Up @@ -515,6 +536,12 @@ jobs:
git-fetch-with-cli = true
"@
- windows_install_baseline
# This will set the version to inlude current date and commit hash
- when:
condition:
equal: [true, << parameters.nightly >>]
steps:
- run: cargo xtask release prepare nightly
- run:
command: >
cargo xtask dist
Expand All @@ -528,6 +555,8 @@ jobs:
root: artifacts
paths:
- "*"
- store_artifacts:
path: artifacts/

publish_github_release:
docker:
Expand Down Expand Up @@ -604,6 +633,8 @@ jobs:

workflows:
ci_checks:
when:
not: << pipeline.parameters.nightly >>
Comment on lines +665 to +666
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mildly frustratingly, this is a requirement of the way that CircleCI invokes workflows, so this will have to be present on each new workflow we may potentially add here in the future.

jobs:
- lint:
matrix:
Expand Down Expand Up @@ -670,7 +701,18 @@ workflows:
requires:
- prepare_patch_release_approval

nightly:
when: << pipeline.parameters.nightly >>
jobs:
- build_release:
matrix:
parameters:
platform:
abernix marked this conversation as resolved.
Show resolved Hide resolved
[macos_build, windows_build, amd_linux_build, arm_linux_build]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this doesn't currently actually publish anything to GitHub Releases like normal releases. Assuming these jobs don't start failing immediately, my next steps are to introduce a step that saves these to CircleCI artifacts:

      - store_artifacts:
          path: ./artifacts

Roughly documented here.

release:
when:
not: << pipeline.parameters.nightly >>
jobs:
- build_release:
matrix:
Expand Down
68 changes: 68 additions & 0 deletions xtask/Cargo.lock

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

1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ camino = "1"
cargo_metadata = "0.15"
chrono = "0.4.23"
flate2 = "1"
git2 = "0.16.0"
itertools = "0.10.5"
libc = "0.2"
octorust = "0.2.1"
Expand Down
97 changes: 72 additions & 25 deletions xtask/src/commands/release.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::{anyhow, Error, Result};
use cargo_metadata::MetadataCommand;
use chrono::prelude::Utc;
use git2::Repository;
use octorust::types::PullsCreateRequest;
use octorust::Client;
use std::str::FromStr;
Expand Down Expand Up @@ -28,6 +30,7 @@ enum Version {
Minor,
Patch,
Current,
Nightly,
Version(String),
}

Expand All @@ -41,6 +44,7 @@ impl FromStr for Version {
"minor" => Version::Minor,
"patch" => Version::Patch,
"current" => Version::Current,
"nightly" => Version::Nightly,
version => Version::Version(version.to_string()),
})
}
Expand Down Expand Up @@ -102,19 +106,29 @@ impl Prepare {
std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable must be set"),
),
)?;
if !self.current_branch && !self.dry_run {
self.switch_to_release_branch(&version)?;
}
self.update_install_script(&version)?;
self.update_helm_charts(&version)?;
self.update_docs(&version)?;
self.docker_files(&version)?;
self.finalize_changelog(&version)?;
self.update_lock()?;
self.check_compliance()?;
if !self.dry_run {
self.create_release_pr(&github, &version).await?;

if let Version::Nightly = &self.version {
println!("Skipping various steps becasuse this is a nightly build.");
} else {
self.update_install_script(&version)?;
self.update_helm_charts(&version)?;
self.update_docs(&version)?;
self.docker_files(&version)?;
self.finalize_changelog(&version)?;

if !self.dry_run {
if !self.current_branch {
self.switch_to_release_branch(&version)?;
}

// This also commits all changes to previously tracked files
// created by this script.
self.create_release_pr(&github, &version).await?;
}
}

Ok(())
}

Expand Down Expand Up @@ -197,6 +211,31 @@ impl Prepare {
"--package",
"apollo-router"
]),
Version::Nightly => {
let head_commit: String = match Repository::open_from_env() {
Ok(repo) => {
let revspec = repo.revparse("HEAD")?;
if revspec.mode().contains(git2::RevparseMode::SINGLE) {
let mut full_hash = revspec.from().unwrap().id().to_string();
full_hash.truncate(8);
full_hash
} else {
panic!("unexpected rev-parse HEAD");
}
}
Err(e) => panic!("failed to open: {}", e),
};

replace_in_file!(
"./apollo-router/Cargo.toml",
r#"^(?P<existingVersion>version\s*=\s*)"[^"]+""#,
format!(
"${{existingVersion}}\"0.0.0-nightly.{}+{}\"",
Utc::now().format("%Y%m%d"),
head_commit
)
);
Comment on lines +237 to +245
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deviates from the pattern used in the other arms of the match in the way which it assigns the version. It does that because cargo set-version from cargo edit doesn't ever let you set the version lower than the current version.

I considered an approach where we instead stuck the nightly on the existing version number, but it became fragile depending on the preid (e.g., alpha, beta) and it seemed most reasonable (even in terms of defining breaking changes in the spirit of semantic versioning) that 0.0.0 was a more sensical number to use on nightlies which seemed compatible with tooling (and just thought provoking enough to humans for them to consider its meaning).

}
Version::Version(version) => {
cargo!(["set-version", version, "--package", "apollo-router"])
}
Expand All @@ -205,27 +244,35 @@ impl Prepare {
let metadata = MetadataCommand::new()
.manifest_path("./apollo-router/Cargo.toml")
.exec()?;
let version = metadata
let resolved_version = metadata
.root_package()
.expect("root package missing")
.version
.to_string();
let packages = vec!["apollo-router-scaffold", "apollo-router-benchmarks"];
for package in packages {
cargo!(["set-version", &version, "--package", package])

if let Version::Nightly = version {
println!("Not changing `apollo-router-scaffold` or `apollo-router-benchmarks` because of nightly build mode.");
} else {
let packages = vec!["apollo-router-scaffold", "apollo-router-benchmarks"];
for package in packages {
cargo!(["set-version", &resolved_version, "--package", package])
}
replace_in_file!(
"./apollo-router-scaffold/templates/base/Cargo.toml",
"^apollo-router\\s*=\\s*\"[^\"]+\"",
format!("apollo-router = \"{}\"", resolved_version)
);
replace_in_file!(
"./apollo-router-scaffold/templates/base/xtask/Cargo.toml",
r#"^apollo-router-scaffold = \{\s*git\s*=\s*"https://github.com/apollographql/router.git",\s*tag\s*=\s*"v[^"]+"\s*\}$"#,
format!(
r#"apollo-router-scaffold = {{ git = "https://github.com/apollographql/router.git", tag = "v{}" }}"#,
resolved_version
)
);
}
replace_in_file!(
"./apollo-router-scaffold/templates/base/Cargo.toml",
"^apollo-router\\s*=\\s*\"[^\"]+\"",
format!("apollo-router = \"{}\"", version)
);
replace_in_file!(
"./apollo-router-scaffold/templates/base/xtask/Cargo.toml",
r#"^apollo-router-scaffold = \{\s*git\s*=\s*"https://github.com/apollographql/router.git",\s*tag\s*=\s*"v[^"]+"\s*\}$"#,
format!(r#"apollo-router-scaffold = {{ git = "https://github.com/apollographql/router.git", tag = "v{}" }}"#, version)
);

Ok(version)
Ok(resolved_version)
}

/// Update the `PACKAGE_VERSION` value in `scripts/install.sh` (it should be prefixed with `v`!)
Expand Down