-
Notifications
You must be signed in to change notification settings - Fork 33
80 lines (71 loc) · 3.44 KB
/
publish.yml
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
name: Publish to Crates.io
on:
push:
branches:
- master
workflow_dispatch: # Allow manual workflow dispatch
jobs:
dry-run-publish:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' # Only run this job for manual triggers
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Test Dry-Run Publish for Each Package
run: |
# Iterate through package names retrieved
PACKAGE_NAMES="testmacro include_gif ledger_secure_sdk_sys ledger_device_sdk"
for PACKAGE_NAME in $PACKAGE_NAMES; do
# Test a dry-run publish for each package within the workspace if required
last_published_version=$(cargo search -q --limit 1 $PACKAGE_NAME | grep -oP '\d+\.\d+\.\d+')
echo "Published version of $PACKAGE_NAME is $version_published"
manifest_version=$(cargo metadata --format-version=1 --no-deps | jq -r --arg PACKAGE_NAME "$PACKAGE_NAME" '.packages[] | select(.name == $PACKAGE_NAME) | .version')
echo "Current version in manifest for $PACKAGE_NAME is $manifest_version"
if [ "$last_published_version" == "$manifest_version" ]; then
echo "Package $PACKAGE_NAME is already published with version $manifest_version."
else
echo "Package $PACKAGE_NAME is not published with version $manifest_version."
echo "Dry-run publishing $PACKAGE_NAME..."
cargo publish --dry-run --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --package "$PACKAGE_NAME"
fi
done
env:
CARGO_TERM_COLOR: always
working-directory: ${{ github.workspace }}
crates-io-publish:
runs-on: ubuntu-latest
if: github.event_name == 'push' # Only run this job for pushes
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Publish Package on crates.io if required
run: |
# Iterate through package names retrieved
PACKAGE_NAMES="testmacro include_gif ledger_secure_sdk_sys ledger_device_sdk"
for PACKAGE_NAME in $PACKAGE_NAMES; do
# Publish each package within the workspace if required
last_published_version=$(cargo search -q --limit 1 $PACKAGE_NAME | grep -oP '\d+\.\d+\.\d+')
echo "Published version of $PACKAGE_NAME is $last_published_version"
manifest_version=$(cargo metadata --format-version=1 --no-deps | jq -r --arg PACKAGE_NAME "$PACKAGE_NAME" '.packages[] | select(.name == $PACKAGE_NAME) | .version')
echo "Current version in manifest for $PACKAGE_NAME is $manifest_version"
if [ "$last_published_version" == "$manifest_version" ]; then
echo "Package $PACKAGE_NAME is already published with version $manifest_version."
else
echo "Package $PACKAGE_NAME with version $manifest_version is not published."
echo "Publishing $PACKAGE_NAME..."
cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --package "$PACKAGE_NAME"
fi
done
env:
CARGO_TERM_COLOR: always
working-directory: ${{ github.workspace }}