Skip to content

Commit

Permalink
feat: create repo after cloning template & commit after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux authored and jpopesculian committed Dec 7, 2024
1 parent de89287 commit d00d2d2
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 21 deletions.
52 changes: 41 additions & 11 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- '*'
- "*"
pull_request:
merge_group:
workflow_dispatch:
Expand All @@ -26,18 +26,42 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Calculate openssl-vendored
shell: bash
id: is-openssl-vendored
run: |
if [[ "${{ startsWith(matrix.target, 'x86') }}" == "true" ]]; then
echo "enabled=" >> $GITHUB_OUTPUT
else
echo "enabled=--features vendored-openssl" >> $GITHUB_OUTPUT
fi
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist
sccache: 'true'
manylinux: auto
args: --release --out dist --find-interpreter ${{ steps.is-openssl-vendored.outputs.enabled }} --features extension-module
sccache: "true"
manylinux: "manylinux2014"
before-script-linux: |
case "${{ matrix.target }}" in
"aarch64" | "armv7" | "s390x" | "ppc64le")
# NOTE: pypa/manylinux docker images are Debian based
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
sudo apt-get install -y cpanminus
sudo cpanm IPC::Cmd
;;
"x86" | "x86_64")
# NOTE: rust-cross/manylinux docker images are CentOS based
yum update -y
yum install -y openssl openssl-devel perl-IPC-Cmd
;;
esac
docker-options: -e SENTRY_DSN
env:
# Workaround ring 0.17 build issue
CFLAGS_aarch64_unknown_linux_gnu: '-D__ARM_ARCH=8'
CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand All @@ -53,14 +77,14 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist
sccache: 'true'
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand All @@ -76,13 +100,19 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Install dependencies
run: brew install openssl pkg-config
- name: Set OpenSSL path
run: echo "OPENSSL_DIR=$(brew --prefix openssl)" >> $GITHUB_ENV
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist
sccache: 'true'
sccache: "true"
env:
OPENSSL_DIR: ${{ env.OPENSSL_DIR }}
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -158,4 +188,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
53 changes: 53 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ name = "aqora"
[features]
default = []
extension-module = ["pyo3/extension-module", "pyo3/abi3-py39", "pyo3/abi3"]
vendored-openssl = ["openssl/vendored"]

[dependencies]
aqora-archiver = { path = "archiver", features = ["indicatif", "tokio", "tracing"] }
Expand Down Expand Up @@ -92,7 +93,9 @@ tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] }
url = { version = "2.5", features = ["serde"] }
uuid = "1.7"
which = "6.0"
git2 = "0.19.0"
openssl = { version = "0.10.68", features = ["vendored"], optional = true }
openssl-probe = { version = "0.1.5", optional = true }
git2 = { version = "0.19.0" , features = ["vendored-openssl"] }

[build-dependencies]
toml_edit = "0.22"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/new/use_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn use_case(args: UseCase, global: GlobalArgs) -> Result<()> {
.title(competition.title)
.render(&dest)
.map_err(|e| format_permission_error("create use case", &dest, &e))?;
init_repository(&pb, &dest, competition.short_description)
init_repository(&pb, &dest, Some(competition.short_description))
.map_err(|e| format_permission_error("initialize Git repository", &dest, &e))?;
pb.finish_with_message(format!(
"Created use case in directory '{}'",
Expand Down
25 changes: 21 additions & 4 deletions src/commands/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
download::download_archive,
error::{self, Result},
git::init_repository,
graphql_client::GraphQLClient,
};
use clap::Args;
Expand Down Expand Up @@ -99,10 +100,26 @@ pub async fn template(args: Template, global: GlobalArgs) -> Result<()> {

pb.set_message("Downloading competition template...");
match download_archive(download_url, &destination, &pb).await {
Ok(_) => pb.finish_with_message(format!(
"Competition template downloaded to {}",
destination.display()
)),
Ok(_) => {
init_repository(&pb, global.project.as_path(), None).map_err(|err| {
error::user(
&format!(
"Failed to init a local Git repository at '{}': {}",
global.project.display(),
err
),
&format!(
"Make sure you have the correct permissions for '{}'",
global.project.display()
),
)
})?;

pb.finish_with_message(format!(
"Competition template downloaded to {}",
destination.display()
))
}
Err(error) => {
pb.finish_with_message("Failed to download competition template");
return Err(error);
Expand Down
18 changes: 18 additions & 0 deletions src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
},
error::{self, Result},
evaluate::evaluate,
git::add_and_commit,
ipynb::{convert_submission_notebooks, convert_use_case_notebooks},
print::wrap_python_output,
python::LastRunResult,
Expand Down Expand Up @@ -419,6 +420,23 @@ pub async fn run_submission_tests(
),
));
}
add_and_commit(
global.project.as_path(),
format!("test: use case v{}", use_case_toml.version().unwrap()),
)
.map_err(|err| {
error::user(
&format!(
"Failed to commit to a local Git repository at '{}': {}",
global.project.display(),
err
),
&format!(
"Make sure you have the correct permissions for '{}'",
global.project.display()
),
)
})?;

result.map(|_| ())
}
Expand Down
58 changes: 54 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use git2::{Error, Repository, RepositoryInitOptions};
use git2::{Error, IndexAddOption, Oid, Repository, RepositoryInitOptions, Signature};
use indicatif::ProgressBar;
use std::path::Path;
use std::{env, path::Path};

pub fn init_repository(
pb: &ProgressBar,
dest: impl AsRef<Path>,
description: impl AsRef<str>,
description: Option<String>,
) -> Result<(), Error> {
pb.set_message("Initializing local Git repository...");
let mut opts = RepositoryInitOptions::new();
opts.description(description.as_ref()).initial_head("main");
opts.description(
description
.unwrap_or("Aqora competition".to_string())
.as_str(),
)
.no_reinit(true)
.initial_head("main");
match Repository::init_opts(dest, &opts) {
Ok(_) => {
pb.set_message("Repository initialized successfully.");
Expand All @@ -18,3 +24,47 @@ pub fn init_repository(
Err(error) => Err(error),
}
}

pub fn add_and_commit(
path: impl AsRef<Path>,
commit_message: impl AsRef<str>,
) -> Result<(), Error> {
let repository = Repository::open(path)?;
add_all_files(&repository)?;
commit_changes(&repository, commit_message)?;
Ok(())
}

fn add_all_files(repository: &Repository) -> Result<(), Error> {
let mut index = repository.index()?;
index.add_all(["*"].iter(), IndexAddOption::DEFAULT, None)?;
index.write()
}

fn commit_changes(repository: &Repository, message: impl AsRef<str>) -> Result<Oid, Error> {
let name = env::var("GIT_AUTHOR_NAME").unwrap_or("Default User".to_string());
let email = env::var("GIT_AUTHOR_EMAIL").unwrap_or("[email protected]".to_string());
let signature = Signature::now(&name, &email)?;

let mut index = repository.index()?;
let tree_oid = index.write_tree()?;
let tree = repository.find_tree(tree_oid)?;

let parent_commit = match repository.head() {
Ok(head) => Some(repository.find_commit(head.target().unwrap())?),
Err(_) => None,
};

repository.commit(
Some("HEAD"),
&signature,
&signature,
message.as_ref(),
&tree,
parent_commit
.as_ref()
.into_iter()
.collect::<Vec<_>>()
.as_slice(),
)
}

0 comments on commit d00d2d2

Please sign in to comment.