From 83ce4a3894beedda9e103467f45f50ee87d528e0 Mon Sep 17 00:00:00 2001 From: Ravi Patel Date: Tue, 17 Jan 2023 17:44:51 -0600 Subject: [PATCH 1/4] Add workflow for uploading WASM & JSON schema to GitHub releases --- .editorconfig | 7 +++ .github/workflows/build.yml | 28 +++++----- .github/workflows/publish.yml | 100 ++++++++++++++++++++++++++++++++++ Makefile | 4 +- 4 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.editorconfig b/.editorconfig index c1e2c64..974dfe8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,6 +3,13 @@ # top-most EditorConfig file root = true +[Makefile] +indent_style = tab + +[.github/workflows/**.{yml,yaml}] +indent_style = space +indent_size = 2 + [*] indent_style = space indent_size = 4 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 898dda5..65795ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build on: push: - branches: [ main, develop ] + branches: [ main ] pull_request: types: [ synchronize, opened, reopened, ready_for_review, converted_to_draft ] workflow_dispatch: @@ -20,6 +20,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + CARGO_TERM_COLOR: always + jobs: linting: name: Linting @@ -29,26 +32,24 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Install stable toolchain + - name: Install stable Rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable default: true - components: clippy, rustfmt - - - name: Cargo — Format - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + components: clippy - name: Cargo — Clippy uses: actions-rs/cargo@v1 + env: + RUSTFLAGS: "-D warnings" with: command: clippy - - name: Cargo — Documentation # TODO: Move to new job that publishes the docs to GitHub Pages + - name: Cargo — Check documentation uses: actions-rs/cargo@v1 + env: + RUSTDOCFLAGS: "-D warnings" with: command: doc @@ -56,7 +57,6 @@ jobs: name: Check Project Integrity runs-on: ubuntu-latest env: - CARGO_TERM_COLOR: always RUN_CODE_COVERAGE: ${{ github.event.inputs.runCodeCoverage || @@ -67,7 +67,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Install stable toolchain + - name: Install stable Rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable @@ -89,7 +89,7 @@ jobs: if: always() with: check_name: "Test Results" - pull_request_build: "commit" + pull_request_build: ${{ github.event_name == 'push' && 'commit' || 'merge' }} report_individual_runs: true files: "test-results.xml" @@ -109,5 +109,3 @@ jobs: flags: unittests fail_ci_if_error: true verbose: true - - # TODO: Add job for publishing Rustdocs to GitHub diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9391cd1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,100 @@ +name: Upload Documentation + +on: + release: + types: [ published ] + workflow_dispatch: + inputs: + targetTag: + type: string + description: The tag of the GitHub release to update + required: true + publishFiles: + type: boolean + description: Upload WASM & JSON schema to GitHub release + default: true + updateDocsSite: + type: boolean + description: Upload documentation to GitHub Pages + default: true + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + publish-files: + name: Publish Contract WASM & JSON schema + runs-on: ubuntu-latest + if: github.event.inputs.publishFiles || github.event_name == 'release' + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Generate JSON schema + run: make schema + + - name: Build & optimize WASM + run: make optimize + + - name: Get release information + id: release_info + uses: cardinalby/git-get-release-action@1.2.4 + if: github.event_name != 'release' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ github.event.inputs.targetTag }} + + - name: Upload files to GitHub release + uses: xresloader/upload-to-github-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ github.event_name == 'release' && github.event.release.id || steps.release_info.outputs.id }} + file: | + artifacts/asset_classification_smart_contract.wasm + artifacts/checksums.txt + schema/validation_oracle_smart_contract.json + overwrite: true + + upload-docs: + name: Upload Documentation to GitHub Pages + runs-on: ubuntu-latest + if: github.event.inputs.updateDocsSite || (github.event_name == 'release' && !github.event.release.prerelease) + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install stable Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + + - name: Cargo — Generate & check documentation + uses: actions-rs/cargo@v1 + env: + RUSTDOCFLAGS: '-D warnings' + with: + command: doc + + - name: Stage documentation + if: env.UPLOAD_TO_GITHUB_PAGES + run: | + # Add redirect page to inner doc index + echo "" >> ./target/doc/index.html + # Create doc deployment location + mkdir ./pages-files + # Move documentation to its configured location in settings + cp -r target/doc ./pages-files/docs + + - name: Deploy documentation to GitHub Pages + if: env.UPLOAD_TO_GITHUB_PAGES + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + branch: github-pages-for-docs + folder: pages-files diff --git a/Makefile b/Makefile index 83ba874..d9e2b4e 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ CONTAINER_RUNTIME := $(shell which docker 2>/dev/null || which podman 2>/dev/nul ### Use cosmwasm/rust-optimizer-arm64 on M1 Macs (https://hub.docker.com/r/cosmwasm/rust-optimizer-arm64) OPTIMIZER_IMAGE := cosmwasm/rust-optimizer -### 0.12.10 is the latest tag (https://hub.docker.com/r/cosmwasm/rust-optimizer/tags) -OPTIMIZER_DOCKER_TAG := 0.12.10 +### See tags here: https://hub.docker.com/r/cosmwasm/rust-optimizer/tags +OPTIMIZER_DOCKER_TAG ?= 0.12.11 .PHONY: all all: clean build fmt lint test schema docs optimize From 86156e9734c56a2dcda6a421261325f8c0344b25 Mon Sep 17 00:00:00 2001 From: Ravi Patel <82118011+rpatel-figure@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:14:07 -0600 Subject: [PATCH 2/4] Try making linting job condition more specific --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65795ec..b636890 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: linting: name: Linting runs-on: ubuntu-latest - if: github.event.inputs.linting || !github.event.pull_request.draft + if: github.event.inputs.linting || (github.event_name == 'pull_request' && !github.event.pull_request.draft) steps: - name: Checkout code uses: actions/checkout@v3 From 073b42c40021738be0d8719ad56956b831d67dd7 Mon Sep 17 00:00:00 2001 From: Ravi Patel <82118011+rpatel-figure@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:43:51 -0600 Subject: [PATCH 3/4] Remove defaults for build workflow inputs --- .github/workflows/build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b636890..4ae8448 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,11 +10,9 @@ on: linting: type: boolean description: Run the linter - default: true runCodeCoverage: type: boolean description: Run code coverage - default: true concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -27,7 +25,7 @@ jobs: linting: name: Linting runs-on: ubuntu-latest - if: github.event.inputs.linting || (github.event_name == 'pull_request' && !github.event.pull_request.draft) + if: github.event.inputs.linting || github.event_name == 'push' || (github.event_name == 'pull_request' && !github.event.pull_request.draft) steps: - name: Checkout code uses: actions/checkout@v3 From f22d91c94212706163401086f7decb5b7f52d160 Mon Sep 17 00:00:00 2001 From: Ravi Patel <82118011+rpatel-figure@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:59:28 -0600 Subject: [PATCH 4/4] Set defaults for workflow dispatch inputs to false --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ae8448..bd89783 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,9 +10,11 @@ on: linting: type: boolean description: Run the linter + default: false runCodeCoverage: type: boolean description: Run code coverage + default: false concurrency: group: ${{ github.workflow }}-${{ github.ref }}