-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (120 loc) · 4.14 KB
/
Copy pathrelease.yml
File metadata and controls
135 lines (120 loc) · 4.14 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
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: hashline
jobs:
build:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
archive_ext: tar.gz
deps: musl-tools
- name: macos-aarch64
os: macos-latest
target: aarch64-apple-darwin
archive_ext: tar.gz
deps: ""
- name: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin
archive_ext: tar.gz
deps: ""
- name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
archive_ext: zip
deps: ""
steps:
- uses: actions/checkout@v6.0.3
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2.9.1
with:
cache-on-failure: true
- name: Install system dependencies
if: matrix.deps != ''
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq ${{ matrix.deps }}
- name: Build binary
shell: bash
run: |
set -euo pipefail
retries=1
if [ "${{ runner.os }}" = "Windows" ]; then retries=2; fi
attempt=1
while [ "$attempt" -le "$retries" ]; do
echo "=== Build attempt $attempt/$retries ==="
if cargo build --release --locked --target "${{ matrix.target }}" -p "$BINARY_NAME"; then
exit 0
fi
if [ "$attempt" -eq "$retries" ]; then
echo "::: Build failed after $retries attempts"
exit 1
fi
echo "::: Build failed, retrying..."
attempt=$((attempt + 1))
sleep 5
done
- name: Package Unix archive
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME}"
STAGE_DIR="${BINARY_NAME}-${VERSION}-${{ matrix.name }}"
mkdir -p "$STAGE_DIR"
cp "target/${{ matrix.target }}/release/${BINARY_NAME}" "$STAGE_DIR/"
cp README.md LICENSE* "$STAGE_DIR/" 2>/dev/null || true
tar -czf "${STAGE_DIR}.tar.gz" "$STAGE_DIR"
shasum -a 256 "${STAGE_DIR}.tar.gz" | awk '{print $1}' > "${STAGE_DIR}.tar.gz.sha256"
- name: Package Windows archive
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = "$env:GITHUB_REF_NAME"
$stageDir = "$env:BINARY_NAME-$version-${{ matrix.name }}"
New-Item -ItemType Directory -Force -Path $stageDir | Out-Null
Copy-Item "target/${{ matrix.target }}/release/$env:BINARY_NAME.exe" "$stageDir/$env:BINARY_NAME.exe"
if (Test-Path README.md) { Copy-Item README.md $stageDir }
Get-ChildItem LICENSE* -ErrorAction SilentlyContinue | Copy-Item -Destination $stageDir -ErrorAction SilentlyContinue
Compress-Archive -Path "$stageDir/*" -DestinationPath "${stageDir}.zip" -Force
$hash = (Get-FileHash "${stageDir}.zip" -Algorithm SHA256).Hash.ToLower()
$hash | Out-File -FilePath "${stageDir}.zip.sha256" -Encoding ascii -NoNewline
- name: Upload artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ matrix.name }}
path: ${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.name }}.${{ matrix.archive_ext }}*
release:
name: Publish GitHub release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifacts
uses: actions/download-artifact@v8.0.1
with:
path: dist
merge-multiple: true
- name: Publish release
uses: softprops/action-gh-release@v3
with:
files: dist/*
generate_release_notes: true