-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (129 loc) · 4.44 KB
/
release.yml
File metadata and controls
145 lines (129 loc) · 4.44 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
name: Publish Release Artifacts
on:
push:
tags:
- 'v*.*.*' # trigger on semantic version tags like v1.2.3
jobs:
release:
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
- target: aarch64-unknown-linux-gnu
runner: ubuntu-latest
- target: x86_64-apple-darwin
runner: macos-latest
- target: aarch64-apple-darwin
runner: macos-latest
- target: x86_64-pc-windows-msvc
runner: ubuntu-latest
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt
override: true
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
- name: Add target for cross builds (if needed)
run: |
rustup target list --installed || true
# Add the target toolchain if missing; for native runners this is harmless.
rustup target add ${{ matrix.target }} || true
- name: Build release
env:
CARGO_HOME: ${{ runner.temp }}/cargo
run: |
set -e
rustup target list --installed || true
# Build release for the target
cargo build --release --target "${{ matrix.target }}"
- name: Package binary
run: |
set -e
TAG=${GITHUB_REF##*/}
VERSION=${TAG#v}
OUTDIR=release-artifacts/${{ matrix.target }}
mkdir -p "$OUTDIR"
case "${{ matrix.target }}" in
*windows*)
BIN_PATH=target/${{ matrix.target }}/release/devspace-sweeper.exe
ARCHIVE_NAME=devspace-sweeper-${VERSION}-${{ matrix.target }}.zip
if [ ! -f "$BIN_PATH" ]; then
echo "Error: build artifact not found: $BIN_PATH" >&2
exit 1
fi
cp "$BIN_PATH" "$OUTDIR/"
cp README.md LICENSE "$OUTDIR/" || true
(cd "$OUTDIR" && zip -r "${ARCHIVE_NAME}" .)
;;
*)
BIN_PATH=target/${{ matrix.target }}/release/devspace-sweeper
ARCHIVE_NAME=devspace-sweeper-${VERSION}-${{ matrix.target }}.tar.gz
if [ ! -f "$BIN_PATH" ]; then
echo "Error: build artifact not found: $BIN_PATH" >&2
exit 1
fi
cp "$BIN_PATH" "$OUTDIR/"
cp README.md LICENSE "$OUTDIR/" || true
# Avoid failing if files change during archiving
(cd "$OUTDIR" && tar --warning=no-file-changed -czf "${ARCHIVE_NAME}" .)
;;
esac
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.target }}
path: release-artifacts/${{ matrix.target }}
publish-release:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release (if not exists) and upload assets
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: artifacts/*.tar.gz, artifacts/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crates:
needs: publish-release
runs-on: ubuntu-latest
# only run publish when triggered by a semantic version tag
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
set -e
# ensure the token is present
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "CARGO_REGISTRY_TOKEN is not set. Add it to repository secrets to enable automated publish." >&2
exit 1
fi
cargo publish --token "$CARGO_REGISTRY_TOKEN"