Skip to content

Commit d561c98

Browse files
authored
Initial commit
0 parents  commit d561c98

25 files changed

+4915
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM --platform=linux/amd64 node:lts-bookworm-slim
2+
SHELL ["/bin/bash", "-c"]
3+
4+
ENV NVM_DIR=/root/.nvm
5+
ENV NODE_VERSION=18.19.0
6+
7+
RUN apt update && apt install -y curl bash git tar gzip libc++-dev jq python3 build-essential
8+
9+
# Install nvm, node and npm
10+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
11+
&& . "$NVM_DIR/nvm.sh" \
12+
&& nvm install ${NODE_VERSION} \
13+
&& nvm use ${NODE_VERSION} \
14+
&& nvm alias default ${NODE_VERSION}
15+
16+
# Add node and npm to path
17+
ENV PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:${PATH}"
18+
RUN npm i -g yarn
19+
RUN yarn

.devcontainer/devcontainer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"build": {
3+
"context": ".",
4+
"dockerfile": "Dockerfile"
5+
},
6+
"features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {} },
7+
"postCreateCommand": "curl -s https://install.aztec.network | NON_INTERACTIVE=1 BIN_PATH=/usr/local/bin bash -s",
8+
"customizations": {
9+
// Configure properties specific to VS Code.
10+
"vscode": {
11+
// Set *default* container specific settings.json values on container create.
12+
"settings": {},
13+
"extensions": ["noir-lang.vscode-noir"]
14+
}
15+
},
16+
"workspaceMount": "source=${localWorkspaceFolder},target=/root/workspace,type=bind",
17+
"workspaceFolder": "/root/workspace"
18+
}

.github/scripts/fetchRelease.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
async function main() {
3+
const fetchOpts = {
4+
headers: {},
5+
};
6+
7+
if (process.env.GITHUB_TOKEN)
8+
fetchOpts.headers = { Authorization: `token ${process.env.GITHUB_TOKEN}` };
9+
10+
const res = await fetch('https://api.github.com/repos/AztecProtocol/aztec-packages/releases', fetchOpts);
11+
12+
const data = await res.json();
13+
14+
const filtered = data.filter(
15+
release => release.tag_name.includes('aztec-packages'),
16+
);
17+
18+
const latest = filtered[0].tag_name;
19+
20+
// TODO: add the prerelease to this object!
21+
// const workflowOutput = JSON.stringify({ latest });
22+
console.log(latest); // DON'T REMOVE, GITHUB WILL CAPTURE THIS OUTPUT
23+
}
24+
25+
main();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { readFileSync, writeFileSync } from 'fs';
2+
import { dirname } from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
// Read Nargo.toml
6+
const nargoContent = readFileSync('Nargo.toml', 'utf8');
7+
const versionMatch = nargoContent.match(/tag\s*=\s*"v([^"]+)"/);
8+
const version = versionMatch ? versionMatch[1] : null;
9+
10+
if (!version) {
11+
console.error('Could not find version tag in Nargo.toml');
12+
process.exit(1);
13+
}
14+
15+
// Read README.md
16+
const readmePath = 'README.md';
17+
let readmeContent = readFileSync(readmePath, 'utf8');
18+
19+
// Update the aztec-up version
20+
const updatedContent = readmeContent.replace(
21+
/aztec-up \d+\.\d+\.\d+/,
22+
`aztec-up ${version}`
23+
);
24+
25+
// Write back to README
26+
writeFileSync(readmePath, updatedContent);
27+
console.log(`Updated README.md with version ${version}`);

