Skip to content

Commit ba7317d

Browse files
authored
fix(ci): release builds (#2219)
## Description Runs the usual release flow, but now also creates a draft release and attaches all binaries to it. Also closes: #2232 Sample: https://github.com/n0-computer/iroh/releases/tag/untagged-b36c22bc1e19cbd75396 ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent b91b684 commit ba7317d

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

Diff for: .gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Set line endings to LF, even on Windows. Otherwise, execution within CI fails.
2+
# See https://help.github.com/articles/dealing-with-line-endings/
3+
*.sh text eol=lf

Diff for: .github/workflows/release.yml

+44-28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ env:
3030
MSRV: "1.75"
3131
SCCACHE_CACHE_SIZE: "50G"
3232
BIN_NAMES: "iroh,iroh-relay,iroh-dns-server"
33+
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
3334

3435
jobs:
3536
create-release:
@@ -39,13 +40,18 @@ jobs:
3940
upload_url: ${{ steps.release.outputs.upload_url }}
4041
release_version: ${{ env.RELEASE_VERSION }}
4142
steps:
42-
- name: Get the release version from the tag (push)
43+
- name: Get the release version from the tag or input
4344
shell: bash
44-
if: env.RELEASE_VERSION == '' && github.event_name == 'push'
45+
if: env.RELEASE_VERSION == ''
4546
run: |
46-
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
47-
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
48-
echo "version is: ${{ env.RELEASE_VERSION }}"
47+
if "${{ github.event.inputs.release_version }}" != ""; then
48+
echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV
49+
echo "version is: ${{ env.RELEASE_VERSION }}"
50+
else
51+
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
52+
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
53+
echo "version is: ${{ env.RELEASE_VERSION }}"
54+
fi
4955
- name: Checkout repository
5056
uses: actions/checkout@v4
5157
with:
@@ -57,6 +63,7 @@ jobs:
5763
env:
5864
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5965
with:
66+
draft: true
6067
tag_name: ${{ env.RELEASE_VERSION || github.event.inputs.release_version}}
6168
release_name: ${{ env.RELEASE_VERSION || github.event.inputs.release_version }}
6269

@@ -138,13 +145,18 @@ jobs:
138145
rustup target add ${{ matrix.cargo_targets }}
139146
140147
- name: build release
148+
if: matrix.os != 'windows-latest'
141149
shell: bash
142150
run: |
143151
if [ "${{ matrix.name }}" = "ubuntu-arm-latest" ]; then
144152
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
145153
export CC=aarch64-linux-gnu-gcc
146154
fi
147155
cargo build --profile optimized-release --all-features --target ${{ matrix.cargo_targets }}
156+
157+
- name: build release
158+
if: matrix.os == 'windows-latest'
159+
run: cargo build --profile optimized-release --all-features --target ${{ matrix.cargo_targets }}
148160

149161
- name: attach artifacts
150162
if: matrix.os != 'windows-latest'
@@ -204,36 +216,40 @@ jobs:
204216
aws s3 cp ./target/${{ matrix.cargo_targets }}/optimized-release/iroh-dns-server s3://vorc/iroh-dns-server-${RELEASE_OS}-${RELEASE_ARCH}-latest --no-progress
205217
206218
- name: Build archives
219+
if: matrix.os != 'windows-latest'
207220
shell: bash
208221
run: |
209222
IFS=',' read -ra BIN_NAMES <<< "${{ env.BIN_NAMES }}"
210223
ASSETS=""
211224
for BIN_NAME in "${BIN_NAMES[@]}"; do
212225
staging="$BIN_NAME-${{ needs.create-release.outputs.release_version }}-${{ matrix.cargo_targets }}"
213226
mkdir -p "$staging"
214-
if [ "${{ matrix.os }}" = "windows-latest" ]; then
215-
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME.exe" "$staging/"
216-
cd "$staging"
217-
7z a "../$staging.zip" .
218-
ASSETS+="$staging.zip,"
219-
else
220-
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME" "$staging/"
221-
tar czf "$staging.tar.gz" -C "$staging" .
222-
ASSETS+="$staging.tar.gz,"
223-
fi
227+
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME" "$staging/"
228+
tar czf "$staging.tar.gz" -C "$staging" .
229+
ASSETS+="$staging.tar.gz,"
224230
done
225-
echo "ASSET=${ASSETS::-1}" >> $GITHUB_ENV
231+
echo "ASSET=$(echo $ASSETS | sed 's/,$//')" >> $GITHUB_ENV
226232
227-
- name: Upload release archives
228-
if: github.event.inputs.upload_artifacts == 'true' || github.event_name == 'push'
233+
- name: Build archives (windows)
234+
if: matrix.os == 'windows-latest'
235+
shell: pwsh
229236
run: |
230-
IFS=',' read -ra ASSETS <<< "${{ env.ASSET }}"
231-
for ASSET in "${ASSETS[@]}"; do
232-
ASSET_NAME=$(basename $ASSET)
233-
curl \
234-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
235-
-H "Content-Type: $(file -b --mime-type application/octet-stream)" \
236-
--data-binary @"$ASSET" \
237-
"${{ needs.create-release.outputs.upload_url }}?name=$ASSET_NAME"
238-
done
239-
237+
$BIN_NAMES = "${{ env.BIN_NAMES }}".Split(',')
238+
$ASSETS = @()
239+
foreach ($BIN_NAME in $BIN_NAMES) {
240+
$staging = "$BIN_NAME-${{ needs.create-release.outputs.release_version }}-${{ matrix.cargo_targets }}"
241+
New-Item -ItemType Directory -Force -Path "$staging"
242+
Copy-Item -Path "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME.exe" -Destination "$staging/"
243+
Set-Location -Path "$staging"
244+
Compress-Archive -Path * -DestinationPath "../$staging.zip"
245+
$ASSETS += "$staging.zip"
246+
Set-Location -Path ..
247+
}
248+
$ASSETS = $ASSETS -join ','
249+
Add-Content -Path $env:GITHUB_ENV -Value "ASSET=$ASSETS"
250+
251+
- uses: n0-computer/actions-upload-release-asset@main
252+
if: (github.event.inputs.upload_artifacts == 'true' || github.event_name == 'push')
253+
with:
254+
upload_url: ${{ needs.create-release.outputs.upload_url }}
255+
asset_path: ${{ env.ASSET }}

0 commit comments

Comments
 (0)