Repository navigation
144 lines (126 loc) · 5.08 KB
/
Copy pathrelease.yml
File metadata and controls
144 lines (126 loc) · 5.08 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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
jobs:
# Fails a bad tag in seconds, before three platforms spend minutes building
# something that will not be published.
guard:
name: Check tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
# merge-base below needs history; a tag checkout is shallow by default.
fetch-depth: 0
- name: Check tag is on main
run: |
git fetch --no-tags --quiet origin main
if ! git merge-base --is-ancestor HEAD origin/main; then
echo "Tag $GITHUB_REF_NAME is not on main. Release tags come from main."
exit 1
fi
# The version the binary reports comes from Cargo.toml, not from the tag.
- name: Check tag matches crate version
run: |
TAG="${GITHUB_REF_NAME#v}"
VERSION=$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2)
if [ "$TAG" != "$VERSION" ]; then
echo "Tag $GITHUB_REF_NAME does not match Cargo.toml version $VERSION"
exit 1
fi
build:
name: Build ${{ matrix.target }}
needs: guard
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: buddy-rescue-linux-x86_64.tar.gz
- os: macos-latest
target: universal-apple-darwin
archive: buddy-rescue-macos-universal.tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: buddy-rescue-windows-x86_64.zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
- name: Build Linux or Windows
if: matrix.target != 'universal-apple-darwin'
run: cargo build --release --locked --target "${{ matrix.target }}"
- name: Build universal macOS binary
if: matrix.target == 'universal-apple-darwin'
shell: bash
run: |
rustup target add x86_64-apple-darwin aarch64-apple-darwin
cargo build --release --locked --target x86_64-apple-darwin
cargo build --release --locked --target aarch64-apple-darwin
mkdir -p target/release
lipo -create \
target/x86_64-apple-darwin/release/buddy-rescue \
target/aarch64-apple-darwin/release/buddy-rescue \
-output target/release/buddy-rescue
- name: Package Unix release
if: runner.os != 'Windows'
shell: bash
run: |
staging="dist/buddy-rescue-${{ matrix.target }}"
mkdir -p "$staging"
if [ "${{ matrix.target }}" = "universal-apple-darwin" ]; then
cp target/release/buddy-rescue "$staging/"
else
cp "target/${{ matrix.target }}/release/buddy-rescue" "$staging/"
fi
cp README.md LICENSE-MIT LICENSE-APACHE "$staging/"
tar -C dist -czf "dist/${{ matrix.archive }}" "buddy-rescue-${{ matrix.target }}"
- name: Package Windows release
if: runner.os == 'Windows'
shell: pwsh
run: |
$staging = "dist/buddy-rescue-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $staging | Out-Null
Copy-Item "target/${{ matrix.target }}/release/buddy-rescue.exe" $staging
Copy-Item README.md, LICENSE-MIT, LICENSE-APACHE $staging
Compress-Archive -Path $staging -DestinationPath "dist/${{ matrix.archive }}"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: release-${{ matrix.target }}
path: dist/${{ matrix.archive }}
if-no-files-found: error
publish:
name: Publish GitHub release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write # create the release
id-token: write # sign the attestation
attestations: write # record it
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
pattern: release-*
merge-multiple: true
path: dist
- name: Generate checksums
working-directory: dist
run: sha256sum buddy-rescue-* > SHA256SUMS
# Publicly verifiable provenance for the exact bytes uploaded below:
# gh attestation verify <file> --repo brandnewbyte/buddy-rescue
# Attesting through the checksums file keeps SHA256SUMS and the
# attestation describing one identical set of artifacts.
- name: Attest build provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4
with:
subject-checksums: dist/SHA256SUMS
- uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3
with:
files: dist/*
generate_release_notes: true
fail_on_unmatched_files: true