name: Release
on:
push:
tags:
- 'v*' env:
PKG_NAME: publicip
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
steps:
- name: Create artifacts directory
run: mkdir artifacts
- name: Get the release version from the tag
if: env.PKG_VERSION == ''
run: |
echo "PKG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "version is: ${{ env.PKG_VERSION }}"
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.PKG_VERSION }}
release_name: ${{ env.PKG_VERSION }}
- name: Save release upload URL to artifact
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
- name: Save version number to artifact
run: echo "${{ env.PKG_VERSION }}" > artifacts/release-version
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: artifacts
path: artifacts
build-release:
name: build-release
needs: ['create-release']
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: short
strategy:
matrix:
build: [linux, linux-arm, macos, win-msvc]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
usecross: false
- build: linux-arm
os: ubuntu-latest
rust: stable
target: arm-unknown-linux-musleabihf
strip: arm-linux-musleabihf-strip
usecross: true
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
usecross: false
- build: win-msvc
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
usecross: false
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Get release download URL
uses: actions/download-artifact@v1
with:
name: artifacts
path: artifacts
- name: Set release upload URL and release version
shell: bash
run: |
release_upload_url="$(cat artifacts/release-upload-url)"
echo "RELEASE_UPLOAD_URL=${release_upload_url}" >> $GITHUB_ENV
echo "release upload url: $RELEASE_UPLOAD_URL"
release_version="$(cat artifacts/release-version)"
echo "RELEASE_VERSION=${release_version}" >> $GITHUB_ENV
echo "release version: $RELEASE_VERSION"
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
profile: minimal
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: build
args: --release --verbose --locked --all --target ${{ matrix.target }}
- name: Strip release binary (linux and macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}"
- name: Strip release binary (linux-arm)
if: matrix.build == 'linux-arm'
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
rustembedded/cross:${{ matrix.target }} \
${{ matrix.strip }} \
/target/${{ matrix.target }}/release/${{ env.PKG_NAME }}
- name: Build archive
shell: bash
run: |
staging="${{ env.PKG_NAME }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
mkdir -p "$staging"
cp {README.md,LICENSE} "$staging/"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}.exe" "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=${staging}.zip" >> $GITHUB_ENV
else
cp "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}" "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=${staging}.tar.gz" >> $GITHUB_ENV
fi
- name: Upload release archive
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream
publish-crate:
name: publish-crate
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: login
args: ${{ secrets.CRATES_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: publish