Skip to content

Commit e538c3c

Browse files
authored
Merge pull request #1299 from input-output-hk/jpraynaud/1298-publish-multiple-crates
Publish multiple packages to `crates.io`
2 parents d3a36fd + 304a2d0 commit e538c3c

File tree

5 files changed

+131
-52
lines changed

5 files changed

+131
-52
lines changed

.github/workflows/actions/deploy-terraform-infrastructure/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ description: |
33
Deploy the infrastructure of a Mithril network with terraform.
44
inputs:
55
dry_run:
6-
description: Dry run will apply the terraform infrastructure, just plan it.
6+
description: Dry run will not apply the terraform infrastructure, just plan it.
77
required: true
8-
default: "true"
98
terraform_backend_bucket:
109
description: terraform backend bucket used to store terraform state.
1110
required: true
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: publish-crate-package
2+
description: |
3+
Deploy the crate package to crates.io
4+
inputs:
5+
dry_run:
6+
description: Dry run will not publish to crates.io, just test it.
7+
required: true
8+
package:
9+
description: crate package name.
10+
required: true
11+
api_token:
12+
description: crates.io API token.
13+
required: false
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Check crate latest version
19+
id: check_version
20+
shell: bash
21+
run: |
22+
echo "Check crate latest published version for '${{ inputs.package}}' package"
23+
LATEST_REMOTE_VERSION=$(curl -sL https://crates.io/api/v1/crates/${{ inputs.package}} | jq -r '.crate.newest_version')
24+
LOCAL_VERSION=$(cargo metadata --quiet --no-deps | jq -r '.packages[] | select(.name=="${{ inputs.package}}") | .version')
25+
echo "Latest crate.io version: $LATEST_REMOTE_VERSION"
26+
echo "Local version: $LOCAL_VERSION"
27+
28+
if [ "$LOCAL_VERSION" != "$LATEST_REMOTE_VERSION" ]; then
29+
echo "Local version is newer than remote version: we will publish to crates.io"
30+
echo "should_deploy=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "Local version and remote version are the same: no need to publish to crates.io"
33+
echo "should_deploy=false" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Cargo publish dry run
37+
shell: bash
38+
run: |
39+
echo "Cargo publish '${{ inputs.package}}' package (dry run)"
40+
cargo publish -p ${{ inputs.package}} --dry-run --no-verify
41+
42+
- name: Cargo package list
43+
shell: bash
44+
run: |
45+
echo "Cargo package list '${{ inputs.package}}' package"
46+
cargo package -p ${{ inputs.package}} --list
47+
48+
- name: Cargo publish
49+
if: inputs.dry_run == 'false' && steps.check_version.outputs.should_deploy == 'true'
50+
shell: bash
51+
run: |
52+
echo "Cargo publish '${{ inputs.package}}' package"
53+
cargo publish -p ${{ inputs.package}} --token ${{ inputs.api_token }} --no-verify

.github/workflows/ci.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,33 @@ jobs:
331331
push: ${{ env.PUSH_PACKAGES }}
332332
tags: ${{ steps.meta.outputs.tags }}
333333

334+
publish-crate-test:
335+
strategy:
336+
fail-fast: false
337+
matrix:
338+
package: [ mithril-stm ]
339+
340+
runs-on: ubuntu-22.04
341+
needs:
342+
- build
343+
- test
344+
- run-test-lab
345+
- check
346+
steps:
347+
- name: Checkout sources
348+
uses: actions/checkout@v3
349+
350+
- name: Install stable toolchain
351+
uses: dtolnay/rust-toolchain@master
352+
with:
353+
toolchain: stable
354+
355+
- name: Publish package to crates.io
356+
uses: ./.github/workflows/actions/publish-crate-package
357+
with:
358+
dry_run: "true"
359+
package: ${{ matrix.package }}
360+
334361
unstable-release:
335362
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith('refs/heads/hotfix', github.ref))
336363
runs-on: ubuntu-22.04
@@ -493,4 +520,5 @@ jobs:
493520
loki_auth_password: ${{ secrets.LOKI_AUTH_PASSWORD }}
494521
loki_ingest_host: ${{ vars.LOKI_INGEST_HOST }}
495522
loki_ingest_username: ${{ secrets.LOKI_INGEST_USERNAME }}
496-
loki_ingest_password: ${{ secrets.LOKI_INGEST_PASSWORD }}
523+
loki_ingest_password: ${{ secrets.LOKI_INGEST_PASSWORD }}
524+

