Repository navigation
158 lines (143 loc) · 5.49 KB
/
Copy pathrelease.yml
File metadata and controls
158 lines (143 loc) · 5.49 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
name: Release
# Pushing a tag such as v0.4.0 builds the `rust-agent-runtime` CLI on native runners,
# packages it and publishes a GitHub release. Running the workflow by hand
# (workflow_dispatch) builds and uploads the archives as workflow artifacts
# but never publishes. See docs/releasing.md.
on:
push:
tags: [ "v*" ]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
prepare:
name: Check version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Read workspace version and compare with the tag
id: version
run: |
version="$(cargo metadata --no-deps --format-version 1 --locked \
| jq -r '.packages[] | select(.name == "rust-agent-runtime") | .version')"
if [ -z "$version" ] || [ "$version" = "null" ]; then
echo "::error::could not read the rust-agent-runtime version from Cargo.toml"
exit 1
fi
if [ "$GITHUB_REF_TYPE" = "tag" ] && [ "$GITHUB_REF_NAME" != "v$version" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match the workspace version $version (expected v$version). Fix the version in Cargo.toml or push the right tag."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.target }}
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:
# Linux builds run on the oldest hosted images so the binaries link
# against an older glibc (2.35) and run on most current distributions.
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
- { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm }
- { target: x86_64-apple-darwin, os: macos-15-intel }
- { target: aarch64-apple-darwin, os: macos-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
env:
VERSION: ${{ needs.prepare.outputs.version }}
TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --locked -p rust-agent-runtime --target ${{ matrix.target }}
- name: Package (unix)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
name="rust-agent-runtime-${VERSION}-${TARGET}"
mkdir -p "dist/${name}"
cp "target/${TARGET}/release/rust-agent-runtime" LICENSE "dist/${name}/"
cp packaging/README.txt "dist/${name}/README.txt"
tar -C dist -czf "dist/${name}.tar.gz" "${name}"
cd dist
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${name}.tar.gz" > "${name}.tar.gz.sha256"
else
shasum -a 256 "${name}.tar.gz" > "${name}.tar.gz.sha256"
fi
cat "${name}.tar.gz.sha256"
- name: Package (windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$name = "rust-agent-runtime-$env:VERSION-$env:TARGET"
New-Item -ItemType Directory -Force -Path "dist/$name" | Out-Null
Copy-Item "target/$env:TARGET/release/rust-agent-runtime.exe" "dist/$name/"
Copy-Item LICENSE "dist/$name/"
Copy-Item packaging/README.txt "dist/$name/README.txt"
Compress-Archive -Path "dist/$name" -DestinationPath "dist/$name.zip"
$hash = (Get-FileHash "dist/$name.zip" -Algorithm SHA256).Hash.ToLower()
"$hash $name.zip" | Set-Content -Path "dist/$name.zip.sha256" -Encoding ascii
Get-Content "dist/$name.zip.sha256"
- name: Smoke test the binary
shell: bash
run: |
set -euo pipefail
exe="target/${TARGET}/release/rust-agent-runtime"
if [ "$RUNNER_OS" = "Windows" ]; then exe="${exe}.exe"; fi
out="$("$exe" --version)"
echo "$out"
case "$out" in
*"${VERSION}"*) ;;
*) echo "::error::binary reports '$out', expected version ${VERSION}"; exit 1 ;;
esac
- name: Upload archives
uses: actions/upload-artifact@v4
with:
name: rust-agent-runtime-${{ matrix.target }}
path: |
dist/*.tar.gz
dist/*.zip
dist/*.sha256
if-no-files-found: error
release:
name: Publish release
# Only for pushed tags; a manual run stops after the build job.
if: github.ref_type == 'tag'
needs: [prepare, build]
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERSION: ${{ needs.prepare.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: rust-agent-runtime-*
merge-multiple: true
- name: List files
run: ls -l dist
- name: Create the GitHub release
run: |
set -euo pipefail
flags=""
case "$VERSION" in *-*) flags="--prerelease" ;; esac
gh release create "$GITHUB_REF_NAME" \
--repo "$GITHUB_REPOSITORY" \
--verify-tag \
--title "rust-agent-runtime $VERSION" \
--generate-notes \
$flags \
dist/*.tar.gz dist/*.zip dist/*.sha256