From 5741f26fb16d2c102a63fbbd825b5b23f6b4a279 Mon Sep 17 00:00:00 2001 From: denbite Date: Fri, 16 Aug 2024 18:43:40 +0200 Subject: [PATCH] ci: update workflows --- .github/workflows/deploy-dev.yml | 28 +++++++++++++ .github/workflows/deploy-production.yml | 27 ------------- .github/workflows/deploy-staging.yml | 52 ------------------------- .github/workflows/deploy-tag.yml | 38 ++++++++++++++++++ .github/workflows/pull-request.yml | 22 +++++++++++ .github/workflows/release-please.yml | 25 ++++++++++++ .github/workflows/test.yml | 32 --------------- .github/workflows/undeploy-staging.yml | 25 ------------ 8 files changed, 113 insertions(+), 136 deletions(-) create mode 100644 .github/workflows/deploy-dev.yml delete mode 100644 .github/workflows/deploy-production.yml delete mode 100644 .github/workflows/deploy-staging.yml create mode 100644 .github/workflows/deploy-tag.yml create mode 100644 .github/workflows/pull-request.yml create mode 100644 .github/workflows/release-please.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/undeploy-staging.yml diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 0000000..6a859b1 --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,28 @@ +name: Deploy contract on Dev account + +on: + push: + branches: [main] + +jobs: + deploy-dev: + name: Deploy contract + runs-on: ubuntu-latest + environment: dev.abstract-dao.testnet + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install cargo-near CLI + run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.6.4/cargo-near-installer.sh | sh + + - name: Deploy contract to ${{ vars.NEAR_ACCOUNT_ID }} + run: | + cargo near deploy "${{ vars.NEAR_ACCOUNT_ID }}" \ + without-init-call \ + network-config "${{ vars.NEAR_NETWORK }}" \ + sign-with-plaintext-private-key \ + --signer-public-key "${{ vars.NEAR_ACCOUNT_PUBLIC_KEY }}" \ + --signer-private-key "${{ secrets.NEAR_ACCOUNT_PRIVATE_KEY }}" \ + send diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml deleted file mode 100644 index f79ba71..0000000 --- a/.github/workflows/deploy-production.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Deploy to production -on: - push: - branches: [main] - -jobs: - test: - uses: ./.github/workflows/test.yml - - deploy-staging: - name: Deploy to production - needs: [test] - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install cargo-near CLI - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.6.2/cargo-near-installer.sh | sh - - name: Deploy to production - run: | - cargo near deploy "${{ vars.NEAR_CONTRACT_PRODUCTION_ACCOUNT_ID }}" \ - without-init-call \ - network-config "${{ vars.NEAR_CONTRACT_PRODUCTION_NETWORK }}" \ - sign-with-plaintext-private-key \ - --signer-public-key "${{ vars.NEAR_CONTRACT_PRODUCTION_ACCOUNT_PUBLIC_KEY }}" \ - --signer-private-key "${{ secrets.NEAR_CONTRACT_PRODUCTION_ACCOUNT_PRIVATE_KEY }}" \ - send diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml deleted file mode 100644 index 5ddc783..0000000 --- a/.github/workflows/deploy-staging.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Deploy to staging -on: - pull_request: - -jobs: - test: - uses: ./.github/workflows/test.yml - - deploy-staging: - name: Deploy to staging subaccount - permissions: - pull-requests: write - needs: [test] - runs-on: ubuntu-latest - env: - NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID: gh-${{ github.event.number }}.${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install near CLI - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.11.1/near-cli-rs-installer.sh | sh - - name: Create staging account - if: github.event.action == 'opened' || github.event.action == 'reopened' - run: | - near account create-account fund-myself "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '10 NEAR' \ - use-manually-provided-public-key "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_PUBLIC_KEY }}" \ - sign-as "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \ - network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \ - sign-with-plaintext-private-key \ - --signer-public-key "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_PUBLIC_KEY }}" \ - --signer-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \ - send - - - name: Install cargo-near CLI - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.6.2/cargo-near-installer.sh | sh - - name: Deploy to staging - run: | - cargo near deploy "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ - without-init-call \ - network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \ - sign-with-plaintext-private-key \ - --signer-public-key "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_PUBLIC_KEY }}" \ - --signer-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \ - send - - - name: Comment on pull request - env: - GH_TOKEN: ${{ github.token }} - run: | - gh pr comment "${{ github.event.number }}" --body "Staging contract is deployed to ["'`'"${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}"'`'" account](https://explorer.${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}.near.org/accounts/${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }})" diff --git a/.github/workflows/deploy-tag.yml b/.github/workflows/deploy-tag.yml new file mode 100644 index 0000000..fc8ef1d --- /dev/null +++ b/.github/workflows/deploy-tag.yml @@ -0,0 +1,38 @@ +name: Deploy contract of exact version +run-name: Deploy `${{ inputs.tag }}` version to `${{ inputs.environment }}` by @${{ github.actor }} + +on: + workflow_dispatch: + inputs: + environment: + description: "Environment to deploy to" + type: environment + required: true + tag: + description: "The tag version of release (v0.1.0)" + required: true + type: string + +jobs: + deploy-tag: + name: Deploy ${{ inputs.tag }} to ${{ inputs.environment }} + environment: ${{ inputs.environment }} + runs-on: ubuntu-latest + steps: + - name: Checkout repository to ${{ inputs.tag }} + uses: actions/checkout@v4 + with: + ref: ref/tags/${{ inputs.tag }} + + - name: Install cargo-near CLI + run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.6.1/cargo-near-installer.sh | sh + + - name: Deploy contract to ${{ vars.NEAR_ACCOUNT_ID }} + run: | + cargo near deploy "${{ vars.NEAR_ACCOUNT_ID }}" \ + without-init-call \ + network-config "${{ vars.NEAR_NETWORK }}" \ + sign-with-plaintext-private-key \ + --signer-public-key "${{ vars.NEAR_ACCOUNT_PUBLIC_KEY }}" \ + --signer-private-key "${{ secrets.NEAR_ACCOUNT_PRIVATE_KEY }}" \ + send diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..af514e5 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,22 @@ +name: Pull Request Test + +on: + pull_request: + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check Formatting + run: cargo fmt --check + + - name: Run cargo clippy + run: | + rustup component add clippy + cargo clippy --all-features --workspace --tests -- --warn clippy::all --warn clippy::nursery + + - name: Run cargo test + run: cargo test diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..e140503 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,25 @@ +on: + workflow_dispatch: + pull_request: + types: + - closed + +name: Release Please + +jobs: + release-please: + runs-on: ubuntu-latest + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(github.event.pull_request.body, 'I have created a release *beep* *boop*') && github.event.pull_request.user.login == 'denbite') + steps: + - uses: googleapis/release-please-action@v4 + id: release + name: Run release-please command + with: + # this assumes that you have created a personal access token + # (PAT) and configured it as a GitHub action secret named + token: ${{ secrets.REPOSITORY_PERSONAL_ACCESS_TOKEN }} + target-branch: main + config-file: .release-please/config.json + manifest-file: .release-please/.manifest.json + skip-github-release: false + skip-github-pull-request: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 7f847af..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Test -on: - workflow_call: - -jobs: - code-formatting: - name: Code Formatting - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - run: cargo fmt --check - - code-linter: - name: Code Linter - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Run cargo clippy - run: | - rustup component add clippy - cargo clippy --all-features --workspace --tests -- --warn clippy::all --warn clippy::nursery - - tests: - name: Tests - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Run cargo test - run: cargo test diff --git a/.github/workflows/undeploy-staging.yml b/.github/workflows/undeploy-staging.yml deleted file mode 100644 index f7d3186..0000000 --- a/.github/workflows/undeploy-staging.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Undeploy staging -on: - pull_request: - types: [closed] - -jobs: - cleanup-staging: - name: Cleanup staging account - runs-on: ubuntu-latest - env: - NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID: gh-${{ github.event.number }}.${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install near CLI - run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.11.1/near-cli-rs-installer.sh | sh - - name: Remove staging account - run: | - near account delete-account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ - beneficiary "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \ - network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \ - sign-with-plaintext-private-key \ - --signer-public-key "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_PUBLIC_KEY }}" \ - --signer-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \ - send