Deploy #3
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: Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Tag name used to deploy the version' | |
required: true | |
type: string | |
env: | |
BIN_NAME: cotp | |
PROJECT_NAME: cotp | |
REPO_NAME: replydev/cotp | |
jobs: | |
dist: | |
name: Dist | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false # don't fail other jobs if one fails | |
matrix: | |
build: [x86_64-linux, aarch64-linux, x86_64-macos, x86_64-win-msvc] | |
include: | |
- build: x86_64-linux | |
os: ubuntu-22.04 | |
target: x86_64-unknown-linux-gnu | |
- build: aarch64-linux | |
os: ubuntu-22.04 | |
target: aarch64-unknown-linux-gnu | |
- build: x86_64-macos | |
os: macos-14 | |
target: x86_64-apple-darwin | |
- build: x86_64-win-msvc | |
os: windows-2022 | |
target: x86_64-pc-windows-msvc | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
target: ${{ matrix.target }} | |
# Cache dependencies | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
key: ${{ matrix.target }}-release | |
- name: Install cross for arm64 compilation | |
if: matrix.build == 'aarch64-linux' | |
run: cargo install cross --git https://github.com/cross-rs/cross | |
- name: Install Dependencies for Linux x86_64 | |
if: matrix.build == 'x86_64-linux' | |
run: sudo apt update && sudo apt install -y libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev | |
- name: Build release binary (arm64) | |
if: matrix.build == 'aarch64-linux' | |
run: cross build --release --locked --target ${{ matrix.target }} | |
- name: Build release binary (x86_64) | |
if: matrix.build != 'aarch64-linux' | |
run: cargo build --release --locked --target ${{ matrix.target }} | |
- name: Build archive | |
shell: bash | |
run: | | |
mkdir dist | |
if [ "${{ matrix.os }}" = "windows-2019" ]; then | |
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/" | |
else | |
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/" | |
fi | |
- uses: actions/[email protected] | |
with: | |
name: cotp-${{ matrix.build }}-${{ inputs.tag }} | |
path: dist | |
publish: | |
name: "Publish binaries to release page" | |
needs: [dist] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
submodules: false | |
- uses: actions/download-artifact@v4 | |
- run: ls -al cotp-* | |
- name: Build archive | |
shell: bash | |
env: | |
TAG: ${{ inputs.tag }} | |
run: | | |
set -ex | |
rm -rf tmp | |
mkdir tmp | |
mkdir dist | |
for dir in cotp-* ; do | |
platform=${dir#"cotp-"} | |
unset exe | |
# If platform contains "win" then append .exe to the filename | |
if [[ "$platform" == *"win"* ]]; then | |
exe=".exe" | |
fi | |
pkgname=$PROJECT_NAME-$TAG-$platform | |
mkdir tmp/$pkgname | |
# cp LICENSE README.md tmp/$pkgname | |
mv cotp-$platform/$BIN_NAME$exe tmp/$pkgname | |
chmod +x tmp/$pkgname/$BIN_NAME$exe | |
if [ "$exe" = "" ]; then | |
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname | |
else | |
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname) | |
fi | |
done | |
- name: Upload binaries to release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: dist/* | |
file_glob: true | |
tag: ${{ inputs.tag }} | |
overwrite: true | |
publish_on_cargo_crates: | |
name: "Publish crate on crates.io" | |
needs: [dist] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
submodules: false | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Login | |
run: cargo login ${{ secrets.CRATE_AUTH_TOKEN }} | |
- name: List | |
run: cargo package --list | |
- name: Publish | |
run: cargo publish | |
aur-publish-cotp: | |
name: "Publish new version to AUR" | |
runs-on: ubuntu-latest | |
needs: [publish] | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Generate PKGBUILDs | |
shell: bash | |
run: | | |
python ci/build_pkgbuild.py ${{ inputs.tag }} | |
cat ./ci/cotp/PKGBUILD | |
cat ./ci/cotp-bin/PKGBUILD | |
- name: Publish cotp AUR package | |
uses: KSXGitHub/[email protected] | |
with: | |
pkgname: cotp | |
pkgbuild: ./ci/cotp/PKGBUILD | |
commit_username: ${{ secrets.AUR_USERNAME }} | |
commit_email: ${{ secrets.AUR_EMAIL }} | |
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
commit_message: Update cotp package to version ${{ inputs.tag }} | |
ssh_keyscan_types: rsa,dsa,ecdsa,ed25519 | |
- name: "Clean repo dir" | |
shell: bash | |
run: | | |
rm -rf /tmp/local-repo | |
- name: Publish cotp-bin AUR package | |
uses: KSXGitHub/[email protected] | |
with: | |
pkgname: cotp-bin | |
pkgbuild: ./ci/cotp-bin/PKGBUILD | |
commit_username: ${{ secrets.AUR_USERNAME }} | |
commit_email: ${{ secrets.AUR_EMAIL }} | |
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
commit_message: Update cotp-bin package to version ${{ inputs.tag }} | |
ssh_keyscan_types: rsa,dsa,ecdsa,ed25519 |