-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (159 loc) · 6.08 KB
/
release.yml
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
# Credit for this workflow to Burntsushi and the contributors of Ripgrep.
# https://github.com/BurntSushi/ripgrep/blob/16a1221fc70d586a07bd0421722635c61df525be/.github/workflows/release.yml
# Their comments are prefixed with "> ".
# > The way this works is a little weird. But basically, the create-release job
# > runs purely to initialize the GitHub release itself. Once done, the upload
# > URL of the release is saved as an artifact.
# >
# > The build-release job runs only once create-release is finished. It gets
# > the release upload URL by downloading the corresponding artifact (which was
# > uploaded by create-release). It then builds the release executables for each
# > supported platform and attaches them as release assets to the previously
# > created release.
# >
# > The key here is that we create the release only once.
name: release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get the release version from the tag
run: |
echo "::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/tags/}"
echo "version is: ${{ env.RELEASE_VERSION }}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: ${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
- name: Create artifacts dir
run: mkdir artifacts
- name: Save release upload URL to artifact
run: echo "${{ steps.create_release.outputs.upload_url }}" > artifacts/release-upload-url
- name: Save version number to artifact
run: echo "${{ env.RELEASE_VERSION }}" > artifacts/release-version
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts
build-release:
name: build-release
needs: ['create-release']
runs-on: ${{ matrix.os }}
env:
# > For some builds, use cross
CARGO: cargo
# > When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
# > When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# > Emit backtraces on panics.
RUST_BACKTRACE: 1
strategy:
matrix:
include:
- name: linux-x86_64
os: ubuntu-18.04
target: x86_64-unknown-linux-gnu
- name: linux-x86_64-musl
os: ubuntu-18.04
target: x86_64-unknown-linux-musl
- name: linux-arm
os: ubuntu-18.04
target: arm-unknown-linux-gnueabihf
- name: macos-x86_64
os: macos-10.15
target: x86_64-apple-darwin
- name: windows-x86_64-gnu
os: windows-2019
target: x86_64-pc-windows-gnu
- name: windows-x86_64-msvc
os: windows-2019
target: x86_64-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Get release download URL
uses: actions/download-artifact@v2
with:
name: artifacts
path: artifacts
- name: Set release upload URL and release version
shell: bash
run: |
release_upload_url="$(cat artifacts/release-upload-url)"
echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url"
echo "release upload url: $RELEASE_UPLOAD_URL"
release_version="$(cat artifacts/release-version)"
echo "::set-env name=RELEASE_VERSION::$release_version"
echo "release version: $RELEASE_VERSION"
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Use Cross
if: matrix.os == 'ubuntu-18.04'
run: |
cargo install cross
echo "::set-env name=CARGO::cross"
echo "::set-env name=TARGET_FLAGS::--target ${{ matrix.target }}"
echo "::set-env name=TARGET_DIR::./target/${{ matrix.target }}"
- name: Show command used for Cargo
run: |
echo "cargo is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Strip release binary (linux and macos)
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'x86_64-apple-darwin'
run: strip "${{ env.TARGET_DIR }}/release/renamer"
- name: Strip release binary (arm)
if: matrix.target == 'arm-unknown-linux-gnueabihf'
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
rustembedded/cross:arm-unknown-linux-gnueabihf \
arm-linux-gnueabihf-strip \
/target/arm-unknown-linux-gnueabihf/release/renamer
- name: Organize output
shell: bash
run: |
executable_name=renamer-${{ env.RELEASE_VERSION }}-${{ matrix.name }}
if [ "${{ matrix.os }}" = "windows-2019" ]; then
executable_path="${{ env.TARGET_DIR }}/release/renamer.exe"
executable_name="${executable_name}.exe"
else
executable_path="${{ env.TARGET_DIR }}/release/renamer"
fi
echo "::set-env name=EXECUTABLE_PATH::$executable_path"
echo "::set-env name=EXECUTABLE_NAME::$executable_name"
- name: Upload release archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: ${{ env.EXECUTABLE_PATH }}
asset_name: ${{ env.EXECUTABLE_NAME }}
asset_content_type: application/octet-stream