Skip to content

Commit d86ef94

Browse files
committed
fix: race condition when CI script fails to create the contract
1 parent a4d7b6f commit d86ef94

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

.github/workflows/deploy-staging.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44

55
permissions:
66
contents: read
7-
id-token: write # Required for workflows that call test.yml (Codecov OIDC)
8-
pull-requests: write # Required for deployment comments
7+
id-token: write # Required for workflows that call test.yml (Codecov OIDC)
8+
pull-requests: write # Required for deployment comments
99

1010
jobs:
1111
# Check if we need to run contract-related jobs
@@ -72,11 +72,11 @@ jobs:
7272

7373
- name: Initialize staging account
7474
run: |
75-
EXISTS=$(./script/ci/account-exists.sh \
75+
ACCOUNT_EXISTS=$(./script/ci/account-exists.sh \
7676
--account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
7777
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}")
7878
79-
if [[ -z "$EXISTS" ]]; then
79+
if [[ -z "$ACCOUNT_EXISTS" ]]; then
8080
echo "Account does not already exist, creating"
8181
8282
near account create-account fund-myself "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '20 NEAR' \
@@ -88,19 +88,26 @@ jobs:
8888
8989
echo "NEWLY_CREATED=1" >> $GITHUB_ENV
9090
else
91-
echo "Account already exists, adding tokens and removing old market versions"
92-
9391
near tokens "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \
9492
send-near "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '6 NEAR' \
9593
network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
9694
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \
9795
send
9896
99-
./script/ci/remove-all-versions-from-registry.sh \
100-
--account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
101-
--registry "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
102-
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
103-
--private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}"
97+
CONTRACT_EXISTS=$(./script/ci/contract-exists.sh \
98+
--contract "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
99+
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}")
100+
101+
if [[ -n "$CONTRACT_EXISTS" ]]; then
102+
echo "Contract already exists on staging account, removing old market versions"
103+
# ./script/ci/remove-all-versions-from-registry.sh \
104+
# --account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
105+
# --registry "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
106+
# --network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
107+
# --private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}"
108+
else
109+
echo "NEWLY_CREATED=1" >> $GITHUB_ENV
110+
fi
104111
fi
105112
106113
- name: Deploy registry to staging account

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/ci/contract-exists.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(dirname "$(readlink -f ${BASH_SOURCE[0]})")
4+
source "$SCRIPT_DIR/utils.sh"
5+
6+
parse_args "--account:ACCOUNT_ID,--network:NETWORK" "$@"
7+
8+
if [ -z "$NETWORK" ]; then
9+
NETWORK="testnet"
10+
fi
11+
12+
near contract download-wasm ${ACCOUNT_ID} save-to-file /tmp/${ACCOUNT_ID}.wasm network-config ${NETWORK} now > /dev/null 2>&1 || true
13+
if [ -f "/tmp/${ACCOUNT_ID}.wasm" ]; then
14+
echo 1
15+
fi

0 commit comments

Comments
 (0)