.github/scripts/update_contract.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
copy_to_file_path="."
4+
version_tag="$1"
5+
6+
echo "version tag: $version_tag"
7+
nargo_file_path="$copy_to_file_path/Nargo.toml"
8+
9+
repo_url="https://github.com/AztecProtocol/aztec-packages.git"
10+
contracts_path="noir-projects/noir-contracts/contracts"
11+
12+
# Check if the file exists
13+
if [ ! -f "$nargo_file_path" ]; then
14+
echo "File not found: $nargo_file_path"
15+
exit 1
16+
fi
17+
18+
# Update the tag in the Nargo.toml file
19+
while IFS= read -r line; do
20+
if [[ $line == *tag=* ]]; then
21+
# Extract the dependency name for logging purposes
22+
dependency_name=$(echo $line | grep -oP '(?<=\").+?(?=\")' | head -1)
23+
# Update the tag
24+
sed -i "s|\($dependency_name.*tag=\"\)[^\"]*|\1$version_tag|" $nargo_file_path
25+
echo "Updated tag for $dependency_name to $version_tag"
26+
fi
27+
done < <(
28+
sed -n '/^\[dependencies\]/,/^$/p' $nargo_file_path | grep -v '^\[dependencies\]' | awk NF
29+
)
30+
31+
# Extract the value of the 'name' field
32+
name_value=$(grep "^name\s*=" "$nargo_file_path" | sed 's/name\s*=\s*"\(.*\)"/\1/')
33+
34+
# Check if name_value is not empty
35+
if [ -z "$name_value" ]; then
36+
echo "Name field not found or empty in the TOML file."
37+
else
38+
echo "The value of the 'name' field is: $name_value"
39+
fi
40+
41+
# Check if this is running as a GitHub action
42+
if [ "$GITHUB_ACTIONS" == "true" ]; then
43+
tmp_dir="$GITHUB_WORKSPACE/tmp"
44+
else
45+
tmp_dir="$copy_to_file_path/tmp"
46+
fi
47+
48+
# Clone the repository into a tmp folder
49+
git clone $repo_url $tmp_dir
50+
cd $tmp_dir && git checkout $version_tag && cd ..
51+
52+
# Check if clone was successful
53+
if [ $? -eq 0 ]; then
54+
55+
# Check if the directory exists
56+
if [ -d "$tmp_dir/$contracts_path/$name_value" ]; then
57+
echo "Directory found: $name_value"
58+
cp -r $tmp_dir/$contracts_path/$name_value/src/ $copy_to_file_path/
59+
rm -rf $tmp_dir
60+
echo "Copied the contracts to $copy_to_file_path"
61+
# You can add additional commands here to handle the directory
62+
63+
# Remove docs comments from the files
64+
find "$copy_to_file_path/src" -type f -name "*.nr" | while read file; do
65+
# Remove lines starting with '// docs:'
66+
sed -i '/[ \t]*\/\/ docs:.*/d' "$file"
67+
68+
echo "Comments removed from $file"
69+
done
70+
else
71+
echo "Directory not found: $name_value"
72+
fi
73+
else
74+
echo "Failed to clone the repository"
75+
fi
76+
77+
rm -rf $tmp_dir

.github/workflows/tests.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
branches:
7+
- main
8+
- dev
9+
10+
jobs:
11+
setup-and-run:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Docker
19+
uses: docker/setup-buildx-action@v2
20+
21+
- name: Install Aztec CLI
22+
run: |
23+
curl -s https://install.aztec.network > tmp.sh
24+
bash tmp.sh <<< yes "yes"
25+
26+
- name: Update path
27+
run: echo "/home/runner/.aztec/bin" >> $GITHUB_PATH
28+
29+
- name: Set Aztec version and start sandbox
30+
run: |
31+
VERSION=0.81.0 aztec-up
32+
aztec start --sandbox &
33+
34+
- name: Install project dependencies
35+
run: yarn
36+
37+
- name: Compile, generate code, and run tests
38+
run: script -e -c "${AZTEC_NARGO:-aztec-nargo} compile"
39+
40+
- name: Codegen
41+
run: script -e -c "aztec codegen target --outdir src/artifacts"
42+
43+
- name: Change ownership # to get around Docker issues
44+
run: sudo chown -R $(whoami) ~/nargo && sudo chown -R $(whoami) ~/nargo/github.com
45+
46+
- name: Run tests
47+
run: script -e -c "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json && aztec test"
48+
49+
- name: Run scripts
50+
run: script -e -c "yarn deploy && yarn deploy-account"

.github/workflows/update.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Update Contract
2+
3+
on:
4+
# schedule:
5+
# Runs at 05:00 UTC every day
6+
# - cron: "0 5 * * *"
7+
workflow_dispatch:
8+
inputs:
9+
input1:
10+
description: "Just run it."
11+
required: false
12+
13+
permissions: write-all
14+
15+
jobs:
16+
update_contract:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
22+
- name: Get version
23+
id: versions_step
24+
run: |
25+
version_tag=$(node ./.github/scripts/fetchRelease.js)
26+
echo "::set-output name=version_tag::$version_tag"
27+
echo "Output from Node.js script: $version_tag"
28+
29+
- name: Check and update tutorials
30+
run: sudo chown $USER ./src && bash ./.github/scripts/update_contract.sh ${{ steps.versions_step.outputs.version_tag }}
31+
32+
- name: Commit and push changes
33+
run: |
34+
git config --global user.email "[email protected]"
35+
git config --global user.name "Josh"
36+
git add .
37+
git commit -m "Github Action: Update contract" -a || echo "No changes to commit"
38+
git push
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
target/
3+
src/artifacts/
4+
log/
5+
.vscode
6+
.DS_Store
7+
codegenCache.json

Nargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "easy_private_voting_contract"
3+
type = "contract"
4+
authors = [ "" ]
5+
compiler_version = ">=0.18.0"
6+
7+
[dependencies]
8+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.81.0", directory = "noir-projects/aztec-nr/aztec" }

0 commit comments

Comments
 (0)