Skip to content

Commit

Permalink
auto build
Browse files Browse the repository at this point in the history
  • Loading branch information
frederik-uni committed Jun 19, 2024
1 parent f50e4dc commit 8e71e4e
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build
on: [push]
env:
# The project name specified in your Cargo.toml
PROJECT_NAME: rust-update
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
jobs:
build:
# Set the job to run on the platform specified by the matrix below
runs-on: ${{ matrix.runner }}

# Define the build matrix for cross-compilation
strategy:
matrix:
include:
- name: x86_64-unknown-linux-gnu # linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- name: x86_64-pc-windows-msvc # win-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
- name: x86_64-apple-darwin # macos-amd64
runner: macos-latest
target: x86_64-apple-darwin
- name: aarch64-apple-darwin # macos-arm64
runner: macos-latest
target: aarch64-apple-darwin

# The steps to run for each matrix item
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: "${{ matrix.target }}"

- name: Setup Cache
uses: Swatinem/rust-cache@v2

- name: Build Binary
run: cargo build --verbose --locked --release --target ${{ matrix.target }}

- name: Move Files
id: move
shell: bash
run: |
BIN_SUFFIX=""
if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
BIN_SUFFIX=".exe"
fi
# The built binary output location
BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
# Define a better name for the final binary
BIN_RELEASE="${PROJECT_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
BIN_RELEASE_VERSIONED="${PROJECT_NAME}-${{ github.ref_name }}-${{ matrix.name }}${BIN_SUFFIX}"
mkdir ./builds
mv "${BIN_OUTPUT}" "./builds/${BIN_RELEASE}"
echo "file_name=${BIN_RELEASE}" >> $GITHUB_ENV
# Move the built binary where you want it
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.file_name }}
path: ./builds/${{ env.file_name }}
release:
permissions:
contents: write
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get version from Cargo.toml
id: get_version
run: echo "version=$(awk -F'"' '/\[package\]/ {p=1} p && /version/ {print $2; exit}' Cargo.toml)" >> $GITHUB_ENV

- name: Get latest release tag
id: get_latest_release
run: echo "latest_tag=$(curl -s https://api.github.com/repos/${{ github.repository }}/tags | jq -r '.[0].name // "0.0.0"')" >> $GITHUB_ENV

- name: Compare versions
id: compare_versions
run: |
IFS='.' read -ra v1 <<< "${{ env.version }}"
IFS='.' read -ra v2 <<< "${{ env.latest_tag }}"
if [ "${v1[0]}" -gt "${v2[0]}" ] || ([ "${v1[0]}" -eq "${v2[0]}" ] && [ "${v1[1]}" -gt "${v2[1]}" ]) || ([ "${v1[0]}" -eq "${v2[0]}" ] && [ "${v1[1]}" -eq "${v2[1]}" ] && [ "${v1[2]}" -gt "${v2[2]}" ]); then
mkdir ./builds
echo "greater=1" >> $GITHUB_ENV
else
echo "greater=0" >> $GITHUB_ENV
fi
- name: Download Artifacts
if: env.greater == 1
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: "./builds"
- name: Create release
if: env.greater == 1
uses: ncipollo/release-action@v1
with:
tag: ${{ env.version }}
name: ${{ env.version }}
artifacts: "./builds/*"
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ pub async fn serve(path: PathBuf, port: u16, global: bool, signal: Option<Signal
}
}
}
Err(e) => {
Err(_e) => {
#[cfg(feature = "log")]
log::warn!("watch error: {:?}", e)
log::warn!("watch error: {:?}", _e)
}
})?;

Expand All @@ -115,9 +115,9 @@ pub async fn serve(path: PathBuf, port: u16, global: bool, signal: Option<Signal
handle_client(stream, path, signal).await;
});
}
Err(e) => {
Err(_e) => {
#[cfg(feature = "log")]
log::warn!("Error accepting connection: {:?}", e);
log::warn!("Error accepting connection: {:?}", _e);
}
}
}
Expand Down

0 comments on commit 8e71e4e

Please sign in to comment.