Skip to content

Commit

Permalink
Fix rebase issues and support act in CI (#6179)
Browse files Browse the repository at this point in the history
- Support `act` in ci.yml for local testing
- Add documentation for `act` testing
- Add `act` binary to .gitignore
- Version bump differences
- Test fixtures
- Minor changes for errors and typos
  • Loading branch information
alfiedotwtf committed Sep 16, 2024
1 parent 2dc5618 commit 8c73032
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 32 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ jobs:
toolchain: ${{ env.RUST_VERSION }}
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- name: Install clang
if: ${{ env.ACT }}
run: dpkg -l clang || apt-get update && apt-get install -y clang
- name: Install Forc
run: cargo install --locked --debug --path ./forc
- name: Initialize test project
Expand Down Expand Up @@ -423,32 +426,40 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v3
- name: Install toolchain
- name: Install Rust toolchain
if: ${{ !env.ACT }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2
- name: Enable Rust caching
if: ${{ !env.ACT }}
uses: Swatinem/rust-cache@v2
- name: Install Forc
if: ${{ !env.ACT }}
run: cargo install --locked --debug --path ./forc
- name: Run benchmarks
if: ${{ !env.ACT }}
run: ./benchmark.sh
- name: Checkout benchmark data
if: github.event_name != 'push'
if: ${{ !env.ACT && github.event_name != 'push' }}
uses: actions/checkout@v3
with:
repository: FuelLabs/sway-performance-data
path: performance-data
token: ${{ secrets.CI_ACCOUNT_PAT }}
- name: Checkout benchmark data
if: github.event_name == 'push'
if: ${{ !env.ACT && github.event_name == 'push' }}
uses: actions/checkout@v3
with:
repository: FuelLabs/sway-performance-data
path: performance-data
token: ${{ secrets.CI_ACCOUNT_PAT }}
- name: Prepare benchmarks data for commit
if: github.event_name == 'push'
if: ${{ !env.ACT && github.event_name == 'push' }}
run: ./benchmark.sh --prepare-for-commit
- uses: EndBug/add-and-commit@v9
- name: Commit benchmark data
if: ${{ !env.ACT }}
uses: EndBug/add-and-commit@v9
with:
cwd: "./performance-data"
message: "Updated benchmark data"
Expand Down Expand Up @@ -542,7 +553,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup Rust and cargo-nextest
uses: moonrepo/setup-rust@v0
uses: moonrepo/setup-rust@v1
with:
channel: stable
cache-target: release
Expand Down Expand Up @@ -588,7 +599,8 @@ jobs:
- name: Install cargo-udeps
run: cargo install --locked cargo-udeps
- name: Check Unused Deps
run: cargo udeps --locked --all-targets
# cargo udeps will fail if the cache is empty on first go, so try one more time
run: cargo udeps --locked --all-targets || cargo udeps --locked --all-targets

notify-slack-on-failure:
needs:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ forc-plugins/forc-debug/tests/**/Forc.lock
examples/**/*/Forc.lock
docs/reference/src/code/examples/**/*/Forc.lock

# `act` for local GitHub Actions
bin/act

# Insta files
*.snap.new
26 changes: 26 additions & 0 deletions docs/book/src/reference/contributing_to_sway.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ _n_ tests run (0 skipped)

Congratulations! You've now got everything setup and are ready to start making contributions.

### Running GitHub Actions Workflow Locally

All [GitHub](https://github.com/) pull requests are run through the [GitHub Actions workflow](https://docs.github.com/en/actions) defined in `.github/workflows/ci.yml`. For convenience, these can be run locally in [Docker](https://www.docker.com/) using a 3rd-party tool called [`act`](https://github.com/nektos/act):

```sh
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
./bin/act pull_request \
-P buildjet-4vcpu-ubuntu-2204=catthehacker/ubuntu:act-latest \
-P buildjet-8vcpu-ubuntu-2204=catthehacker/ubuntu:act-latest \
-P ubuntu-latest=catthehacker/ubuntu:act-latest \
-W .github/workflows/ci.yml \
| tee output.txt
```

By default `act` will run all jobs within `.github/workflows/ci.yml`, but you can narrow down to a single job using the `-j` argument:

```sh
./bin/act pull_request \
-P buildjet-4vcpu-ubuntu-2204=catthehacker/ubuntu:act-latest \
-P buildjet-8vcpu-ubuntu-2204=catthehacker/ubuntu:act-latest \
-P ubuntu-latest=catthehacker/ubuntu:act-latest \
-W .github/workflows/ci.yml \
-j cargo-clippy \
| tee output.txt
```

## Finding something to work on

There are many ways in which you may contribute to the Sway project, some of which involve coding knowledge and some which do not. A few examples include:
Expand Down
15 changes: 10 additions & 5 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl Built {
impl BuildPlan {
/// Create a new build plan for the project from the build options provided.
///
/// To do so, it tries to read the manifet file at the target path and creates the plan with
/// To do so, it tries to read the manifest file at the target path and creates the plan with
/// `BuildPlan::from_lock_and_manifest`.
pub fn from_pkg_opts(pkg_options: &PkgOpts) -> Result<Self> {
let path = &pkg_options.path;
Expand Down Expand Up @@ -2081,10 +2081,15 @@ fn build_profile_from_opts(
.get(selected_profile_name)
.cloned()
.unwrap_or_else(|| {
println_warning(&format!(
"The provided profile option {selected_profile_name} is not present in the manifest file. \
Using default profile."
));
if selected_profile_name.is_empty() {
println_warning("No profile provided. Using default profile.");
}
else {
println_warning(&format!(
"The provided profile option '{selected_profile_name}' is not present in the manifest \
file. Using default profile."
));
}
BuildProfile::default()
});
profile.name = selected_profile_name.into();
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ async fn test_deploy_fresh_proxy() {
node.kill().unwrap();
let impl_contract = DeployedContract {
id: ContractId::from_str(
"50fe882cbef5f3da6da82509a66b7e5e0a64a40d70164861c01c908a332198ae",
"47fd96252869c61cc26e8274a7991c8d97bf522d4742036ce09699af59524cbb",
)
.unwrap(),
proxy: Some(
ContractId::from_str(
"8eae70214f55d25a65608bd288a5863e7187fcf65705143ee1a45fd228dacc19",
"a325d26e72eb664e3d080e547a7cd8824256e37bccad508aedeec5e24fc20cc7",
)
.unwrap(),
),
Expand Down
8 changes: 4 additions & 4 deletions forc/tests/cli_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ fn test_forc_test_raw_logs() -> Result<(), rexpect::error::Error> {
// Assert that the output is correct
process.exp_string(" test test_log_4")?;
process.exp_string("Raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12596,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(" test test_log_2")?;
process.exp_string("Raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12596,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;

process.process.exit()?;
Ok(())
Expand All @@ -74,11 +74,11 @@ fn test_forc_test_both_logs() -> Result<(), rexpect::error::Error> {
process.exp_string(" test test_log_4")?;
process.exp_string("Decoded log value: 4, log rb: 1515152261580153489")?;
process.exp_string("Raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12596,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(" test test_log_2")?;
process.exp_string("Decoded log value: 2, log rb: 1515152261580153489")?;
process.exp_string("Raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12596,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.process.exit()?;
Ok(())
}
2 changes: 1 addition & 1 deletion sway-lsp/src/utils/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ impl KeywordDocs {
let name = ident.trim_end_matches("_keyword").to_owned();
let mut documentation = String::new();
keyword.attrs.iter().for_each(|attr| {
let tokens = attr.to_token_stream();
let tokens = attr.meta.clone().into_token_stream();
let lit = extract_lit(tokens);
writeln!(documentation, "{lit}").unwrap();
});
Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ fn hover_docs_for_functions_vscode() {
req_uri: &uri,
req_line: 20,
req_char: 14,
documentation: vec!["```sway\npub fn bar(p: Point) -> Point\n```\n---\n A function declaration with struct as a function parameter\n\n---\nGo to [Point](command:sway.goToLocation?%5B%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A5%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A2%7D%7D%2C%22uri%22%3A%22file","sway%2Fsway-lsp%2Ftests%2Ffixtures%2Ftokens%2Ffunctions%2Fsrc%2Fmain.sw%22%7D%5D \"functions::Point\")"],
documentation: vec!["```sway\npub fn bar(p: Point) -> Point\n```\n---\n A function declaration with struct as a function parameter\n\n---\nGo to [Point](command:sway.goToLocation?%5B%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A5%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A2%7D%7D%2C%22uri%22%3A%22file","sway-lsp%2Ftests%2Ffixtures%2Ftokens%2Ffunctions%2Fsrc%2Fmain.sw%22%7D%5D \"functions::Point\")"],
};
lsp::hover_request(&server, &hover).await;
let _ = server.shutdown_server();
Expand Down Expand Up @@ -1784,7 +1784,7 @@ fn hover_docs_for_self_keywords_vscode() {

lsp::hover_request(&server, &hover).await;
hover.req_char = 24;
hover.documentation = vec!["```sway\nstruct MyStruct\n```\n---\n\n---\n[2 implementations](command:sway.peekLocations?%5B%7B%22locations%22%3A%5B%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A4%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A2%7D%7D%2C%22uri%22%3A%22file","sway%2Fsway-lsp%2Ftests%2Ffixtures%2Fcompletion%2Fsrc%2Fmain.sw%22%7D%2C%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A14%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A6%7D%7D%2C%22uri%22%3A%22file","sway%2Fsway-lsp%2Ftests%2Ffixtures%2Fcompletion%2Fsrc%2Fmain.sw%22%7D%5D%7D%5D \"Go to implementations\")"];
hover.documentation = vec!["```sway\nstruct MyStruct\n```\n---\n\n---\n[2 implementations](command:sway.peekLocations?%5B%7B%22locations%22%3A%5B%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A4%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A2%7D%7D%2C%22uri%22%3A%22file","sway-lsp%2Ftests%2Ffixtures%2Fcompletion%2Fsrc%2Fmain.sw%22%7D%2C%7B%22range%22%3A%7B%22end%22%3A%7B%22character%22%3A1%2C%22line%22%3A14%7D%2C%22start%22%3A%7B%22character%22%3A0%2C%22line%22%3A6%7D%7D%2C%22uri%22%3A%22file","sway-lsp%2Ftests%2Ffixtures%2Fcompletion%2Fsrc%2Fmain.sw%22%7D%5D%7D%5D \"Go to implementations\")"];
lsp::hover_request(&server, &hover).await;
let _ = server.shutdown_server();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::hash::*;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0x14ed3cd06c2947248f69d54bfa681fe40d26267be84df7e19e253622b7921bbe;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0xf9f1fec713b977865880637fc24e58cda9e69f6e711ed8e5efe7de9ce51c88ec; // AUTO-CONTRACT-ID ../../test_contracts/array_of_structs_contract --release
const CONTRACT_ID = 0x59dd4d4919defc3ca2ab8712550fa9495fee6279cd858c4e635521d05dbcd0c0; // AUTO-CONTRACT-ID ../../test_contracts/array_of_structs_contract --release

fn get_address() -> Option<std::address::Address> {
Some(CONTRACT_ID.into())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use test_fuel_coin_abi::*;
#[cfg(experimental_new_encoding = false)]
const FUEL_COIN_CONTRACT_ID = 0xec2277ebe007ade87e3d797c3b1e070dcd542d5ef8f038b471f262ef9cebc87c;
#[cfg(experimental_new_encoding = true)]
const FUEL_COIN_CONTRACT_ID = 0xf2fecff29038dab2ef571397ea5507359265c9154608e7de36ccbea20ed5c8aa;
const FUEL_COIN_CONTRACT_ID = 0x8ada7184b9acc22a124ff9b836cc7af2b86d872d319aefd0035bc8d5da73515d;

#[cfg(experimental_new_encoding = false)]
const BALANCE_CONTRACT_ID = 0xf6cd545152ac83225e8e7df2efb5c6fa6e37bc9b9e977b5ea8103d28668925df;
#[cfg(experimental_new_encoding = true)]
const BALANCE_CONTRACT_ID = 0xccf637b5b0071861f3074fcf963ef2339dab5d306d919b4c7e65024a7fbc64e6; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release
const BALANCE_CONTRACT_ID = 0x5ee90442589b20a58dfd6ff911440ba77709bda043de8b3221d6e0b12b72ec3e; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release

fn main() -> bool {
let default_gas = 1_000_000_000_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use balance_test_abi::BalanceTest;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0xf6cd545152ac83225e8e7df2efb5c6fa6e37bc9b9e977b5ea8103d28668925df;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0xccf637b5b0071861f3074fcf963ef2339dab5d306d919b4c7e65024a7fbc64e6; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release
const CONTRACT_ID = 0x5ee90442589b20a58dfd6ff911440ba77709bda043de8b3221d6e0b12b72ec3e; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release

fn main() -> bool {
let balance_test_contract = abi(BalanceTest, CONTRACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use basic_storage_abi::{BasicStorage, Quad};
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0x94db39f409a31b9f2ebcadeea44378e419208c20de90f5d8e1e33dc1523754cb;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0x23afacfc8eaa13d36c3f2f4d764b66e53d284e4cd31477e8bd72b4ccc411022b; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release
const CONTRACT_ID = 0xecc65bf7cfa323e4863b034efbcb6974ba6f45d795692a88d724a4c8dc833a5b; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release

fn main() -> u64 {
let addr = abi(BasicStorage, CONTRACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dynamic_contract_call::*;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0xd1b4047af7ef111c023ab71069e01dc2abfde487c0a0ce1268e4f447e6c6e4c2;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0x5229470a8bb907a909aba79325a347bd8849a8aceb9c8116e3d1c73ea4977b6d; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release
const CONTRACT_ID = 0x49b3355ebe3d9148e93e6675a6b82d61bbb1dda21fea0199f2a49b1caf7fe0e9; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release

fn main() -> bool {
let the_abi = abi(Incrementor, CONTRACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use storage_enum_abi::*;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0xc601d11767195485a6654d566c67774134668863d8c797a8c69e8778fb1f89e9;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0x4bb9cb0a4b3df7981e702609cbce4b684b3d9c21e474e9988825f48fae81b06d; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release
const CONTRACT_ID = 0xabbd5fe31028e34f224c33cacbeca41de56bbe9eefee4cbe642c93de2e274f47; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release

fn main() -> u64 {
let caller = abi(StorageEnum, CONTRACT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use auth_testing_abi::AuthTesting;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0xc2eec20491b53aab7232cbd27c31d15417b4e9daf0b89c74cc242ef1295f681f;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0xbbd538c6fc4f6a805b4e178529e1460453aee648b5e49949bdfc8a12a585e7d2; // AUTO-CONTRACT-ID ../../test_contracts/auth_testing_contract --release
const CONTRACT_ID = 0x8422c350d493719dc688581b4666ecdcda39df4105a8d4dfc96f96f3066ca9e8; // AUTO-CONTRACT-ID ../../test_contracts/auth_testing_contract --release

// should be false in the case of a script
fn main() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use context_testing_abi::*;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0x6054c11cda000f5990373a4d61929396165be4dfdd61d5b7bd26da60ab0d8577;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0x7821bf368390972d4892e1f382fd954fea5b567e533eed6fac0f173800647945; // AUTO-CONTRACT-ID ../../test_contracts/context_testing_contract --release
const CONTRACT_ID = 0x82d2d8a19e7a3c21eeef5db4e5709000c5803f96d67789576f55c52f4ad447ae; // AUTO-CONTRACT-ID ../../test_contracts/context_testing_contract --release

fn main() -> bool {
let gas: u64 = u64::max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::hash::*;
#[cfg(experimental_new_encoding = false)]
const CONTRACT_ID = 0x3bc28acd66d327b8c1b9624c1fabfc07e9ffa1b5d71c2832c3bfaaf8f4b805e9;
#[cfg(experimental_new_encoding = true)]
const CONTRACT_ID = 0x3da675876942326fd4c66b079216742f75e5f15681271a5db54a9cf19a813b22; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release
const CONTRACT_ID = 0xf012aa4a68ffac291acd5d8b79b6a76f3e444869cf2302e0b712103b3e5b4ad5; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release

fn main() -> bool {
let caller = abi(StorageAccess, CONTRACT_ID);
Expand Down

0 comments on commit 8c73032

Please sign in to comment.