diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index 33e245f09..91e4875f9 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -13,7 +13,7 @@ on: - 'alfs/**' - 'archived/**' - 'aries/**' - - 'congig/**' + - 'config/**' - 'docker/**' - 'docs/**' - 'moon/**' diff --git a/.github/workflows/mono-engine-deploy.yml b/.github/workflows/mono-engine-deploy.yml new file mode 100644 index 000000000..461c266c0 --- /dev/null +++ b/.github/workflows/mono-engine-deploy.yml @@ -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 \ No newline at end of file diff --git a/ceres/src/api_service/mono_api_service.rs b/ceres/src/api_service/mono_api_service.rs index 46923c2c9..73677f33e 100644 --- a/ceres/src/api_service/mono_api_service.rs +++ b/ceres/src/api_service/mono_api_service.rs @@ -308,7 +308,7 @@ impl MonoApiService { Ok(p_commit_id) } - pub async fn content_diff(&self, mr_link: &str) -> Result { + pub async fn content_diff(&self, mr_link: &str, listen_addr: &str) -> Result { 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(); @@ -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) diff --git a/common/src/utils.rs b/common/src/utils.rs index 36d5a6c25..989266eba 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -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
diff --git a/docker/mono-engine-dockerfile b/docker/mono-engine-dockerfile index c0dec30c4..549571649 100644 --- a/docker/mono-engine-dockerfile +++ b/docker/mono-engine-dockerfile @@ -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 diff --git a/libra/src/command/fetch.rs b/libra/src/command/fetch.rs index c60ff0c8f..10cd8524b 100644 --- a/libra/src/command/fetch.rs +++ b/libra/src/command/fetch.rs @@ -100,7 +100,7 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option refs, Err(e) => { eprintln!("fatal: {}", e); @@ -115,26 +115,28 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option>(); // 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::>(); + let want = refs.iter().map(|r| r._hash.clone()).collect::>(); 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(); @@ -223,10 +225,17 @@ pub async fn fetch_repository(remote_config: &RemoteConfig, branch: Option { diff --git a/mono/src/api/mr/mr_router.rs b/mono/src/api/mr/mr_router.rs index 3dd98c28f..f2d5c9a8d 100644 --- a/mono/src/api/mr/mr_router.rs +++ b/mono/src/api/mr/mr_router.rs @@ -235,7 +235,8 @@ async fn get_mr_files_changed( Path(link): Path, state: State, ) -> Result>, 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);