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
2 changes: 1 addition & 1 deletion .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'alfs/**'
- 'archived/**'
- 'aries/**'
- 'congig/**'
- 'config/**'
- 'docker/**'
- 'docs/**'
- 'moon/**'
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/mono-engine-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Mono Engine deploy
on:
push:
branches:
- main
paths-ignore:
- 'alfs/**'
- 'archived/**'
- 'aries/**'
- 'config/**'
- 'docker/**'
- 'docs/**'
- 'moon/**'
- 'rust/**'
- 'scripts/**'
- 'third-party/**'
- 'toolchains/**'
- '.github/workflows/web-test.yml'
- '.github/workflows/web-deploy.yml'

jobs:
deploy-mono:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: m8q5m4u3
REPOSITORY: mega
IMAGE_TAG: mono-0.1.0-pre-release
run: |
docker buildx build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG -f ./docker/mono-engine-dockerfile .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
20 changes: 12 additions & 8 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl MonoApiService {
Ok(p_commit_id)
}

pub async fn content_diff(&self, mr_link: &str) -> Result<String, GitError> {
pub async fn content_diff(&self, mr_link: &str, listen_addr: &str) -> Result<String, GitError> {
let stg = self.context.mr_stg();
if let Some(mr) = stg.get_mr(mr_link).await.unwrap() {
let base_path = self.context.config.base_dir.clone();
Expand All @@ -330,32 +330,36 @@ impl MonoApiService {
.await
.expect("Failed to execute libra init");
// libra remote add origin http://localhost:8000/project
// TODO remove hard-code here
let git_remote = if mr.path.starts_with("/") {
format!("{}{}", listen_addr, mr.path)
} else {
format!("{}/{}", listen_addr, mr.path)
};
Command::new("libra")
.arg("remote")
.arg("add")
.arg("origin")
.arg(format!("http://localhost:8000{}", mr.path))
.arg(git_remote)
.output()
.await
.expect("Failed to execute libra remote add");
// libra fetch origin QB0X1X1K
// libra fetch origin refs/mr/PC0EPG1L
Command::new("libra")
.arg("fetch")
.arg("origin")
.arg(mr_link)
.arg(format!("refs/mr/{}", mr_link))
.output()
.await
.expect("Failed to execute libra fetch");
// libra branch QB0X1X1K origin/QB0X1X1K
// libra branch PC0EPG1L origin/mr/PC0EPG1L
Command::new("libra")
.arg("branch")
.arg(mr_link)
.arg(format!("origin/{}", mr_link))
.arg(format!("origin/mr/{}", mr_link))
.output()
.await
.expect("Failed to execute libra branch");
// libra switch QB0X1X1K
// libra switch PC0EPG1L
Command::new("libra")
.arg("switch")
.arg(mr_link)
Expand Down
2 changes: 1 addition & 1 deletion common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn generate_rich_text(content: &str) -> String {
}

pub fn mr_ref_name(mr_link: &str) -> String {
format!("refs/heads/{}", mr_link)
format!("refs/mr/{}", mr_link)
}

/// Format commit message with GPG signature<br>
Expand Down
4 changes: 2 additions & 2 deletions docker/mono-engine-dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ COPY . .

# build
RUN if [ "$BUILD_TYPE" = "release" ]; then \
cargo build -p mono --release && cargo build -p libra --release; \
cargo build --release -p mono -p libra; \
else \
cargo build -p mono && cargo build -p libra; \
cargo build -p mono -p libra; \
fi

# final image
Expand Down
33 changes: 21 additions & 12 deletions libra/src/command/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option<Strin
};
let http_client = HttpsClient::from_url(&url);

let refs = match http_client.discovery_reference(UploadPack).await {
let mut refs = match http_client.discovery_reference(UploadPack).await {
Ok(refs) => refs,
Err(e) => {
eprintln!("fatal: {}", e);
Expand All @@ -115,26 +115,28 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option<Strin

let remote_head = refs.iter().find(|r| r._ref == "HEAD").cloned();
// remote branches
let mut ref_heads = refs // DO NOT use `refs` later
let ref_heads = refs
.clone()
.into_iter()
.filter(|r| r._ref.starts_with("refs/heads"))
.collect::<Vec<_>>();

// filter by branch
if let Some(ref branch) = branch {
let branch = format!("refs/heads/{}", branch);
ref_heads.retain(|r| r._ref == branch);
let branch = if !branch.starts_with("refs") {
format!("refs/heads/{}", branch)
} else {
branch.to_owned()
};
refs.retain(|r| r._ref == branch);

if ref_heads.is_empty() {
if refs.is_empty() {
eprintln!("fatal: '{}' not found in remote", branch);
return;
}
}

let want = ref_heads
.iter()
.map(|r| r._hash.clone())
.collect::<Vec<_>>();
let want = refs.iter().map(|r| r._hash.clone()).collect::<Vec<_>>();
let have = current_have().await; // TODO: return `DiscRef` rather than only hash, to compare `have` & `want` more accurately

let mut result_stream = http_client.fetch_objects(&have, &want).await.unwrap();
Expand Down Expand Up @@ -223,10 +225,17 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option<Strin
}

/* update reference */
for r in &ref_heads {
let branch_name = r._ref.strip_prefix("refs/heads/").unwrap();
for r in &refs {
let ref_str = &r._ref;
let remote = Some(remote_config.name.as_str());
Branch::update_branch(branch_name, &r._hash, remote).await;
if let Some(branch_name) = ref_str.strip_prefix("refs/heads/") {
Branch::update_branch(branch_name, &r._hash, remote).await;
} else if let Some(mr_name) = ref_str.strip_prefix("refs/mr/") {
let branch_name = format!("mr/{}", mr_name);
Branch::update_branch(&branch_name, &r._hash, remote).await;
} else {
tracing::warn!("Unsupported ref type: {}", ref_str);
}
}
match remote_head {
Some(remote_head) => {
Expand Down
3 changes: 2 additions & 1 deletion mono/src/api/mr/mr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ async fn get_mr_files_changed(
Path(link): Path<String>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<FilesChangedList>>, ApiError> {
let res = state.monorepo().content_diff(&link).await;
let listen_addr = &state.listen_addr;
let res = state.monorepo().content_diff(&link, listen_addr).await;
let res = match res {
Ok(data) => {
let diff_files = extract_files_with_status(&data);
Expand Down