Publish crate #18
Workflow file for this run
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: Publish crate | |
on: | |
push: | |
tags: [v*] | |
permissions: | |
contents: write | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Run tests | |
run: cargo test | |
macos-build: | |
runs-on: macos-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Install cross | |
run: cargo install cross | |
- name: Add target to rustup | |
run: rustup target add x86_64-apple-darwin | |
- name: Build for Apple x86_64 | |
run: cross build --target x86_64-apple-darwin --release | |
- name: Add target to rustup | |
run: rustup target add aarch64-apple-darwin | |
- name: Build for Apple aarch64 | |
run: cross build --target aarch64-apple-darwin --release | |
- name: Upload x86_64-apple-darwin artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: x86_64-apple-darwin | |
path: target/x86_64-apple-darwin/release/clipcat | |
if-no-files-found: error | |
- name: Upload aarch64-apple-darwin artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: aarch64-apple-darwin | |
path: target/aarch64-apple-darwin/release/clipcat | |
if-no-files-found: error | |
build: | |
runs-on: ubuntu-latest | |
needs: test | |
env: | |
FILE_PATH: "" | |
strategy: | |
matrix: | |
target: | |
[ | |
x86_64-unknown-linux-gnu, | |
arm-unknown-linux-gnueabihf, | |
x86_64-pc-windows-gnu, | |
] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Install cross | |
run: cargo install cross | |
- name: Build for ${{ matrix.target }} | |
run: cross build --target ${{ matrix.target }} --release | |
- name: Set file path to ENV | |
run: | | |
if [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" ]; then | |
echo FILE_PATH=target/${{ matrix.target }}/release/clipcat.exe >> $GITHUB_ENV | |
else | |
echo FILE_PATH=target/${{ matrix.target }}/release/clipcat >> $GITHUB_ENV | |
fi | |
- name: Upload ${{ matrix.target }} artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.target }} | |
path: ${{ env.FILE_PATH }} | |
if-no-files-found: error | |
release: | |
runs-on: ubuntu-latest | |
needs: [build, macos-build] | |
steps: | |
- name: Download Linux x86_64 artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: x86_64-unknown-linux-gnu | |
path: target/x86_64-unknown-linux-gnu/release/ | |
- name: Download Linux arm artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: arm-unknown-linux-gnueabihf | |
path: target/arm-unknown-linux-gnueabihf/release/ | |
- name: Download Windows x86_64 artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: x86_64-pc-windows-gnu | |
path: target/x86_64-pc-windows-gnu/release/ | |
- name: Download Apple x86_64 artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: x86_64-apple-darwin | |
path: target/x86_64-apple-darwin/release/ | |
- name: Download Apple aarch64 artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: aarch64-apple-darwin | |
path: target/aarch64-apple-darwin/release/ | |
- name: Rename binaries | |
run: | | |
mv target/x86_64-unknown-linux-gnu/release/clipcat clipcat-linux-x86_64 | |
mv target/arm-unknown-linux-gnueabihf/release/clipcat clipcat-linux-arm | |
mv target/x86_64-pc-windows-gnu/release/clipcat.exe clipcat-windows-x86_64.exe | |
mv target/x86_64-apple-darwin/release/clipcat clipcat-macos-x86_64 | |
mv target/aarch64-apple-darwin/release/clipcat clipcat-macos-aarch64 | |
- name: Give executable permissions | |
run: | | |
chmod +x clipcat-linux-x86_64 | |
chmod +x clipcat-linux-arm | |
chmod +x clipcat-windows-x86_64.exe | |
chmod +x clipcat-macos-x86_64 | |
chmod +x clipcat-macos-aarch64 | |
- name: Release ${{ github.ref_name }} | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
clipcat-linux-x86_64 | |
clipcat-linux-arm | |
clipcat-windows-x86_64.exe | |
clipcat-macos-x86_64 | |
clipcat-macos-aarch64 | |
crates-io: | |
runs-on: ubuntu-latest | |
needs: [test, release] | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Publish to crates.io | |
run: cargo publish || true |