.github/workflows/pre-release.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,25 @@ jobs:
219219
loki_ingest_host: ${{ vars.LOKI_INGEST_HOST }}
220220
loki_ingest_username: ${{ secrets.LOKI_INGEST_USERNAME }}
221221
loki_ingest_password: ${{ secrets.LOKI_INGEST_PASSWORD }}
222+
223+
publish-crate-test:
224+
strategy:
225+
fail-fast: false
226+
matrix:
227+
package: [ mithril-stm ]
228+
229+
runs-on: ubuntu-22.04
230+
steps:
231+
- name: Checkout sources
232+
uses: actions/checkout@v3
233+
234+
- name: Install stable toolchain
235+
uses: dtolnay/rust-toolchain@master
236+
with:
237+
toolchain: stable
238+
239+
- name: Publish package to crates.io
240+
uses: ./.github/workflows/actions/publish-crate-package
241+
with:
242+
dry_run: "true"
243+
package: ${{ matrix.package }}

.github/workflows/release.yml

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -59,55 +59,6 @@ jobs:
5959
file: ${{ env.DOCKER_FILE }}
6060
push: true
6161
tags: ${{ steps.meta.outputs.tags }}
62-
63-
check-deploy-crates-io:
64-
runs-on: ubuntu-22.04
65-
outputs:
66-
should-deploy: ${{ steps.check_version.outputs.should_deploy }}
67-
steps:
68-
- name: Checkout sources
69-
uses: actions/checkout@v3
70-
71-
- name: Check crate latest version
72-
id: check_version
73-
run: |
74-
LATEST_REMOTE_VERSION=$(wget -q -O - https://crates.io/api/v1/crates/mithril-stm | jq -r '.crate.newest_version')
75-
LOCAL_VERSION=$(cargo metadata --quiet --no-deps | jq -r '.packages[] | select(.name=="mithril-stm") | .version')
76-
echo "Latest crate.io version: $LATEST_REMOTE_VERSION"
77-
echo "Local version: $LOCAL_VERSION"
78-
79-
if [ "$LOCAL_VERSION" != "$LATEST_REMOTE_VERSION" ]; then
80-
echo "Local version is newer than remote version: we will publish to crates.io"
81-
echo "should_deploy=true" >> $GITHUB_OUTPUT
82-
else
83-
echo "Local version and remote version are the same: no need to publish to crates.io"
84-
echo "should_deploy=false" >> $GITHUB_OUTPUT
85-
fi
86-
87-
deploy-crates-io:
88-
runs-on: ubuntu-22.04
89-
needs: check-deploy-crates-io
90-
if: needs.check-deploy-crates-io.outputs.should-deploy == 'true'
91-
steps:
92-
- name: Checkout sources
93-
uses: actions/checkout@v3
94-
95-
- name: Install stable toolchain
96-
uses: dtolnay/rust-toolchain@master
97-
with:
98-
toolchain: stable
99-
100-
- name: Cargo publish dry run
101-
shell: bash
102-
run: cargo publish -p mithril-stm --dry-run
103-
104-
- name: Cargo package list
105-
shell: bash
106-
run: cargo package -p mithril-stm --list
107-
108-
- name: Cargo publish
109-
shell: bash
110-
run: cargo publish -p mithril-stm --token ${{ secrets.CRATES_IO_API_TOKEN }}
11162

11263
deploy-release:
11364
strategy:
@@ -208,3 +159,29 @@ jobs:
208159
loki_ingest_host: ${{ vars.LOKI_INGEST_HOST }}
209160
loki_ingest_username: ${{ secrets.LOKI_INGEST_USERNAME }}
210161
loki_ingest_password: ${{ secrets.LOKI_INGEST_PASSWORD }}
162+
163+
publish-crate:
164+
strategy:
165+
fail-fast: false
166+
matrix:
167+
package: [ mithril-stm ]
168+
include:
169+
- package: mithril-stm
170+
api_token_secret_name: CRATES_IO_API_TOKEN
171+
172+
runs-on: ubuntu-22.04
173+
steps:
174+
- name: Checkout sources
175+
uses: actions/checkout@v3
176+
177+
- name: Install stable toolchain
178+
uses: dtolnay/rust-toolchain@master
179+
with:
180+
toolchain: stable
181+
182+
- name: Publish package to crates.io
183+
uses: ./.github/workflows/actions/publish-crate-package
184+
with:
185+
dry_run: "false"
186+
package: ${{ matrix.package }}
187+
api_token: ${{ secrets[matrix.api_token_secret_name] }}

0 commit comments

Comments
 (0)