-
Notifications
You must be signed in to change notification settings - Fork 9
141 lines (125 loc) · 5.1 KB
/
rust-publish-dry-run-v2.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
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
name: Publish Dry Run v2
on:
workflow_call:
inputs:
crates:
description: 'Space separated list of crate names in the order to be published.'
required: false
type: string
runs-on:
required: false
default: 'ubuntu-latest'
type: string
target:
required: false
default: 'x86_64-unknown-linux-gnu'
type: string
cargo-hack-feature-options:
required: false
default: '--feature-powerset'
type: string
additional-deb-packages:
description: 'Space separated list of .deb packages that will be installed on ubuntu.'
required: false
default: ''
type: string
jobs:
publish-dry-run:
runs-on: ${{ inputs.runs-on }}
defaults:
run:
shell: bash
env:
CARGO_BUILD_TARGET: ${{ inputs.target }}
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
RUST_BACKTRACE: 1
steps:
- uses: stellar/actions/disk-cleanup@main
- uses: actions/checkout@v4
- uses: stellar/actions/rust-cache@main
- run: rustup update
- run: rustup target add ${{ inputs.target }}
- name: Install add'l compilers (Linux arm64 only)
if: inputs.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get -y install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Install additional dependencies (Linux)
if: (inputs.target == 'aarch64-unknown-linux-gnu' || inputs.target == 'x86_64-unknown-linux-gnu') && inputs.additional-deb-packages != ''
run: sudo apt-get update && sudo apt-get -y install ${{ inputs.additional-deb-packages }}
# macOS comes with an old version of `make` that causes issues when building
# some projects
- name: Update GNU Make (macOS only)
if: inputs.target == 'x86_64-apple-darwin' || inputs.target == 'aarch64-apple-darwin'
run: |
brew update && brew install make
echo "$(brew --prefix)/opt/make/libexec/gnubin/" >> "$GITHUB_PATH"
- uses: stellar/binaries@v21
with:
name: cargo-hack
version: 0.5.28
- uses: stellar/binaries@v26
with:
name: cargo-workspaces
version: 0.3.4
# Create the vendor directory because it'll only be created in the next step
# if the crate has dependencies, but it's needed for the latter steps in all
# cases.
- run: mkdir -p vendor
# Vendor all the dependencies into the vendor/ folder. Temporarily remove
# [patch.crates-io] entries in the workspace Cargo.toml that reference git
# repos. These will be removed when published.
- name: Vendor Dependencies
run: |
cp Cargo.toml Cargo.toml.bak
sed -r '/(git|rev) ?=/d' Cargo.toml.bak > Cargo.toml
cargo vendor --versioned-dirs
rm Cargo.toml
mv Cargo.toml.bak Cargo.toml
# If a list of crates weren't provided, prepare a list by asking
# cargo-workspaces for the order it would publish the crates in.
- name: Prepare List of Crates Ordered by Publish-Order
uses: actions/github-script@v7
id: crates
with:
script: |
let crates = "";
await exec.exec(
"bash", [ "-c", "cargo-workspaces workspaces list" ],
{ listeners: { stdout: (buf) => { crates += buf.toString(); } } },
);
return crates.split("\n").join(" ");
result-encoding: string
- name: List of Crates
run: echo "${{steps.crates.outputs.result}}"
# Package the crates that will be published. Verification is disabled
# because we aren't ready to verify yet. Add each crate that was packaged to
# the vendor/ directory.
- name: Package Crates ${{ steps.crates.outputs.result }}
run: |
# shellcheck disable=SC2043
for name in ${{ steps.crates.outputs.result }}
do
version=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name=="'$name'") | .version')
cargo package \
--no-verify \
--package "$name" \
--config "source.crates-io.replace-with = 'vendored-sources'" \
--config "source.vendored-sources.directory = 'vendor'"
path="target/package/${name}-${version}.crate"
tar xvfz "$path" -C vendor/
# Crates in the vendor directory require a checksum file, but it doesn't
# matter if it is empty.
echo '{"files":{}}' > "vendor/$name-$version/.cargo-checksum.json"
done
# Rerun the package command but with verification enabled this time. Tell
# cargo to use the local vendor/ directory as the source for all packages. Run
# the package command on the full feature powerset so that all features of
# each crate are verified to compile.
- name: Verify Crates with ${{ inputs.cargo-hack-feature-options }}
run: >
cargo-hack hack
${{ inputs.cargo-hack-feature-options }}
--ignore-private
--config "source.crates-io.replace-with = 'vendored-sources'"
--config "source.vendored-sources.directory = 'vendor'"
package
--target ${{ inputs.target }}