Skip to content

Commit 4eb32b8

Browse files
committed
fix(ci): check if release was already published
1 parent c2d093e commit 4eb32b8

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

.github/workflows/release.yaml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,29 @@ jobs:
3434
set -euo pipefail
3535
3636
publish() {
37-
echo "Publishing $1"
38-
(cd "$1" && cargo publish --locked)
39-
echo "Waiting for crates.io index to update..."
40-
sleep 25
37+
local dir="$1"
38+
pushd "$dir" >/dev/null
39+
40+
local name version
41+
name="$(
42+
cargo metadata --no-deps --format-version 1 --manifest-path Cargo.toml \
43+
| jq -r --arg mp "$PWD/Cargo.toml" '.packages[] | select(.manifest_path == $mp) | .name'
44+
)"
45+
version="$(
46+
cargo metadata --no-deps --format-version 1 --manifest-path Cargo.toml \
47+
| jq -r --arg mp "$PWD/Cargo.toml" '.packages[] | select(.manifest_path == $mp) | .version'
48+
)"
49+
50+
if curl -fsS "https://crates.io/api/v1/crates/$name/$version" >/dev/null; then
51+
echo "The crate $1 is already up to date, skipping"
52+
else
53+
echo "Publishing $1"
54+
cargo publish --locked
55+
echo "Waiting for crates.io index to update"
56+
sleep 25
57+
fi
58+
59+
popd >/dev/null
4160
}
4261
4362
publish idl/spec
@@ -64,8 +83,6 @@ jobs:
6483
contents: read
6584
environment:
6685
name: production
67-
env:
68-
NODE_ENV: production
6986
steps:
7087
- uses: actions/checkout@v4
7188

@@ -82,20 +99,27 @@ jobs:
8299
83100
publish() {
84101
local dir="$1"
85-
local name
86-
name="$(basename "$dir")"
102+
pushd "$dir" >/dev/null
103+
104+
local name version
105+
name="$(node -p "require('./package.json').name")"
106+
version="$(node -p "require('./package.json').version")"
107+
108+
if npm view "${name}@${version}" version >/dev/null 2>&1; then
109+
echo "The package $1 is already up to date, skipping"
110+
popd >/dev/null
111+
return 0
112+
fi
87113
88114
echo "Publishing $dir"
89115
pushd "$dir" >/dev/null
90116
91117
yarn
92-
93118
if [[ "$name" == spl-* ]]; then
94119
yarn build:npm
95120
else
96121
yarn build
97122
fi
98-
99123
npm publish
100124
101125
popd >/dev/null
@@ -163,9 +187,10 @@ jobs:
163187
push: true
164188
tags: ${{ steps.meta.outputs.tags }}
165189
labels: ${{ steps.meta.outputs.labels }}
190+
# TODO: swap ANCHOR_CLI to ${{ github.ref_name }}
166191
build-args: |
167192
SOLANA_CLI=v2.3.0
168-
ANCHOR_CLI=${{ github.ref_name }}
193+
ANCHOR_CLI=v0.32.1
169194
provenance: mode=max
170195
sbom: true
171196

0 commit comments

Comments
 (0)