Skip to content

Commit

Permalink
Cross platform tests and release workflow (#2)
Browse files Browse the repository at this point in the history
* Add cross-platform tests
* Add release workflows
  • Loading branch information
jfharden authored Jan 29, 2024
1 parent 4bba167 commit af68ebd
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 6 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/post-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test and Tag

on:
push:
branches:
- main

permissions:
contents: read

jobs:
test:
uses: ./.github/workflows/run-tests.yml

check-for-and-create-new-release:
name: Create new release tag if needed
runs-on: ubuntu-latest
needs:
- test

permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- shell: bash
run: |
VERSION=$(yq -oy '.package.version' Cargo.toml)
echo "Checking for version $VERSION"
git tag --list
echo "With grep"
git tag --list | grep "^$VERSION\$"
if git tag --list | grep "^$VERSION\$" >>/dev/null 2>&1; then
echo "Version $VERSION already tagged, no release to complete"
exit 0
fi
echo "Continuing to create release tag"
git config user.name BridgeBoard-PC-Boot-Patcher-AutoRelease
git tag "$VERSION"
git push origin "$VERSION"
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Thanks to https://dzfrias.dev/blog/deploy-rust-cross-platform-github-actions on which
# most of this workflow was based
name: Create Release

on:
push:
branches:
- main
tags:
- "[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write

jobs:
build-and-upload:
name: Build and Upload

runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-gnu

- build: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin

# Can build, but not test
- build: macos-arm64
os: macos-latest
target: aarch64-apple-darwin

- build: windows
os: windows-latest
target: x86_64-pc-windows-gnu
steps:
- uses: actions/checkout@v4

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

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

- name: Release build
shell: bash
run: |
cargo build --release --target ${{ matrix.target }}
- name: Build archive
shell: bash
run: |
binary_name="bridgeboard-pc-boot-patcher"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
else
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
fi
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$dirname.zip" "$dirname"
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
else
tar -czf "$dirname.tar.gz" "$dirname"
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
fi
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.ASSET }}
33 changes: 27 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
# Thanks to https://dzfrias.dev/blog/deploy-rust-cross-platform-github-actions on which
# most of this workflow was based
name: Run Tests

on:
workflow_call:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
test:
name: cargo test
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
include:
- build: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu

- build: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin

- build: windows-gnu-x86_64
os: windows-latest
target: x86_64-pc-windows-gnu

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --all-features
- name: Install rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Run tests
shell: bash
run: |
cargo test --target "${{ matrix.target }}" --all-features

0 comments on commit af68ebd

Please sign in to comment.