Skip to content
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

init #1

Merged
merged 8 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example rate-limiter-contract_schema"
143 changes: 143 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
name: Build Contracts

on:
schedule:
- cron: '0 5 * * 1-5'
push:
branches:
- '**'
workflow_dispatch:
inputs:
toolchain:
description: 'Default Rust Toolchain'
default: "1.73.0"
required: true
type: string
target:
description: 'Default Rust Target'
default: "wasm32-unknown-unknown"
required: true
type: string
branch:
description: 'Default Branch or Commit hash to use'
default: "main"
required: true
type: string
id:
description: 'Workflow ID (Optional)'
default: "scheduled"
required: false
type: string

env:
TOOLCHAIN: ${{ inputs.toolchain || '1.73.0' }}
TARGET: ${{ inputs.target || 'wasm32-unknown-unknown' }}
REF: ${{ github.event_name == 'push' && github.ref || inputs.branch || 'main' }}
ID: ${{ inputs.id || 'scheduled' }}

jobs:
build:
name: Build & Upload contracts
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.REF }}
fetch-depth: 0
- name: Save SHA
run: echo "sha=$(/usr/bin/git log -1 --format='%H')" >> $GITHUB_ENV
- name: Check input type
run: |
if git show-ref --quiet --heads $REF; then
echo "REF is a branch"
echo "The value is $REF"
echo "REF_TYPE=branch" >> $GITHUB_ENV
BRANCH_NAME="${REF#refs/heads/}"
echo "BRANCH=${BRANCH_NAME}" >> $GITHUB_ENV
else
echo "REF is a commit hash"
echo "The value is $REF"
echo "REF_TYPE=commit" >> $GITHUB_ENV
fi
env:
REF: ${{ env.REF }}
- name: Get branch name from commit
if: ${{ env.REF_TYPE == 'commit' }}
run: |
set -x
echo "REF = ${REF}"
git show -s --pretty=%d "${REF}"
BRANCH_NAME="$(git show -s --pretty=%d "${REF}" | sed -n 's/^.*[(,]\s*origin\/\([^),]*\).*$/\1/p')"
echo "BRANCH_NAME = ${BRANCH_NAME}"
echo "BRANCH=${BRANCH_NAME}" >> $GITHUB_ENV
echo "Commit ${REF} is on branch ${BRANCH_NAME}"
env:
REF: ${{ env.REF }}
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Evaluate Artifacts in GCP
run: |
if gsutil -q stat gs://neutron-contracts/${{ github.repository }}/${{ env.sha }}/*.wasm; then
if [ ${{ env.ID }} != 'scheduled' ]; then
echo "Force Contract Building requested, continuing workflow"
echo "ARTIFACTS_EXIST=false" >> $GITHUB_ENV
else
echo "Directory already exists, stopping workflow"
echo "ARTIFACTS_EXIST=true" >> $GITHUB_ENV
fi
else
echo "Directory does not exist, continuing workflow"
echo "ARTIFACTS_EXIST=false" >> $GITHUB_ENV
fi
- name: Skip Workflow if Artifacts exist
if: ${{ env.ARTIFACTS_EXIST == 'true' }}
run: echo "::notice::Artifacts already exist in GCP Bucket, skipping workflow."
- uses: dtolnay/rust-toolchain@master
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
with:
toolchain: ${{ env.TOOLCHAIN }}
target: ${{ env.TARGET}}
components: rustfmt, clippy
- run: make schema
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- run: cargo fetch --verbose
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- run: cargo clippy --all --all-targets -- -D warnings
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- run: cargo test --verbose --all
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
env:
RUST_BACKTRACE: 1
- run: cargo fmt -- --check
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- run: make compile
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- run: make -j$(nproc) check_contracts
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
- name: 'Upload Contracts to the Cloud (repo/branch/sha)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/${{ env.sha }}/'
- name: 'Set Metadata (repo/branch/sha)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.sha }}" gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/${{ env.sha }}/'
- name: 'Upload Contracts to the Cloud (repo/branch/WF/ID)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/WF/${{ env.ID }}/'
- name: 'Set Metadata (repo/branch/WF/ID)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.sha }}" gs://neutron-contracts/${{ github.repository }}/${{ env.BRANCH }}/WF/${{ env.ID }}/'
- name: 'Upload Contracts to the Cloud (repo/sha)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil -h "Cache-Control:no-cache, no-store, must-revalidate" cp -r artifacts/* gs://neutron-contracts/${{ github.repository }}/${{ env.sha }}/'
- name: 'Set Metadata (repo/sha)'
if: ${{ env.ARTIFACTS_EXIST == 'false' }}
run: 'gsutil setmeta -r -h "x-goog-meta-Neutron-Repo: ${{ github.repository }}" -h "x-goog-meta-Neutron-Commit: ${{ env.sha }}" gs://neutron-contracts/${{ github.repository }}/${{ env.sha }}/'
- name: 'Cleanup'
if: always()
uses: AutoModality/[email protected]
57 changes: 57 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Delete old workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 30
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
required: true
default: 6
delete_workflow_pattern:
description: 'The name or filename of the workflow. if not set then it will target all workflows.'
required: false
delete_workflow_by_state_pattern:
description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: "All"
type: choice
options:
- "All"
- active
- deleted
- disabled_inactivity
- disabled_manually
delete_run_by_conclusion_pattern:
description: 'Remove workflow by conclusion: action_required, cancelled, failure, skipped, success'
required: true
default: "All"
type: choice
options:
- "All"
- action_required
- cancelled
- failure
- skipped
- success
dry_run:
description: 'Only log actions, do not perform any delete operations.'
required: false

