Get release version from Cargo toml (#44) #45
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: Create Release | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "linkup-cli/Cargo.toml" | |
jobs: | |
publish-to-github: | |
name: Publish to Github | |
runs-on: ${{matrix.os}} | |
strategy: | |
matrix: | |
include: | |
- build: linux | |
os: ubuntu-latest | |
rust: stable | |
target: x86_64-unknown-linux-gnu | |
cross: false | |
- build: aarch64 | |
os: ubuntu-latest | |
rust: stable | |
target: aarch64-unknown-linux-gnu | |
linker: gcc-aarch64-linux-gnu | |
cross: true | |
- build: macos | |
os: macos-latest | |
rust: stable | |
target: x86_64-apple-darwin | |
cross: false | |
- build: macos-aarch64 | |
os: macos-latest | |
rust: stable | |
target: aarch64-apple-darwin | |
cross: false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 1 | |
- name: Install Linker | |
if: matrix.cross | |
run: | | |
cargo install cross | |
sudo apt update | |
sudo apt install -y ${{ matrix.linker }} | |
cat .cargo/config.github >> .cargo/config | |
- name: Install Rust | |
run: | | |
rustup install ${{ matrix.rust }} | |
rustup target add ${{ matrix.target }} | |
rustup show | |
- name: Build | |
run: cargo build --release --manifest-path linkup-cli/Cargo.toml --target ${{ matrix.target }} | |
- name: Get Version from Cargo.toml | |
id: get_version | |
run: | | |
VERSION=$(grep '^version = ' linkup-cli/Cargo.toml | sed -E 's/version = "(.*)"/\1/') | |
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Package Artifacts | |
run: | | |
src=$(pwd) | |
stage= | |
case $RUNNER_OS in | |
Linux) | |
stage=$(mktemp -d) | |
;; | |
macOS) | |
stage=$(mktemp -d -t tmp) | |
;; | |
esac | |
cp target/${{ matrix.target }}/release/linkup $stage/ | |
cd $stage | |
# Use the version from the environment variable | |
RELEASE_VERSION=${{ env.RELEASE_VERSION }} | |
ASSET_NAME="linkup-$RELEASE_VERSION-${{ matrix.target }}.tar.gz" | |
ASSET_PATH="$src/$ASSET_NAME" | |
CHECKSUM_PATH="$ASSET_PATH.sha256" | |
echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV | |
echo "CHECKSUM_PATH=$CHECKSUM_PATH" >> $GITHUB_ENV | |
tar czf $ASSET_PATH * | |
cd $src | |
case $RUNNER_OS in | |
Linux) | |
sha256sum $ASSET_NAME > $CHECKSUM_PATH | |
;; | |
macOS) | |
shasum -a 256 $ASSET_NAME > $CHECKSUM_PATH | |
;; | |
esac | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ github.event.inputs.tag }} | |
files: | | |
${{ env.ASSET_PATH }} | |
${{ env.CHECKSUM_PATH }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |