-
Notifications
You must be signed in to change notification settings - Fork 12
194 lines (167 loc) · 6.16 KB
/
release.yaml
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
---
# This workflow runs when PRs are merged and tags/builds/publishes a release.
# Run when PRs to main are closed.
on:
pull_request:
types:
- closed
branches:
- main
name: Build and publish a release
jobs:
# We make `if_merged` a `needs:` of the other jobs here to only run this
# workflow on merged PRs.
if_merged:
name: Check that PR was merged and not closed
if: github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- run: |
echo "This is a canonical hack to run GitHub Actions on merged PRs"
echo "See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-workflow-when-a-pull-request-merges"
- name: Comment on PR with link to this action
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
[This release is now being built.][run]
[run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
version:
name: Get version number
needs: if_merged
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_cargo_metadata.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install rustup
uses: dtolnay/rust-toolchain@stable
- name: Install jq
run: sudo apt install -y jq
- name: Get version number
id: get_cargo_metadata
run: |
echo "version=$(./.github/workflows/get-crate-version.sh)" >> "$GITHUB_OUTPUT"
build:
name: Release Build
# Now we're ready to do the release build. In this step, we upload
# "artifacts" which lets us share files between jobs (the artifacts are
# downloaded by the next job, `upload`) and aggregate files from different
# parts of the matrix (so we can have the macOS and Linux executables in
# the next job).
needs: if_merged
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install rustup
uses: dtolnay/rust-toolchain@stable
if: runner.os == 'macOS'
with:
target: x86_64-apple-darwin, aarch64-apple-darwin
- name: Install rustup
uses: dtolnay/rust-toolchain@stable
if: runner.os == 'Linux'
with:
target: x86_64-unknown-linux-musl, aarch64-unknown-linux-musl
- name: Log versions
run: which -a rustup && rustup --version
- name: Test
run: cargo test
- name: Build (macOS, x86_64)
if: runner.os == 'macOS'
run: cargo build --release --target x86_64-apple-darwin
- name: Build (macOS, aarch64)
if: runner.os == 'macOS'
run: cargo build --release --target aarch64-apple-darwin
- name: Build (Linux, x86_64)
if: runner.os == 'Linux'
run: cargo build --release --target x86_64-unknown-linux-musl
- name: Create macOS universal executable and codesign it
if: runner.os == 'macOS'
run: |
lipo -create -output target/release/nix-your-shell-macos \
target/x86_64-apple-darwin/release/nix-your-shell \
target/aarch64-apple-darwin/release/nix-your-shell
- name: Rename executables for upload
if: runner.os == 'Linux'
run: |
mkdir -p target/release
mv target/x86_64-unknown-linux-musl/release/nix-your-shell \
target/release/nix-your-shell-x86_64-linux
- name: Upload macOS executable
uses: actions/upload-artifact@v3
if: runner.os == 'macOS'
with:
name: macos
path: target/release/nix-your-shell-macos
- name: Upload Linux x86_64 executable
uses: actions/upload-artifact@v3
if: runner.os == 'Linux'
with:
name: linux-x86_64
path: target/release/nix-your-shell-x86_64-linux
- name: Publish to crates.io
if: runner.os == 'Linux'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo publish
upload:
name: Upload assets to release
runs-on: ubuntu-latest
needs:
- if_merged
- build
- version
permissions:
contents: write
pull-requests: write
steps:
- name: Tag the release
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_sha: ${{ github.event.pull_request.merge_commit_sha }}
custom_tag: ${{ needs.version.outputs.version }}
- name: Download artifacts
# This downloads the uploaded artifacts to the current directory; the
# path format for downloaded artifacts is `{name}/{basename}`, where
# `{basename}` is the basename of the upload `path`.
#
# For example, the following artifact:
#
# - uses: actions/upload-artifact@v3
# with:
# name: linux-aarch64
# path: target/release/nix-your-shell-aarch64-linux
#
# will be downloaded to `linux-aarch64/nix-your-shell-aarch64-linux`.
uses: actions/download-artifact@v3
- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
generate_release_notes: true
tag_name: v${{ needs.version.outputs.version }}
files: |
macos/nix-your-shell-macos
linux-x86_64/nix-your-shell-x86_64-linux
- name: Comment on PR with link to the release
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
[Release ${{ needs.version.outputs.version }}][release] was built and published successfully!
[release]: ${{ steps.create_release.outputs.url }}