-
Notifications
You must be signed in to change notification settings - Fork 17
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
ci: cargo near new integration test + gh workflow to autorenew image tag/digest #235
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ade0327
test: rename docker test, shorten api call
2788c6f
test: replace build of docker-build-template with build of gen prj
6024e8d
ci: add git to installed deps for test
22cc88d
ci: debug info
f9b7660
chore: add `--author=` flag to `git-commit` cmd in `new` flow
3884ecd
test: add common test_basics_on between new template and test
60be55a
ci: use env.RUST_MSRV in msrv checks
3d76a76
chore: replace toml comparison with locks comparison (near-workspaces)
7f31b6a
test: add test of `cargo test` on `cargo near new` result
4fcac35
test: add test_regular_build
46cdd06
ci: add auto-update workflow for docker tag+digest
6c9b22e
chore: wrap some CrateMetadata code into block
04c7efa
ci: add permissions clause to image update workflow
207dd03
chore: improve metadata resolve err msg
e84de7c
chore: improve logic of `find_direct_dependency`
ec5a4df
test: remove unneeded parts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: renew docker image tag and digest periodically and on-demand | ||
|
||
on: | ||
schedule: | ||
- cron: '0 1 * * *' # Runs daily at 1 hour after midnight | ||
workflow_dispatch: | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
check_latest_docker_image: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the main branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- uses: hustcer/setup-nu@v3 | ||
with: | ||
version: "*" | ||
|
||
- name: Run update script | ||
shell: nu {0} | ||
run: | | ||
let record = http get "https://hub.docker.com/v2/namespaces/sourcescan/repositories/cargo-near/tags" | get results | first; | ||
|
||
let mod_content = ( | ||
open cargo-near/src/commands/new/new-project-template/Cargo.toml.template --raw | lines | ||
| each { | ||
|line| if ($line | str starts-with "image = ") { | ||
$'image = "sourcescan/cargo-near:($record.name)"' | ||
} else { $line } | ||
} | ||
| each { | ||
|line| if ($line | str starts-with "image_digest = ") { | ||
$'image_digest = "($record.digest)"' | ||
} else { $line } | ||
} | ||
| to text | ||
); | ||
|
||
$mod_content | save -f cargo-near/src/commands/new/new-project-template/Cargo.toml.template | ||
|
||
git diff | ||
|
||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
title: update `cargo near new` template `image` and `image_digest` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,11 @@ jobs: | |
run: sudo apt-get update && sudo apt-get install --assume-yes libudev-dev | ||
|
||
- name: Cargo check | ||
env: | ||
# info: (overridden by '/home/runner/work/cargo-near/cargo-near/rust-toolchain.toml') | ||
RUSTUP_TOOLCHAIN: ${{ env.RUST_MSRV }} | ||
run: | | ||
rustc -vV | ||
cargo check -p cargo-near | ||
cargo check -p cargo-near-build --all-features | ||
|
||
|
@@ -56,9 +60,9 @@ jobs: | |
- name: "Install stable Rust toolchain" | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
# channel is really controlled by ./rust-toolchain.toml | ||
toolchain: stable | ||
default: true | ||
profile: minimal | ||
|
||
- name: Install `wasm32-unknown-unknown` | ||
run: rustup target add wasm32-unknown-unknown | ||
|
@@ -68,7 +72,10 @@ jobs: | |
run: sudo apt-get update && sudo apt-get install --assume-yes libudev-dev | ||
|
||
- name: Run tests | ||
run: cargo test --workspace | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "nearprotocol-ci" | ||
cargo test --workspace | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,4 @@ docker = [ | |
"dep:nix", | ||
"dep:shell-words", | ||
] | ||
test_code = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "cargo-near" | |
version = "0.10.1" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.78.0" | ||
rust-version = "1.79.0" | ||
description = "Cargo extension for building Rust smart contracts on NEAR" | ||
readme = "README.md" | ||
repository = "https://github.com/near/cargo-near" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ impl NewContext { | |
.replace( | ||
"cargo-near-new-ci-tool-version-self", | ||
env!("CARGO_PKG_VERSION"), | ||
) | ||
.replace( | ||
"TEST_BASICS_ON_INCLUDE", | ||
include_str!("./test_basics_on.rs.in"), | ||
), | ||
) | ||
.wrap_err_with(|| format!("Failed to write to file: {}", new_file_path.display()))?; | ||
|
@@ -96,17 +100,20 @@ impl NewContext { | |
)); | ||
} | ||
|
||
let status = std::process::Command::new("git") | ||
let child = std::process::Command::new("git") | ||
.arg("commit") | ||
.arg("-m") | ||
.arg("init") | ||
.arg("--author=nearprotocol-ci <[email protected]>") | ||
.current_dir(project_dir) | ||
.stdout(Stdio::null()) | ||
.stderr(Stdio::null()) | ||
.status()?; | ||
if !status.success() { | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
.spawn()?; | ||
let output = child.wait_with_output()?; | ||
if !output.status.success() { | ||
println!("{}", String::from_utf8_lossy(&output.stderr)); | ||
return Err(color_eyre::eyre::eyre!( | ||
"Failed to execute process: `git commit -m init`" | ||
"Failed to execute process: `git commit -m init --author='nearprotocol-ci <[email protected]>'`" | ||
)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
async fn test_basics_on(contract_wasm: &[u8]) -> Result<(), Box<dyn std::error::Error>> { | ||
let sandbox = near_workspaces::sandbox().await?; | ||
let contract = sandbox.dev_deploy(contract_wasm).await?; | ||
|
||
let user_account = sandbox.dev_create_account().await?; | ||
|
||
let outcome = user_account | ||
.call(contract.id(), "set_greeting") | ||
.args_json(json!({"greeting": "Hello World!"})) | ||
.transact() | ||
.await?; | ||
assert!(outcome.is_success()); | ||
|
||
let user_message_outcome = contract.view("get_greeting").args_json(json!({})).await?; | ||
assert_eq!(user_message_outcome.json::<String>()?, "Hello World!"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example of pr created dj8yfo/gh_self_create_pr#3 ,
it renews previous pr automatically and doesn't create one if there's no change