Merge pull request #15 from Rovel/add-artifacts #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust Multi-Arch Build | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
test: | |
name: Test for ${{ matrix.target }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
- target: armv7-unknown-linux-gnueabihf | |
- target: aarch64-unknown-linux-gnu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
run: curl https://sh.rustup.rs -sSf | sh -s -- -y | |
- name: Install cross | |
run: cargo install cross | |
- name: Test binary | |
run: cross test --target ${{ matrix.target }} | |
build: | |
name: Build for ${{ matrix.target }} | |
needs: test | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
- target: armv7-unknown-linux-gnueabihf | |
- target: aarch64-unknown-linux-gnu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
run: curl https://sh.rustup.rs -sSf | sh -s -- -y | |
- name: Install cross | |
run: cargo install cross | |
- name: Set Rust flags | |
run: export RUSTFLAGS="-C link-arg=-o -C link-arg=image_cleaner_#{{ matrix.target }}" | |
- name: Build binary | |
run: cross build --target ${{ matrix.target }} --release | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: image_cleaner-${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/ | |
release: | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'Merge') }} | |
name: Release | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
path: target | |
- name: Display structure of downloaded files | |
run: ls - | |
- name: Rename binaries | |
run: | | |
for dir in */ ; do | |
if [ -d "$dir" ]; then | |
base=$(basename "$dir") | |
mv "${dir%/}/image_cleaner" "${dir%/}/${dir%/}" # Rename binary to match directory name | |
fi | |
done | |
- name: Bump version and push tag | |
id: tag_version | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Prepare artifact paths | |
id: prep | |
run: | | |
artifacts="" | |
for dir in */ ; do | |
if [ -d "$dir" ]; then | |
artifacts="${artifacts},${dir%/}/${dir%/}" # Append the new binary path | |
fi | |
done | |
artifacts=${artifacts:1} # Remove leading comma | |
echo "::set-output name=artifacts::$artifacts" | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.tag_version.outputs.new_tag }} | |
name: Release ${{ steps.tag_version.outputs.new_tag }} | |
artifacts: ${{ steps.prep.outputs.artifacts }} | |
body: ${{ steps.tag_version.outputs.changelog }} |