name: Undeploy staging on: pull_request: types: [closed] jobs: # Check if a staging environment was actually created (contract changes existed) check-staging-exists: name: Check if staging environment exists runs-on: ubuntu-latest outputs: should-cleanup: ${{ steps.check.outputs.exists }} 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 uses: ./.github/actions/install-near-cli with: network: "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" rpc-url: "${{ vars.NEAR_CONTRACT_STAGING_RPC_URL }}" rpc_api_key: "${{ secrets.NEAR_CONTRACT_STAGING_RPC_API_KEY }}" - name: Check if staging account exists id: check run: | EXISTS=$(./script/ci/account-exists.sh \ --account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ --network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" || echo "") if [[ -n "$EXISTS" ]]; then echo "exists=true" >> $GITHUB_OUTPUT echo "Staging account exists, will proceed with cleanup" else echo "exists=false" >> $GITHUB_OUTPUT echo "Staging account does not exist, skipping cleanup" fi cleanup-staging: name: Cleanup staging account runs-on: ubuntu-latest needs: check-staging-exists if: needs.check-staging-exists.outputs.should-cleanup == 'true' 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 uses: ./.github/actions/install-near-cli with: network: "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" rpc-url: "${{ vars.NEAR_CONTRACT_STAGING_RPC_URL }}" rpc_api_key: "${{ secrets.NEAR_CONTRACT_STAGING_RPC_API_KEY }}" - name: Install Rust toolchain uses: dtolnay/rust-toolchain@1.86.0 - uses: actions/cache@v4 with: path: | ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Remove markets run: | ./script/ci/remove-all-markets-from-registry.sh \ --account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ --registry "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ --network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \ --private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" - name: Remove registry account run: | ./script/ci/remove-registry.sh \ --account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \ --beneficiary "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \ --network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \ --private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}"