jobs:
del_runs:
runs-on: self-hosted
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
dry_run: ${{ github.event.inputs.dry_run }}
37 changes: 37 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: PR

on:
pull_request:
types: [assigned, unassigned, labeled, unlabeled, opened, edited, closed, reopened, synchronize, converted_to_draft, ready_for_review, locked, unlocked, review_requested, review_request_removed]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]

jobs:
pr_commented:
# This job only runs for pull request comments
name: PR comment
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Send Notification
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
User @${{ github.actor }} commented PR #${{ github.event.issue.number }} "${{ github.event.issue.title }}" (${{ github.event.issue.pull_request.html_url }})

pull_requests_and_review:
name: Pull request action or review
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Send Notification
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
User @${{ github.actor }} updated PR #${{ github.event.number }} "${{ github.event.pull_request.title }}", action "${{ github.event.action }}" (${{ github.event.pull_request.html_url }})
37 changes: 37 additions & 0 deletions .github/workflows/test_trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Dispatch Workflow

concurrency: neutron-tests

on:
push:
branches:
- main
pull_request:
types:
- closed

jobs:
dispatch:
name: Dispatch Tests Workflow
runs-on: ubuntu-latest
steps:
- name: Evaluate PR Merged Status and Labels
run: |
PR_MERGED=${{ github.event.pull_request.merged }}
CONTAINS_LABEL=${{ contains(github.event.pull_request.labels.*.name, 'trigger-tests') }}
echo "PR Merged Status: $PR_MERGED"
echo "Contains 'trigger-tests' label: $CONTAINS_LABEL"
if [[ "$PR_MERGED" == "true" && "$CONTAINS_LABEL" == "true" ]]; then
echo "CONTINUE=true" >> $GITHUB_ENV
else
echo "CONTINUE=false" >> $GITHUB_ENV
fi
- name: Repository Dispatch
if: ${{ env.CONTINUE == 'true' }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.PAT_TOKEN }}
repository: neutron-org/neutron-tests
event-type: run-tests
client_payload: '{"checkratelimiter":"true"}'
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
push:
branches:
- '**'

name: tests

jobs:
clippy:
name: Actions - clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.73.0
components: clippy
profile: minimal
override: true
- run: cargo fetch --verbose
- run: cargo clippy --all --all-targets -- -D warnings

rustfmt:
name: Actions - rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.73.0
components: rustfmt
profile: minimal
override: true
- run: cargo fmt -- --check

unit-test:
name: Actions - unit test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macOS-latest, ubuntu-latest ]
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.73.0
profile: minimal
- run: cargo fetch --verbose
- run: cargo build
- run: cargo test --verbose --all
env:
RUST_BACKTRACE: 1
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Cargo
# will have compiled files and executables
target/

# These are backup files generated by rustfmt
**/*.rs.bk

.idea
.vscode
.DS_Store

artifacts/
Loading
Loading