Skip to content

Commit

Permalink
fix(ci): release builds (#2219)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
Arqu authored Apr 29, 2024
1 parent b91b684 commit ba7317d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Set line endings to LF, even on Windows. Otherwise, execution within CI fails.
# See https://help.github.com/articles/dealing-with-line-endings/
*.sh text eol=lf
72 changes: 44 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ env:
MSRV: "1.75"
SCCACHE_CACHE_SIZE: "50G"
BIN_NAMES: "iroh,iroh-relay,iroh-dns-server"
RELEASE_VERSION: ${{ github.event.inputs.release_version }}

jobs:
create-release:
Expand All @@ -39,13 +40,18 @@ jobs:
upload_url: ${{ steps.release.outputs.upload_url }}
release_version: ${{ env.RELEASE_VERSION }}
steps:
- name: Get the release version from the tag (push)
- name: Get the release version from the tag or input
shell: bash
if: env.RELEASE_VERSION == '' && github.event_name == 'push'
if: env.RELEASE_VERSION == ''
run: |
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.RELEASE_VERSION }}"
if "${{ github.event.inputs.release_version }}" != ""; then
echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV
echo "version is: ${{ env.RELEASE_VERSION }}"
else
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.RELEASE_VERSION }}"
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
Expand All @@ -57,6 +63,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
tag_name: ${{ env.RELEASE_VERSION || github.event.inputs.release_version}}
release_name: ${{ env.RELEASE_VERSION || github.event.inputs.release_version }}

Expand Down Expand Up @@ -138,13 +145,18 @@ jobs:
rustup target add ${{ matrix.cargo_targets }}
- name: build release
if: matrix.os != 'windows-latest'
shell: bash
run: |
if [ "${{ matrix.name }}" = "ubuntu-arm-latest" ]; then
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
export CC=aarch64-linux-gnu-gcc
fi
cargo build --profile optimized-release --all-features --target ${{ matrix.cargo_targets }}
- name: build release
if: matrix.os == 'windows-latest'
run: cargo build --profile optimized-release --all-features --target ${{ matrix.cargo_targets }}

- name: attach artifacts
if: matrix.os != 'windows-latest'
Expand Down Expand Up @@ -204,36 +216,40 @@ jobs:
aws s3 cp ./target/${{ matrix.cargo_targets }}/optimized-release/iroh-dns-server s3://vorc/iroh-dns-server-${RELEASE_OS}-${RELEASE_ARCH}-latest --no-progress
- name: Build archives
if: matrix.os != 'windows-latest'
shell: bash
run: |
IFS=',' read -ra BIN_NAMES <<< "${{ env.BIN_NAMES }}"
ASSETS=""
for BIN_NAME in "${BIN_NAMES[@]}"; do
staging="$BIN_NAME-${{ needs.create-release.outputs.release_version }}-${{ matrix.cargo_targets }}"
mkdir -p "$staging"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME.exe" "$staging/"
cd "$staging"
7z a "../$staging.zip" .
ASSETS+="$staging.zip,"
else
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME" "$staging/"
tar czf "$staging.tar.gz" -C "$staging" .
ASSETS+="$staging.tar.gz,"
fi
cp "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME" "$staging/"
tar czf "$staging.tar.gz" -C "$staging" .
ASSETS+="$staging.tar.gz,"
done
echo "ASSET=${ASSETS::-1}" >> $GITHUB_ENV
echo "ASSET=$(echo $ASSETS | sed 's/,$//')" >> $GITHUB_ENV
- name: Upload release archives
if: github.event.inputs.upload_artifacts == 'true' || github.event_name == 'push'
- name: Build archives (windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
IFS=',' read -ra ASSETS <<< "${{ env.ASSET }}"
for ASSET in "${ASSETS[@]}"; do
ASSET_NAME=$(basename $ASSET)
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type application/octet-stream)" \
--data-binary @"$ASSET" \
"${{ needs.create-release.outputs.upload_url }}?name=$ASSET_NAME"
done
$BIN_NAMES = "${{ env.BIN_NAMES }}".Split(',')
$ASSETS = @()
foreach ($BIN_NAME in $BIN_NAMES) {
$staging = "$BIN_NAME-${{ needs.create-release.outputs.release_version }}-${{ matrix.cargo_targets }}"
New-Item -ItemType Directory -Force -Path "$staging"
Copy-Item -Path "target/${{ matrix.cargo_targets }}/optimized-release/$BIN_NAME.exe" -Destination "$staging/"
Set-Location -Path "$staging"
Compress-Archive -Path * -DestinationPath "../$staging.zip"
$ASSETS += "$staging.zip"
Set-Location -Path ..
}
$ASSETS = $ASSETS -join ','
Add-Content -Path $env:GITHUB_ENV -Value "ASSET=$ASSETS"
- uses: n0-computer/actions-upload-release-asset@main
if: (github.event.inputs.upload_artifacts == 'true' || github.event_name == 'push')
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}

0 comments on commit ba7317d

Please sign in to comment.