Repository navigation
210 lines (183 loc) · 6.84 KB
/
Copy pathrelease.yml
File metadata and controls
210 lines (183 loc) · 6.84 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch: # Allows manual testing
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.result }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/github-script@v7
with:
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: context.ref.replace('refs/tags/', ''),
name: `Release ${context.ref.replace('refs/tags/', '')}`,
draft: true,
prerelease: false
});
return release.data.id;
build:
name: Build ${{ matrix.target }}
needs: create-release
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux x86_64
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: pgsqlite
asset_name: pgsqlite-linux-amd64
use_cross: false
# Linux ARM64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: pgsqlite
asset_name: pgsqlite-linux-arm64
use_cross: true
# Windows x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: pgsqlite.exe
asset_name: pgsqlite-windows-amd64
use_cross: false
# macOS x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: pgsqlite
asset_name: pgsqlite-macos-intel
use_cross: false
# macOS ARM64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: pgsqlite
asset_name: pgsqlite-macos-apple-silicon
use_cross: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ matrix.target }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install cross
if: matrix.use_cross == true
run: cargo install cross --version 0.2.5
- name: Build (cargo)
if: matrix.use_cross == false
run: cargo build --release --target ${{ matrix.target }}
- name: Build (cross)
if: matrix.use_cross == true
run: cross build --release --target ${{ matrix.target }}
- name: Strip binary (Unix)
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
else
if [[ "${{ matrix.use_cross }}" == "true" ]]; then
docker run --rm -v "$PWD:/work" -w /work rustembedded/cross:${{ matrix.target }} \
aarch64-linux-gnu-strip /work/target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
else
strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
fi
fi
- name: Create archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
cd -
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target\${{ matrix.target }}\release
Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ..\..\..\${{ matrix.asset_name }}.zip
cd -
- name: Generate SHA256 (Unix)
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
shasum -a 256 ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
else
sha256sum ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
fi
- name: Generate SHA256 (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$hash = Get-FileHash -Path "${{ matrix.asset_name }}.zip" -Algorithm SHA256
"$($hash.Hash.ToLower()) ${{ matrix.asset_name }}.zip" | Out-File -FilePath "${{ matrix.asset_name }}.zip.sha256" -NoNewline
- name: Upload Release Assets
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const releaseId = ${{ needs.create-release.outputs.release_id }};
// Determine file extension based on OS
const isWindows = '${{ matrix.os }}' === 'windows-latest';
const archiveExt = isWindows ? 'zip' : 'tar.gz';
const archiveName = `${{ matrix.asset_name }}.${archiveExt}`;
const checksumName = `${archiveName}.sha256`;
// Upload main archive
console.log(`Uploading ${archiveName}...`);
const archiveData = fs.readFileSync(archiveName);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: archiveName,
data: archiveData,
headers: {
'content-type': isWindows ? 'application/zip' : 'application/gzip',
'content-length': archiveData.length
}
});
// Upload checksum
console.log(`Uploading ${checksumName}...`);
const checksumData = fs.readFileSync(checksumName);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: checksumName,
data: checksumData,
headers: {
'content-type': 'text/plain',
'content-length': checksumData.length
}
});