Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Aug 16, 2023
2 parents a881a65 + a466b7c commit 121ba85
Show file tree
Hide file tree
Showing 121 changed files with 4,206 additions and 747 deletions.
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.68.2"
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.68.2' }}
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/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: '{"checkdev":"true"}'
29 changes: 4 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0
toolchain: 1.68.2
components: clippy
profile: minimal
override: true
Expand All @@ -31,33 +31,12 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0
toolchain: 1.68.2
components: rustfmt
profile: minimal
override: true
- run: cargo fmt -- --check

checkbuild:
name: Actions - check artifacts hash sums
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0
components: rustfmt
profile: minimal
override: true
- name: Get hash of checksum file
id: checksum
run: echo "::set-output name=DATA::$(shasum -a 256 ./artifacts/checksums.txt | cut -f1 -d ' ')"
- name: Rebuild artifacts
run: make schema && ./build_release.sh
- name: Verify
run: if [[ "${{steps.checksum.outputs.DATA}}" != $(shasum -a 256 ./artifacts/checksums.txt | cut -f1 -d ' ') ]]; then return 2; fi

unit-test:
name: Actions - unit test
runs-on: ${{ matrix.os }}
Expand All @@ -70,10 +49,10 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0
toolchain: 1.68.2
profile: minimal
- run: cargo fetch --verbose
- run: cargo build
- run: cargo test --verbose --all
env:
RUST_BACKTRACE: 1
RUST_BACKTRACE: 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
target/
artifacts/
Loading

0 comments on commit 121ba85

Please sign in to comment.