-
-
Notifications
You must be signed in to change notification settings - Fork 2
151 lines (132 loc) · 4.32 KB
/
Copy pathrelease.yml
File metadata and controls
151 lines (132 loc) · 4.32 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
name: Release
on:
push:
paths:
- 'Cargo.toml'
branches:
- main
workflow_dispatch:
inputs:
force:
description: Force release regardless of version change
type: boolean
default: false
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.extract.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version changed
id: check
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force }}" = "true" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
elif git rev-parse HEAD^ >/dev/null 2>&1 && git diff HEAD^ HEAD -- Cargo.toml | grep -q '^[+-]version = '; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Extract version
id: extract
if: steps.check.outputs.changed == 'true'
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
build:
needs: check-version
if: needs.check-version.outputs.version_changed == 'true'
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_name: pik
asset_name: pik-linux-x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: pik
asset_name: pik-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: pik
asset_name: pik-macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: pik.exe
asset_name: pik-windows-x86_64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install musl-tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y musl-tools
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary
if: matrix.os != 'windows-latest'
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
release:
needs: [check-version, build]
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
VERSION="${{ needs.check-version.outputs.version }}"
if [ -z "$VERSION" ]; then
echo "No version resolved — aborting"
exit 1
fi
if gh release view "v$VERSION" &>/dev/null; then
echo "Release v$VERSION already exists — skipping"
exit 0
fi
gh release create "v$VERSION" --title "v$VERSION" --generate-notes
shopt -s nullglob
ASSETS=(artifacts/*/*)
echo "Found ${#ASSETS[@]} artifacts:"
for f in "${ASSETS[@]}"; do
echo " - $f"
done
if [ "${#ASSETS[@]}" -eq 0 ]; then
echo "No artifacts found to upload — failing"
exit 1
fi
FAILED=0
for f in "${ASSETS[@]}"; do
dir=$(basename "$(dirname "$f")")
echo "Uploading $f as $dir..."
if ! gh release upload "v$VERSION" "$f#$dir" --clobber; then
echo "Failed to upload $f"
FAILED=1
fi
done
if [ "$FAILED" -eq 1 ]; then
echo "One or more uploads failed"
exit 1
fi