-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (121 loc) · 3.98 KB
/
release.yml
File metadata and controls
134 lines (121 loc) · 3.98 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
name: release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build:
name: build-${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bin_name: errat
archive_ext: tar.gz
use_cross: true
- os: macos-15-intel
target: x86_64-apple-darwin
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
bin_name: errat
archive_ext: tar.gz
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
bin_name: errat.exe
archive_ext: zip
use_cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: ${{ matrix.use_cross }}
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Build (cross)
if: ${{ matrix.use_cross }}
run: cross build --release --target ${{ matrix.target }}
- name: Build (native)
if: ${{ !matrix.use_cross }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: ${{ matrix.archive_ext == 'tar.gz' }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME}"
dist="dist"
mkdir -p "${dist}"
bin="target/${{ matrix.target }}/release/${{ matrix.bin_name }}"
pkg="errat-${version}-${{ matrix.target }}"
stage="${pkg}"
mkdir -p "${stage}"
cp "${bin}" "${stage}/"
cp README.md README.zh-CN.md LICENSE "${stage}/"
tar -czf "${dist}/${pkg}.tar.gz" "${stage}"
- name: Sha256 (unix)
if: ${{ matrix.archive_ext == 'tar.gz' }}
shell: bash
run: |
set -euo pipefail
file="dist/errat-${GITHUB_REF_NAME}-${{ matrix.target }}.tar.gz"
python3 - <<'PY' "$file"
import hashlib, pathlib, sys
p = pathlib.Path(sys.argv[1])
h = hashlib.sha256(p.read_bytes()).hexdigest()
out = p.with_suffix(p.suffix + ".sha256")
out.write_text(f"{h} {p.name}\n")
PY
- name: Package (windows)
if: ${{ matrix.archive_ext == 'zip' }}
shell: pwsh
run: |
$version = "${{ github.ref_name }}"
$dist = "dist"
New-Item -ItemType Directory -Force -Path $dist | Out-Null
$bin = "target\${{ matrix.target }}\release\${{ matrix.bin_name }}"
$pkg = "errat-$version-${{ matrix.target }}"
$stage = $pkg
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item $bin $stage\
Copy-Item README.md, README.zh-CN.md, LICENSE $stage\
$zip = "$dist\$pkg.zip"
Compress-Archive -Path $stage\* -DestinationPath $zip -Force
$hash = (Get-FileHash $zip -Algorithm SHA256).Hash.ToLower()
$sha = "$zip.sha256"
"$hash $(Split-Path $zip -Leaf)" | Out-File -Encoding ascii $sha
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: errat-${{ matrix.target }}
path: dist/*
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: errat-*
merge-multiple: true
- name: Publish release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: dist/*