1
- # The way this works is a little weird. But basically, the create-release job
2
- # runs purely to initialize the GitHub release itself. Once done, the upload
3
- # URL of the release is saved as an artifact.
4
- #
5
- # The build-release job runs only once create-release is finished. It gets
6
- # the release upload URL by downloading the corresponding artifact (which was
7
- # uploaded by create-release). It then builds the release executables for each
8
- # supported platform and attaches them as release assets to the previously
9
- # created release.
10
- #
11
- # The key here is that we create the release only once.
1
+ # This is largely adapted from past and recent versions of the ripgrep release workflow.
2
+ # https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml
12
3
13
4
name : release
14
5
15
- env :
16
- RUST_BACKTRACE : 1
17
- CARGO_TERM_COLOR : always
18
- CLICOLOR : 1
19
-
20
6
on :
21
7
workflow_dispatch :
22
8
push :
23
9
# Enable when testing release infrastructure on a branch.
24
10
# branches:
25
11
# - fix-releases
26
12
tags :
27
- - " v.*"
13
+ - ' v*'
14
+
15
+ env :
16
+ RUST_BACKTRACE : 1
17
+ CARGO_TERM_COLOR : always
18
+ CLICOLOR : 1
19
+
20
+ defaults :
21
+ run :
22
+ shell : bash
23
+
28
24
jobs :
25
+ # The create-release job runs purely to initialize the GitHub release itself,
26
+ # and names the release after the version tag that was pushed. It's separate
27
+ # from building the release so that we only create the release once.
29
28
create-release :
30
29
name : create-release
31
30
runs-on : ubuntu-latest
32
31
# env:
33
32
# # Set to force version number, e.g., when no tag exists.
34
- # ARTIFACT_VERSION : TEST-0.0.0
33
+ # VERSION : TEST-0.0.0
35
34
steps :
36
35
- name : Create artifacts directory
37
36
run : mkdir artifacts
38
37
39
38
- name : Get the release version from the tag
40
- if : env.ARTIFACT_VERSION == ''
41
- run : |
42
- echo "ARTIFACT_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
43
- echo "version is: ${{ env.ARTIFACT_VERSION }}"
39
+ if : env.VERSION == ''
40
+ run : echo 'VERSION=${{ github.ref_name }}' >> "$GITHUB_ENV"
44
41
45
42
- name : Create GitHub release
46
43
id : release
47
44
uses : ncipollo/release-action@v1
48
45
with :
49
- tag : ${{ env.ARTIFACT_VERSION }}
50
- name : ${{ env.ARTIFACT_VERSION }}
46
+ tag : ${{ env.VERSION }}
47
+ name : ${{ env.VERSION }}
51
48
allowUpdates : true
52
49
omitBody : true
53
50
omitPrereleaseDuringUpdate : true
54
51
token : ${{ secrets.GITHUB_TOKEN }}
55
52
56
53
- name : Save release upload URL to artifact
57
- run : echo " ${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
54
+ run : echo ' ${{ steps.release.outputs.upload_url }}' > artifacts/release-upload-url
58
55
59
56
- name : Save version number to artifact
60
- run : echo "${{ env.ARTIFACT_VERSION }} " > artifacts/release-version
57
+ run : echo "$VERSION " > artifacts/release-version
61
58
62
59
- name : Upload artifacts
63
60
uses : actions/upload-artifact@v4
@@ -67,23 +64,13 @@ jobs:
67
64
68
65
build-release :
69
66
name : build-release
70
- needs : [ "create-release" ]
71
- env :
72
- # For some builds, we use cross to test on 32-bit and big-endian
73
- # systems.
74
- CARGO : cargo
75
- # When CARGO is set to CROSS, this is set to `--target matrix.target`.
76
- TARGET_FLAGS : " "
77
- # When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
78
- TARGET_DIR : ./target
79
- # Emit backtraces on panics.
80
- RUST_BACKTRACE : 1
81
- # The name of the executable to expect
82
- EXE_NAME : ein
67
+
68
+ needs : [ create-release ]
69
+
83
70
strategy :
84
71
matrix :
85
72
build : [ linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc ]
86
- feature : [ " small", " lean", " max", " max-pure" ]
73
+ feature : [ small, lean, max, max-pure ]
87
74
include :
88
75
- build : linux
89
76
os : ubuntu-latest
@@ -127,11 +114,16 @@ jobs:
127
114
feature : max
128
115
129
116
runs-on : ${{ matrix.os }}
117
+
118
+ env :
119
+ CARGO : cargo # Sometimes changes to `cross` later (such as when building linux-arm).
120
+ TARGET_FLAGS : --target=${{ matrix.target }}
121
+ TARGET_DIR : ./target/${{ matrix.target }}
122
+ RUST_BACKTRACE : 1 # Emit backtraces on panics.
123
+
130
124
steps :
131
125
- name : Checkout repository
132
126
uses : actions/checkout@v4
133
- with :
134
- fetch-depth : 1
135
127
136
128
- name : Install packages (Ubuntu)
137
129
# Because openssl doesn't work on musl by default, we resort to max-pure. And that won't need any dependency, so we can skip this.continue-on-error
@@ -147,18 +139,16 @@ jobs:
147
139
targets : ${{ matrix.target }}
148
140
149
141
- name : Use Cross
150
- # if: matrix.os != 'windows -latest'
142
+ if : matrix.os == 'ubuntu -latest'
151
143
run : |
152
144
cargo install cross
153
- echo "CARGO=cross" >> $GITHUB_ENV
154
- echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
155
- echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
145
+ echo 'CARGO=cross' >> "$GITHUB_ENV"
156
146
157
147
- name : Show command used for Cargo
158
148
run : |
159
- echo "cargo command is: ${{ env. CARGO }} "
160
- echo "target flag is: ${{ env. TARGET_FLAGS }} "
161
- echo "target dir is: ${{ env. TARGET_DIR }} "
149
+ echo "cargo command is: $CARGO"
150
+ echo "target flag is: $TARGET_FLAGS"
151
+ echo "target dir is: $TARGET_DIR"
162
152
163
153
- name : Get release download URL
164
154
uses : actions/download-artifact@v4
@@ -167,21 +157,17 @@ jobs:
167
157
path : artifacts
168
158
169
159
- name : Set release upload URL and release version
170
- shell : bash
171
160
run : |
172
- release_upload_url="$(cat artifacts/release-upload-url)"
173
- echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
174
- echo "release upload url: $RELEASE_UPLOAD_URL"
175
- release_version="$(cat artifacts/release-version)"
176
- echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
177
- echo "release version: $RELEASE_VERSION"
161
+ echo "UPLOAD_URL=$(< artifacts/release-upload-url)" >> "$GITHUB_ENV"
162
+ echo "VERSION=$(< artifacts/release-version)" >> "$GITHUB_ENV"
178
163
179
164
- name : Build release binary
180
- run : ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} --no-default-features --features ${{ matrix.feature }}
165
+ run : |
166
+ "$CARGO" build --verbose --release "$TARGET_FLAGS" --no-default-features --features ${{ matrix.feature }}
181
167
182
168
- name : Strip release binary (linux and macos)
183
169
if : matrix.build == 'linux' || matrix.build == 'macos'
184
- run : strip target/${{ matrix.target }} /release/${{ env.EXE_NAME }} target/${{ matrix.target }}/release/ gix
170
+ run : strip "$TARGET_DIR" /release/{ein, gix}
185
171
186
172
- name : Strip release binary (arm)
187
173
if : matrix.build == 'linux-arm'
@@ -190,32 +176,34 @@ jobs:
190
176
"$PWD/target:/target:Z" \
191
177
rustembedded/cross:arm-unknown-linux-gnueabihf \
192
178
arm-linux-gnueabihf-strip \
193
- /target/arm-unknown-linux-gnueabihf/release/${{ env.EXE_NAME }} \
179
+ /target/arm-unknown-linux-gnueabihf/release/ein \
194
180
/target/arm-unknown-linux-gnueabihf/release/gix
181
+
195
182
- name : Build archive
196
- shell : bash
197
183
run : |
198
- staging=" gitoxide-${{ matrix.feature }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
199
- mkdir -p "$staging"
184
+ staging=' gitoxide-${{ matrix.feature }}-${{ env.VERSION }}-${{ matrix.target }}'
185
+ mkdir -p -- "$staging"
200
186
201
187
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
202
188
203
- if [ "${{ matrix.os }}" = "windows-latest" ]; then
204
- cp target/release/${{ env.EXE_NAME }}.exe target/release/gix.exe "$staging/"
189
+ if [ '${{ matrix.os }}' = 'windows-latest' ]; then
190
+ file -- "$TARGET_DIR"/release/{ein,gix}.exe
191
+ cp -- "$TARGET_DIR"/release/{ein,gix}.exe "$staging/"
205
192
7z a "$staging.zip" "$staging"
206
- echo "ASSET=$staging.zip" >> $GITHUB_ENV
193
+ echo "ASSET=$staging.zip" >> " $GITHUB_ENV"
207
194
else
208
- cp target/${{ matrix.target }}/release/${{ env.EXE_NAME }} target/${{ matrix.target }}/release/gix "$staging/"
195
+ file -- "$TARGET_DIR"/release/{ein,gix}
196
+ cp -- "$TARGET_DIR"/release/{ein,gix} "$staging/"
209
197
tar czf "$staging.tar.gz" "$staging"
210
- echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
198
+ echo "ASSET=$staging.tar.gz" >> " $GITHUB_ENV"
211
199
fi
212
200
213
201
- name : Upload release archive
214
202
215
203
env :
216
204
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
217
205
with :
218
- upload_url : ${{ env.RELEASE_UPLOAD_URL }}
206
+ upload_url : ${{ env.UPLOAD_URL }}
219
207
asset_path : ${{ env.ASSET }}
220
208
asset_name : ${{ env.ASSET }}
221
209
asset_content_type : application/octet-stream
0 commit comments