refactor: GitHub workflow action improved

This commit is contained in:
Jack Wills
2024-01-05 11:07:47 +00:00
parent 4301e4709f
commit 04b66af2b6
+22 -20
View File
@@ -12,11 +12,19 @@ jobs:
cross_platform_build: cross_platform_build:
strategy: strategy:
matrix: matrix:
platform: include:
- target: x86_64-unknown-linux-musl - target: x86_64-unknown-linux-musl
output_name: linux_x86_64.tar.gz
- target: aarch64-unknown-linux-musl - target: aarch64-unknown-linux-musl
output_name: linux_aarch64.tar.gz
- target: arm-unknown-linux-musleabihf - target: arm-unknown-linux-musleabihf
output_name: linux_armv6.tar.gz
- target: x86_64-pc-windows-gnu - target: x86_64-pc-windows-gnu
output_name: windows_x86_64.zip
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
@@ -30,35 +38,29 @@ jobs:
- name: install cross - name: install cross
run: cargo install cross --git https://github.com/cross-rs/cross run: cargo install cross --git https://github.com/cross-rs/cross
# Set env's
- name: set names
run: |
translate_platform() { case "$1" in x86_64-unknown-linux-musl) echo "linux_x86_64.tar.gz";; aarch64-unknown-linux-musl) echo "linux_aarch64.tar.gz";; arm-unknown-linux-musleabihf) echo "linux_armv6.tar.gz";; x86_64-pc-windows-gnu) echo "windows_x86_64.zip";; *) echo "Error: Unsupported platform $1"; exit 1;; esac; }
target_platform="${{ matrix.platform.target }}"
output_name=$(translate_platform "$target_platform")
echo "TARGET_OUTPUT_NAME=${output_name}" >> $GITHUB_ENV
echo "TARGET_PLATFORM=${target_platform}" >> $GITHUB_ENV
# Build binary # Build binary
- name: build - name: build
run: cross build --target "${TARGET_PLATFORM}" --release run: cross build --target ${{ matrix.target }} --release
# Compress, rename, and move # Compress the output
- name: compress - name: compress windows
if: matrix.target == 'x86_64-pc-windows-gnu'
run: | run: |
if [[ $TARGET_PLATFORM == *windows-gnu* ]]; then zip -j "./oxker_${{ matrix.output_name }}" target/${{ matrix.target }}/release/oxker.exe
zip -j "./oxker_${TARGET_OUTPUT_NAME}" target/${TARGET_PLATFORM}/release/oxker.exe
else # Compress the output
tar -C "target/${TARGET_PLATFORM}/release" -czf "./oxker_${TARGET_OUTPUT_NAME}" oxker - name: compress linux
fi if: matrix.target != 'x86_64-pc-windows-gnu'
run: |
tar -C "target/${{ matrix.target }}/release" -czf "./oxker_${{ matrix.output_name }}" oxker
# Upload output for release page # Upload output for release page
- name: Upload Artifacts - name: Upload Artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
if-no-files-found: error if-no-files-found: error
name: ${{ env.TARGET_PLATFORM }} name: ${{ matrix.target }}
path: oxker_${{ env.TARGET_OUTPUT_NAME }} path: oxker_${{ matrix.output_name }}
retention-days: 1 retention-days: 1
################### ###################