-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (143 loc) · 6.33 KB
/
Copy pathdev-publish.yml
File metadata and controls
165 lines (143 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Dev publish
# Publish a dev-tagged snapshot of @parity/truapi-provider without moving
# `latest`. Stable releases go through release.yml.
on:
workflow_dispatch:
inputs:
npm_tag_suffix:
description: 'Optional dev dist-tag suffix. Empty -> "dev-<YYYYMMDD>"; else "dev-<YYYYMMDD>-<suffix>". Charset: [A-Za-z0-9-].'
type: string
required: false
default: ""
# Triggers: a `truapi-provider-dev[-<suffix>]` tag (suffix becomes the
# dist-tag suffix), or a chain-spec change landing on main. The paths filter
# only applies to branch pushes, never tags.
push:
tags:
- "truapi-provider-dev*"
branches:
- main
paths:
- "rust/crates/truapi-provider/networks/**"
permissions:
contents: read
concurrency:
group: dev-publish-truapi-provider
cancel-in-progress: false
jobs:
# Nothing reaches npm unverified. release.yml gets this from a `workflow_run`
# gate on green CI, which a tag push cannot use (CI runs on branches, not
# tags), so the checks that matter for this crate run here instead.
verify:
name: Verify truapi-provider
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@5b842231ba77f5c045dba54ac5560fed2db780e2 # nightly
with:
toolchain: nightly
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@f0d9c3887740aee45f6153b24b3a6b815192ec16 # v2.8.1
- run: cargo +nightly fmt -p truapi-provider --check
- run: cargo +nightly clippy -p truapi-provider --all-targets --all-features -- -D warnings
# The published artifact is the wasm build, so lint the target it ships as.
- run: cargo +nightly clippy -p truapi-provider --target wasm32-unknown-unknown --no-default-features --features "js smoldot networks" --all-targets -- -D warnings
- run: cargo test -p truapi-provider --all-features
dev-publish:
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
- uses: dtolnay/rust-toolchain@5b842231ba77f5c045dba54ac5560fed2db780e2 # stable
with:
toolchain: stable
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@f0d9c3887740aee45f6153b24b3a6b815192ec16 # v2
- name: Install wasm-pack
run: cargo install wasm-pack --version 0.14.0 --locked
# Stamp <next-patch>-dev-<date>[-suffix].N (sorts below any future stable)
# into package.json; never committed.
- name: Compute dev version and dist-tag
id: devver
shell: bash
env:
NPM_TAG_SUFFIX: ${{ inputs.npm_tag_suffix }}
run: |
set -euo pipefail
suffix="${NPM_TAG_SUFFIX:-}"
# On a tag push, derive the suffix from the tag name
# (truapi-provider-dev[-<suffix>]); workflow_dispatch supplies it directly.
if [[ -z "$suffix" && "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
suffix="${GITHUB_REF_NAME#truapi-provider-dev}"
suffix="${suffix#-}"
fi
if [[ -n "$suffix" && ! "$suffix" =~ ^[A-Za-z0-9-]+$ ]]; then
echo "::error::dev suffix must match [A-Za-z0-9-]+ or be empty"
exit 1
fi
pkg=js/packages/truapi-provider
base="$(jq -r .version "$pkg/package.json")"
stable="${base%%-*}"
IFS='.' read -r major minor patch <<< "$stable"
next="$major.$minor.$((patch + 1))"
date="$(date -u +%Y%m%d)"
if [[ -z "$suffix" ]]; then
tag="dev-${date}"
else
tag="dev-${date}-${suffix}"
fi
prefix="${next}-${tag}"
# `|| echo '[]'`: npm view 404s before the first publish; `|| true`:
# no version matches the prefix on the first same-day build.
max_n="$(
{ npm view --json @parity/truapi-provider versions 2>/dev/null || echo '[]'; } \
| jq -r '.[]?' \
| { grep -E "^${prefix}\.[0-9]+$" || true; } \
| sed -E "s|^${prefix}\.||" \
| sort -n | tail -1
)"
n=$(( ${max_n:--1} + 1 ))
version="${prefix}.${n}"
jq --arg v "$version" '.version = $v' "$pkg/package.json" > "$pkg/package.json.tmp"
mv "$pkg/package.json.tmp" "$pkg/package.json"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "Computed @parity/truapi-provider@${version} -> dist-tag ${tag}"
- name: Build wasm
run: npm run build:wasm --prefix js/packages/truapi-provider
- name: Pack
run: |
set -euo pipefail
mkdir -p artifacts
(cd js/packages/truapi-provider && npm pack --pack-destination "$GITHUB_WORKSPACE/artifacts/")
- name: Upload package artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: truapi-provider-dev-${{ github.sha }}
path: artifacts/*.tgz
- name: Publish via npm_publish_automation
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
with:
route: POST /repos/paritytech/npm_publish_automation/actions/workflows/publish.yml/dispatches
ref: main
inputs: '${{ format(''{{ "repo": "{0}", "run_id": "{1}", "artifact_name": "truapi-provider-dev-{2}", "npm_tag": "{3}" }}'', github.repository, github.run_id, github.sha, steps.devver.outputs.tag) }}'
env:
GITHUB_TOKEN: ${{ secrets.NPM_PUBLISH_AUTOMATION_TOKEN }}
# No tags to gate here, so a missing version just fails the job. The check
# is version-addressed, so the dist-tag above does not affect it.
- name: Confirm the dev snapshot reached npm
timeout-minutes: 15
env:
DEV_VERSION: ${{ steps.devver.outputs.version }}
run: |
node scripts/wait-for-npm-publish.mjs \
--package @parity/truapi-provider --version "${DEV_VERSION}"