Skip to content

Commit ca5de4a

Browse files
authored
Merge pull request #1475 from EliahKagan/w32
Fix 32-bit Windows releases so they are the correct architecture
2 parents 55cffe4 + 3c3a831 commit ca5de4a

File tree

1 file changed

+56
-68
lines changed

1 file changed

+56
-68
lines changed

.github/workflows/release.yml

+56-68
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,60 @@
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
123

134
name: release
145

15-
env:
16-
RUST_BACKTRACE: 1
17-
CARGO_TERM_COLOR: always
18-
CLICOLOR: 1
19-
206
on:
217
workflow_dispatch:
228
push:
239
# Enable when testing release infrastructure on a branch.
2410
# branches:
2511
# - fix-releases
2612
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+
2824
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.
2928
create-release:
3029
name: create-release
3130
runs-on: ubuntu-latest
3231
# env:
3332
# # Set to force version number, e.g., when no tag exists.
34-
# ARTIFACT_VERSION: TEST-0.0.0
33+
# VERSION: TEST-0.0.0
3534
steps:
3635
- name: Create artifacts directory
3736
run: mkdir artifacts
3837

3938
- 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"
4441

4542
- name: Create GitHub release
4643
id: release
4744
uses: ncipollo/release-action@v1
4845
with:
49-
tag: ${{ env.ARTIFACT_VERSION }}
50-
name: ${{ env.ARTIFACT_VERSION }}
46+
tag: ${{ env.VERSION }}
47+
name: ${{ env.VERSION }}
5148
allowUpdates: true
5249
omitBody: true
5350
omitPrereleaseDuringUpdate: true
5451
token: ${{ secrets.GITHUB_TOKEN }}
5552

5653
- 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
5855

5956
- name: Save version number to artifact
60-
run: echo "${{ env.ARTIFACT_VERSION }}" > artifacts/release-version
57+
run: echo "$VERSION" > artifacts/release-version
6158

6259
- name: Upload artifacts
6360
uses: actions/upload-artifact@v4
@@ -67,23 +64,13 @@ jobs:
6764

6865
build-release:
6966
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+
8370
strategy:
8471
matrix:
8572
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 ]
8774
include:
8875
- build: linux
8976
os: ubuntu-latest
@@ -127,11 +114,16 @@ jobs:
127114
feature: max
128115

129116
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+
130124
steps:
131125
- name: Checkout repository
132126
uses: actions/checkout@v4
133-
with:
134-
fetch-depth: 1
135127

136128
- name: Install packages (Ubuntu)
137129
# 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:
147139
targets: ${{ matrix.target }}
148140

149141
- name: Use Cross
150-
# if: matrix.os != 'windows-latest'
142+
if: matrix.os == 'ubuntu-latest'
151143
run: |
152144
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"
156146
157147
- name: Show command used for Cargo
158148
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"
162152
163153
- name: Get release download URL
164154
uses: actions/download-artifact@v4
@@ -167,21 +157,17 @@ jobs:
167157
path: artifacts
168158

169159
- name: Set release upload URL and release version
170-
shell: bash
171160
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"
178163
179164
- 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 }}
181167
182168
- name: Strip release binary (linux and macos)
183169
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}
185171

186172
- name: Strip release binary (arm)
187173
if: matrix.build == 'linux-arm'
@@ -190,32 +176,34 @@ jobs:
190176
"$PWD/target:/target:Z" \
191177
rustembedded/cross:arm-unknown-linux-gnueabihf \
192178
arm-linux-gnueabihf-strip \
193-
/target/arm-unknown-linux-gnueabihf/release/${{ env.EXE_NAME }} \
179+
/target/arm-unknown-linux-gnueabihf/release/ein \
194180
/target/arm-unknown-linux-gnueabihf/release/gix
181+
195182
- name: Build archive
196-
shell: bash
197183
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"
200186
201187
cp {README.md,LICENSE-*,CHANGELOG.md} "$staging/"
202188
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/"
205192
7z a "$staging.zip" "$staging"
206-
echo "ASSET=$staging.zip" >> $GITHUB_ENV
193+
echo "ASSET=$staging.zip" >> "$GITHUB_ENV"
207194
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/"
209197
tar czf "$staging.tar.gz" "$staging"
210-
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
198+
echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"
211199
fi
212200
213201
- name: Upload release archive
214202
uses: actions/[email protected]
215203
env:
216204
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
217205
with:
218-
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
206+
upload_url: ${{ env.UPLOAD_URL }}
219207
asset_path: ${{ env.ASSET }}
220208
asset_name: ${{ env.ASSET }}
221209
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)