Repository navigation
148 lines (132 loc) · 4.62 KB
/
Copy pathrelease.yml
File metadata and controls
148 lines (132 loc) · 4.62 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
name: Release binaries
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version string to stamp into the binary (e.g. 0.2.9)'
required: false
permissions:
contents: write
jobs:
build:
name: ${{ matrix.asset }}
runs-on: ${{ matrix.os }}
# A label with no runner behind it waits forever rather than failing, so
# give every job a ceiling: an image that has been retired should cost
# twenty minutes, not an afternoon.
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
asset: diffuse-linux-x86_64
native: true
- os: ubuntu-22.04-arm
target: aarch64-unknown-linux-gnu
asset: diffuse-linux-aarch64
native: true
# Both macOS binaries are built on Apple Silicon. Intel runner images
# are retired, and Apple's own toolchain cross-compiles to x86_64
# without anything extra, so this needs no Intel machine to exist.
- os: macos-latest
target: x86_64-apple-darwin
asset: diffuse-macos-x86_64
native: false
- os: macos-latest
target: aarch64-apple-darwin
asset: diffuse-macos-aarch64
native: true
- os: windows-2022
target: x86_64-pc-windows-msvc
asset: diffuse-windows-x86_64.exe
native: true
steps:
- uses: actions/checkout@v4
with:
# The version the binary reports comes from `git describe`, which
# needs the tags, and a shallow clone has none of them.
fetch-depth: 0
- name: Install protobuf compiler
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
shell: bash
run: |
if [ -n "${{ inputs.version }}" ]; then
export DIFFUSE_VERSION="${{ inputs.version }}"
fi
cargo build --release --locked --bin diffuse --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
mkdir -p dist
if [ "${{ runner.os }}" = "Windows" ]; then
cp "target/${{ matrix.target }}/release/diffuse.exe" "dist/${{ matrix.asset }}"
else
cp "target/${{ matrix.target }}/release/diffuse" "dist/${{ matrix.asset }}"
chmod +x "dist/${{ matrix.asset }}"
fi
cd dist
if command -v sha256sum > /dev/null; then
sha256sum "${{ matrix.asset }}" > "${{ matrix.asset }}.sha256"
else
shasum -a 256 "${{ matrix.asset }}" > "${{ matrix.asset }}.sha256"
fi
- name: Check the binary runs
# Only where the runner can execute what was just built. The Intel
# macOS binary is cross-compiled and has no host here to try it on.
if: matrix.native
shell: bash
run: ./dist/${{ matrix.asset }} --version
- name: Check the cross-built binary is for the right machine
if: ${{ !matrix.native }}
run: file "dist/${{ matrix.asset }}" | grep -q "x86_64"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset }}
path: dist/*
publish:
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Take this tag's section out of the changelog
# The release notes are the changelog entry for this version, so there
# is nothing to paste by hand and the two cannot drift apart. A tag
# with no section fails here rather than publishing an empty release.
run: |
version="${GITHUB_REF_NAME#v}"
awk -v want="## v${version}" '
$0 == want { found = 1; next }
/^## / { if (found) exit }
found
' CHANGELOG.md | sed '/^---$/d' > notes.md
if [ ! -s notes.md ]; then
echo "CHANGELOG.md has no '## v${version}' section"
exit 1
fi
head -3 notes.md
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
body_path: notes.md
files: dist/*
fail_on_unmatched_files: true