-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from TehPers/cd
Add release pipeline
- Loading branch information
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "[0-9]+.[0-9]+.[0-9]+" | ||
# Enable for testing (for the testing branch) | ||
# branches: | ||
# - cd | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
# Create the release separately so it is only created once | ||
create-release: | ||
name: create-release | ||
runs-on: ubuntu-latest | ||
env: | ||
# Enable for testing | ||
# OVERRIDE_VERSION: 0.0.0-ignore-me | ||
outputs: | ||
app_version: ${{ steps.get_version.outputs.version }} | ||
upload_url: ${{ steps.release.outputs.upload_url }} | ||
steps: | ||
- name: Get version | ||
id: get_version | ||
run: | | ||
TAG_VERSION="${GITHUB_REF/refs\/tags\//}" | ||
echo ::set-output name=version::${OVERRIDE_VERSION:-TAG_VERSION} | ||
- name: Create release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
prerelease: true # TODO: remove this on v1 release | ||
tag_name: ${{ steps.get_version.outputs.version }} | ||
release_name: ${{ steps.get_version.outputs.version }} | ||
|
||
# Build the artifacts | ||
release: | ||
name: Create release | ||
needs: [create-release] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
RUST_BACKTRACE: 1 | ||
TARGET_DIR: ./target/${{ matrix.target }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
build: [linux, macos, win-msvc] | ||
include: | ||
- build: linux | ||
os: ubuntu-18.04 | ||
rust: stable | ||
target: x86_64-unknown-linux-musl | ||
- build: macos | ||
os: macos-latest | ||
rust: stable | ||
target: x86_64-apple-darwin | ||
- build: win-msvc | ||
os: windows-2019 | ||
rust: stable | ||
target: x86_64-pc-windows-msvc | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
profile: minimal | ||
override: true | ||
target: ${{ matrix.target }} | ||
- name: Build release | ||
run: cargo build --verbose --release --target ${{ matrix.target }} | ||
- name: Strip binary | ||
if: matrix.build == 'linux' || matrix.build == 'macos' | ||
run: strip "$TARGET_DIR/release/pufferwatch" | ||
- name: Create archive | ||
id: create_archive | ||
shell: bash | ||
run: | | ||
# Create artifact directory | ||
ARTIFACT_DIR="pufferwatch-${{ needs.create-release.outputs.app_version }}-${{ matrix.target }}" | ||
mkdir -p "$ARTIFACT_DIR" | ||
# Copy documentation files into artifact directory | ||
cp README.md "$ARTIFACT_DIR" | ||
cp LICENSE-MIT "$ARTIFACT_DIR" | ||
cp LICENSE-APACHE "$ARTIFACT_DIR" | ||
# Copy binary into artifact directory | ||
if [ "${{ matrix.os }}" = "windows-2019" ]; then | ||
cp "$TARGET_DIR/release/pufferwatch.exe" "$ARTIFACT_DIR/" | ||
7z a "$ARTIFACT_DIR.zip" "$ARTIFACT_DIR" | ||
echo ::set-output name=asset::$ARTIFACT_DIR.zip | ||
else | ||
cp "$TARGET_DIR/release/pufferwatch" "$ARTIFACT_DIR/" | ||
tar -czf "$ARTIFACT_DIR.tar.gz" "$ARTIFACT_DIR" | ||
echo ::set-output name=asset::$ARTIFACT_DIR.tar.gz | ||
fi | ||
- name: Upload archive | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.create-release.outputs.upload_url }} | ||
asset_path: ${{ steps.create_archive.outputs.asset }} | ||
asset_name: ${{ steps.create_archive.outputs.asset }} | ||
asset_content_type: application/octet-stream |