-
Notifications
You must be signed in to change notification settings - Fork 6
230 lines (197 loc) · 7.42 KB
/
Copy pathrelease-github.yml
File metadata and controls
230 lines (197 loc) · 7.42 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: GitHub CLI Release
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.3.39)"
required: true
permissions:
contents: write
actions: write
env:
PROJECT_NAME: smb
CARGO_TERM_COLOR: always
CLI_CLIENT_SECRET: ${{ secrets.CLI_CLIENT_SECRET }}
jobs:
build:
name: Build binary (${{ matrix.name }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: linux-arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- name: win-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
- name: win-arm64
runner: windows-latest
target: aarch64-pc-windows-msvc
- name: macos-amd64
runner: macos-15-intel
target: x86_64-apple-darwin
- name: macos-arm64
runner: macos-latest
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
- name: Read Rust toolchain
shell: bash
run: |
rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
if [ -z "$rust_toolchain" ]; then
echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
exit 1
fi
echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
- name: Install toolkit
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
targets: ${{ matrix.target }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: github-${{ matrix.target }}
- name: Build binary
shell: bash
run: cargo build --locked --release --target ${{ matrix.target }} --package smbcloud-cli
- name: Package binary
shell: bash
run: |
BIN_SUFFIX=""
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
BIN_SUFFIX=".exe"
fi
BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
BIN_RELEASE="${PROJECT_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
mkdir -p ./release
mv "${BIN_OUTPUT}" "./release/${BIN_RELEASE}"
- name: Package macOS tarball for Homebrew
if: contains(matrix.target, 'apple-darwin')
shell: bash
run: |
ARCHIVE_NAME="${PROJECT_NAME}-${{ matrix.name }}.tar.gz"
mkdir -p staging-brew
cp "./release/${PROJECT_NAME}-${{ matrix.name }}" "staging-brew/${PROJECT_NAME}"
strip "staging-brew/${PROJECT_NAME}"
tar -C staging-brew -czf "${ARCHIVE_NAME}" "${PROJECT_NAME}"
shasum -a 256 "${ARCHIVE_NAME}" | awk '{print $1}' > "${ARCHIVE_NAME}.sha256"
echo "Archive: ${ARCHIVE_NAME}"
echo "SHA256: $(cat "${ARCHIVE_NAME}.sha256")"
# Homebrew has always had a checksum because the tap needs one. Scoop
# and winget each need one too, and they consume the raw Windows
# binaries rather than the macOS tarball, so every asset gets a
# sidecar. Windows runners use bash from Git for Windows, which has
# sha256sum; macOS only has shasum.
- name: Checksum release assets
shell: bash
run: |
cd release
for asset in *; do
case "${asset}" in *.sha256) continue ;; esac
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${asset}" | awk '{print $1}' > "${asset}.sha256"
else
shasum -a 256 "${asset}" | awk '{print $1}' > "${asset}.sha256"
fi
echo "${asset}: $(cat "${asset}.sha256")"
done
- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: binary-${{ matrix.name }}
path: release/*
- name: Upload macOS Homebrew artifacts
if: contains(matrix.target, 'apple-darwin')
uses: actions/upload-artifact@v7
with:
name: homebrew-${{ matrix.name }}
path: |
${{ env.PROJECT_NAME }}-${{ matrix.name }}.tar.gz
${{ env.PROJECT_NAME }}-${{ matrix.name }}.tar.gz.sha256
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
steps:
- name: Resolve tag
id: tag
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Download binary artifacts
uses: actions/download-artifact@v7
with:
pattern: "binary-*"
path: release
merge-multiple: true
- name: Download Homebrew artifacts
uses: actions/download-artifact@v7
with:
pattern: "homebrew-*"
path: release
merge-multiple: true
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.tag }}
files: release/*
# Build the notes from the PRs since the previous tag, the same
# format as the "Generate release notes" button on the web UI, so
# nobody has to fill the release body in by hand after the fact.
generate_release_notes: true
# These channels all publish somewhere outside this repo (a tap, a
# Scoop bucket, microsoft/winget-pkgs) and every one of them reads
# checksums off the release created above, so they hang off this job
# rather than firing on the tag directly.
- name: Trigger OS package manager releases
uses: actions/github-script@v8
with:
script: |
const tag = '${{ steps.tag.outputs.tag }}'
const workflows = [
'release-homebrew.yml',
'release-scoop.yml',
'release-winget.yml',
]
for (const workflow_id of workflows) {
try {
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id,
ref: tag,
inputs: { tag },
})
console.log(`Dispatched ${workflow_id} for tag ${tag}`)
} catch (error) {
// One packaging channel being unconfigured (a missing secret,
// a bucket repo that does not exist yet) should not take the
// rest of the fan-out down with it.
core.warning(`Failed to dispatch ${workflow_id}: ${error.message}`)
}
}