Skip to content
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
1 change: 1 addition & 0 deletions services/autorust/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ qstring = "0.7"

[dev-dependencies]
thiserror = "1.0"
crates_io_api = "0.8"
38 changes: 34 additions & 4 deletions services/autorust/codegen/examples/gen_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use autorust_codegen::{
crates::{list_crate_names, list_dirs},
jinja::{CargoToml, CheckAllServicesYml},
jinja::{CargoToml, CheckAllServicesYml, PublishSdksYml, PublishServicesYml},
Result,
};
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

fn main() -> Result<()> {
let dirs = list_dirs()?;
Expand All @@ -19,7 +19,37 @@ fn main() -> Result<()> {
let yml = CheckAllServicesYml { packages };
yml.create("../../.github/workflows/check-all-services.yml")?;

// let yml = PublishServicesYml { packages };
// yml.create("../../.github/workflows/publish-services.yml")?;
if std::env::args().any(|arg| arg == "publish") {
publish_sdks()?;
publish_services()?;
}
Ok(())
}

fn publish_sdks() -> Result<()> {
let packages = &vec![
"azure_core",
"azure_data_cosmos",
"azure_data_tables",
"azure_identity",
"azure_iot_hub",
"azure_messaging_eventgrid",
"azure_messaging_servicebus",
"azure_security_keyvault",
"azure_storage",
"azure_storage_blobs",
"azure_storage_datalake",
"azure_storage_queues",
];
let yml = PublishSdksYml { packages };
yml.create("../../.github/workflows/publish-sdks.yml")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be awesome to not have to rely on these very awkward relative paths.

Ok(())
}

fn publish_services() -> Result<()> {
let packages = list_crate_names()?;
let packages = &packages.iter().map(String::as_str).collect();
let yml = PublishServicesYml { packages };
yml.create("../../.github/workflows/publish-services.yml")?;
Ok(())
}
30 changes: 30 additions & 0 deletions services/autorust/codegen/examples/owned_crates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// cargo run --example owned_crates
// Validates that the GitHub team has ownership of all crates.
// If not, it prints the command to add the crate.

use autorust_codegen::crates::list_crate_names;

/// https://github.com/orgs/Azure/teams/azure-sdk-publish-rust
/// https://crates.io/teams/github:azure:azure-sdk-publish-rust
const TEAM: &str = "github:azure:azure-sdk-publish-rust";

use crates_io_api::SyncClient;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

fn main() -> Result<()> {
let client = &SyncClient::new("azure-sdk-for-rust", std::time::Duration::from_millis(1000))?;
for crate_name in &list_crate_names()? {
if !is_owner(client, crate_name)? {
println!("cargo owner --add {TEAM} -- {crate_name}")
}
}
Ok(())
}

// This looks up each crate individually.
// It would be more efficient to get a list of crates for a user if possible.
// https://github.com/theduke/crates-io-api/issues/52
fn is_owner(client: &SyncClient, crate_name: &str) -> Result<bool> {
let cr = client.full_crate(crate_name, false)?;
Ok(cr.owners.iter().any(|owner| owner.login == TEAM))
}
4 changes: 2 additions & 2 deletions services/autorust/codegen/src/crates.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{ErrorKind, Result, ResultExt};
use camino::{Utf8Path, Utf8PathBuf};
use serde::Deserialize;
use std::io::BufRead;
Expand All @@ -6,7 +7,6 @@ use std::{
io::BufReader,
str::FromStr,
};
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

/// Get all directories below the given directory.
fn list_dirs_in(dir: impl AsRef<Utf8Path>) -> Result<Vec<Utf8PathBuf>> {
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn has_version(name: &str, version: &str) -> Result<bool> {
fn get_versions(crate_name: &str) -> Result<Vec<CrateVersion>> {
// all of these crates begin with "azure".
let path = format!("../../../crates.io-index/az/ur/{}", crate_name);
let path = Utf8PathBuf::from_str(&path)?;
let path = Utf8PathBuf::from_str(&path).map_kind(ErrorKind::Parse)?;
let mut versions = Vec::new();
if path.exists() {
let file = File::open(path)?;
Expand Down
12 changes: 12 additions & 0 deletions services/autorust/codegen/src/jinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ impl<'a> PublishServicesYml<'a> {
}
}

#[derive(Template)]
#[template(path = "publish-sdks.yml.jinja")]
pub struct PublishSdksYml<'a> {
pub packages: &'a Vec<&'a str>,
}

impl<'a> PublishSdksYml<'a> {
pub fn create(&self, path: impl AsRef<Utf8Path>) -> Result<()> {
render(self, path)
}
}

#[derive(Template)]
#[template(path = "check-all-services.yml.jinja")]
pub struct CheckAllServicesYml<'a> {
Expand Down
21 changes: 21 additions & 0 deletions services/autorust/codegen/templates/publish-sdks.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish SDKs

on:
workflow_dispatch:

# Do NOT add your CARGO_REGISTRY_TOKEN to Azure/azure-sdk-for-rust repository. Only add it to your repository.
# The publish actions are intended for running in your own fork where only you have access to run the actions.
env:
CARGO_REGISTRY_TOKEN: {% raw %}${{ secrets.CARGO_REGISTRY_TOKEN }}{% endraw %}

jobs:
{% for package in packages %}
{{package}}:
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: publish
run: |
cargo publish -p {{package}}
{% endfor %}