Repository navigation
203 lines (180 loc) · 7.07 KB
/
Copy pathrelease.yml
File metadata and controls
203 lines (180 loc) · 7.07 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
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag to build artifacts for, e.g. v0.5.0"
required: true
type: string
push:
branches: [main]
tags: ["v*"]
permissions:
contents: write
id-token: write
pull-requests: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: cell
jobs:
release-plz-release:
name: Release-plz release
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.release-metadata.outputs.release_tag }}
releases_created: ${{ steps.release-plz.outputs.releases_created }}
permissions:
contents: write
id-token: write
pull-requests: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
- name: Publish release
id: release-plz
uses: release-plz/action@v0.5.147
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract release tag
id: release-metadata
if: steps.release-plz.outputs.releases_created == 'true'
env:
RELEASES: ${{ steps.release-plz.outputs.releases }}
run: |
release_tag="$(echo "$RELEASES" | jq -r 'map(select(.package_name == "cell-sheet-tui"))[0].tag // empty')"
if [ -z "$release_tag" ]; then
echo "cell-sheet-tui release tag not found in release-plz output" >&2
exit 1
fi
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
release-plz-pr:
name: Release-plz PR
if: github.ref == 'refs/heads/main'
needs: release-plz-release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
- name: Open or update release PR
uses: release-plz/action@v0.5.147
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
name: Build (${{ matrix.target }})
# Tags created by release-plz use GITHUB_TOKEN and do not trigger a second
# tag-push workflow run, so build artifacts in this same run when released.
if: always() && (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' || needs.release-plz-release.outputs.releases_created == 'true')
needs: release-plz-release
runs-on: ${{ matrix.os }}
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || startsWith(github.ref, 'refs/tags/v') && github.ref_name || needs.release-plz-release.outputs.release_tag }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.RELEASE_TAG }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
run: cargo build --locked --release --target ${{ matrix.target }} -p cell-sheet-tui
- name: Package (unix)
if: matrix.archive == 'tar.gz'
run: |
mkdir -p dist/${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}/
cp README.md CHANGELOG.md LICENSE dist/${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}/
tar czf ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.tar.gz -C dist ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}
shasum -a 256 ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.tar.gz > ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.tar.gz.sha256
- name: Package (windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$dist = "dist/${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $dist
Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" $dist
Copy-Item README.md,CHANGELOG.md,LICENSE $dist
Compress-Archive -Path $dist -DestinationPath "${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.zip"
$hash = (Get-FileHash "${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.zip" -Algorithm SHA256).Hash.ToLower()
"$hash ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.zip" | Out-File -Encoding ascii "${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.zip.sha256"
- uses: actions/upload-artifact@v7
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
path: ${{ env.BINARY_NAME }}-${{ env.RELEASE_TAG }}-${{ matrix.target }}.*
upload-artifacts:
name: Upload release artifacts
if: always() && needs.build.result == 'success'
needs: [release-plz-release, build]
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || startsWith(github.ref, 'refs/tags/v') && github.ref_name || needs.release-plz-release.outputs.release_tag }}
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v8
with:
path: artifacts
merge-multiple: true
- name: Wait for release-plz draft
run: |
for attempt in {1..30}; do
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
echo "release $RELEASE_TAG was not created by release-plz" >&2
exit 1
env:
GH_TOKEN: ${{ github.token }}
- name: Upload release artifacts
run: |
gh release upload "$RELEASE_TAG" artifacts/* --clobber
gh release edit "$RELEASE_TAG" --draft=false
env:
GH_TOKEN: ${{ github.token }}